Basic IRC Tasks - Channel Related Tasks
(Page 3 of 5 )
The two most basic channel related tasks are joining and parting a channel. The commands are “JOIN” and “PART” and look like this:
JOIN channel
PART channel
No surprises there. Let's put it into Python code:
def join ( self, channel ):
self.send ( 'JOIN ' + channel )
def part ( self, channel ):
self.send ( 'PART ' + channel )
Getting and setting the topic is also pretty simple. The same command, “TOPIC”, is used for both operations. Here is how to get and set a topic, in the respective order:
TOPIC channel
TOPIC channel topic
Our topic should not actually retrieve the data, though. Instead, the recv and retrieve methods should catch it, so creating a method to “get” and set the topic should be pretty simple.
def topic ( self, channel, topic = '' ):
self.send ( 'TOPIC ' + channel + ' ' + topic )
To get a list of names of everyone in a given channel, the “NAMES” command is used:
NAMES #channel
The Python version is short and sweet:
def names ( self, channel ):
self.send ( 'NAMES ' + channel )
IRC allows people to invite their friends to a certain channel using the “INVITE” command:
INVITE person channel
Let's create an invite method:
def invite ( self, nick, channel ):
self.send ( 'INVITE ' + nick + ' ' + channel )
Setting a channel's mode is done with the “MODE” command:
MODE channel mode
Sometimes, a user must be specified:
MODE channel user
To make that a bit more clear, here's an example:
MODE #python +o Peyton
The above command would give “Peyton” operator status in a channel. Let's create a mode method:
def mode ( self, channel, mode, nick = '' ):
self.send ( 'MODE ' + channel + ' ' + mode + ' ' + nick )
If you have operator status in a channel, you may kick a user from the channel:
KICK channel user
A reason can also be specified:
KICK channel user reason
Here's the Python way:
def kick ( self, channel, nick, reason = '' ):
self.send ( 'KICK ' + channel + ' ' + nick + ' ' + reason )
Next: User Related Tasks >>
More Python Articles
More By Peyton McCullough