title: Python IRC Bot, distinguish from channel messages and private messages
body: <p>I'm coding a simple IRC bot in Python. Actually, It can connect to a specific channel, read messages and send response, but it can't distinguish between channel messages and private messages. </p>
  
  <p><strong>Example</strong>:<br>
  John, connected to the same channel, send a private message to the Bot's chat, like "!say hello";
  Bot have to send "hello" to the same private chat, only to John.<br>
  Instead, when bot read "!say hello" in channel's board, have to send "hello" to the channel.</p>
  
  <p><strong>My code:</strong>  </p>
  
  <pre><code>ircmsg = connection.ircsock.recv(2048)
  ircmsg_clean = ircmsg.strip(str.encode('\n\r'))
  if ircmsg.find(str.encode("!say")) != -1:
      try:
          parts = ircmsg_clean.split()
          content = parts[4]
          connection.sendMsg(channel, content)
      except IndexError:
          connection.sendMsg(channel, "Invalid syntax")
  </code></pre>
  
  <p><strong>Connection file:</strong></p>
  
  <pre><code>def sendmsg(channel, msg):
  ircsock.send(str.encode("PRIVMSG " + channel +" :" + msg + "\n"))
  </code></pre>
  
  <p>I know how to send a message to a specific user:</p>
  
  <pre><code>def sendPrivateMsg(username, msg):
  ircsock.send(str.encode("PRIVMSG " + username + " :" + msg + "\n"))
  </code></pre>
  
  <p>But have to know from where the message came, channel or user, and send appropriate response.</p>
  
  <p>Sorry for my bad english.</p>