Basic IRC Tasks - Communication Tasks
(Page 2 of 5 )
All right. It's time to get into some actual tasks now that the basics of our module are completed. Let's start with communication, since it's pretty basic. “PRIVMSG” is the logical place to start. Recall the command from the last article:
PRIVMSG destination :message
This is easy to work into our class. We'll just create a method, privmsg, that accepts two arguments. The first argument is the destination, and the second argument is the message to be sent:
def privmsg ( self, destination, message ):
self.send ( 'PRIVMSG ' + destination + ' :' + message )
The “PRIVMSG” command works with nicknames and channels both.
The “NOTICE” command can also be used to send messages:
def notice ( self, destination, message ):
self.send ( 'NOTICE ' + destination + ' :' + message )
As you can see, “NOTICE” works very similarly to “PRIVMSG.” The only difference is how the commands are intended to be handled. “NOTICE” must never be automatically replied to.
Next: Channel Related Tasks >>
More Python Articles
More By Peyton McCullough