Source

#! /usr/bin/env python## Example program using irclib.py.## This program is free without restrictions; do anything you like with# it.## Joel Rosdahl <joel@rosdahl.net>importirclibimportstringimportsysclassIRCCat(irclib.SimpleIRCClient):def__init__(self,target):irclib.SimpleIRCClient.__init__(self)self.target=targetdefon_welcome(self,connection,event):ifirclib.is_channel(self.target):connection.join(self.target)else:self.send_it()defon_join(self,connection,event):self.send_it()defon_disconnect(self,connection,event):sys.exit(0)defsend_it(self):while1:line=sys.stdin.readline()ifnotline:breakself.connection.privmsg(self.target,line)self.connection.quit("Using irclib.py")defmain():iflen(sys.argv)!=4:print"Usage: irccat2 <server[:port]> <nickname> <target>"print"\ntarget is a nickname or a channel."sys.exit(1)s=string.split(sys.argv[1],":",1)server=s[0]iflen(s)==2:try:port=int(s[1])exceptValueError:print"Error: Erroneous port."sys.exit(1)else:port=6667nickname=sys.argv[2]target=sys.argv[3]c=IRCCat(target)try:c.connect(server,port,nickname)exceptirclib.ServerConnectionError,x:printxsys.exit(1)c.start()if__name__=="__main__":main()