Question

Say you are telneting into IRC to figure out how it all works. As you issue commands the IRC server returns data telling you what it's doing. Once I have created a default script that basically is how a normal IRC connection between server and client occurs, if it ever deviates from that it won't tell me what is wrong. I need to be able to throw exceptions based on what the server returns to me. How do I do that in python?

Was it helpful?

Solution

Here's a tutorial which pretty much walks you through an IRC client using sockets in Python:

OTHER TIPS

Twisted is an event-driven networking engine written in Python, and includes support for IRC protocols. To access IRC functionality, import it:

from twisted.words.protocols import irc

See an example here: ircLogBot.py - connects to an IRC server and logs all messages. The example __doc__:

"""An example IRC log bot - logs a channel's events to a file.

If someone says the bot's name in the channel followed by a ':',
e.g.

  <foo> logbot: hello!

    the bot will reply:

  <logbot> foo: I am a log bot

Run this script with two arguments, the channel name the bot should
connect to, and file to log to, e.g.:

  $ python ircLogBot.py test test.log

will log channel #test to the file 'test.log'.
"""
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top