Before you start coding, join the network “irc.freenode.net” and enter the channel “#irclib” on your IRC client of preference. We'll do all of our testing there. If you wish, though, you are free to use any channel on any network. However, it is important that you do not test the code in this article out in a populated channel. Users will quickly get annoyed. Now it's time to jump into some code. First, we'll try joining an IRC server, sending it a message and leaving. Python-IRCLib makes this quite easy: import irclib # Connection information # Create an IRC object # Create a server object, connect and join the channel It may take a moment for your application to join the channel, so don't panic if you have to wait a moment. Notice how much easier it is to use a library rather than work directly with the IRC protocol. With a single IRC object, it is possible to create multiple server objects, allowing for multiple connections: import irclib # Connection information for the first connection # Information for the second connection # Create an IRC object # Make the first connection # Make the second connection # Infinite loop The privmsg method is used to send messages. Recall that “PRIVMSG” is used to send messages to both users and channels: import irclib # Set this variable to your nickname # Connection information # Connect # Loop
blog comments powered by Disqus |
|
|
|
|
|
|
|