import socket import sys import os import string import math botnick = 'libproog' ident = 'libproog' realname = 'teh proog library' server = 'irc.openstormnet.org' channel = '#openstorm' port = 6667 mather1 = math.sqrt(987654321) poc = 0 # If server's ping on connect function is on, set this to one, else to anything else. def irc_connect(): global irc irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) irc.connect((server, int(port))) irc.send('NICK %s\r\n' % botnick ) irc.send('USER %s 8 * :%s\r\n' % (ident, realname) ) if poc == 1: while 1: buffer2 = irc.recv(1024) data = string.split(buffer2) if 'PING' in data: a = len(data) - 1 irc.send("PONG %s\r\n" % data[a]) break; irc.send('JOIN %s\r\n' % channel) irc.send('PRIVMSG %s :%s initialized on %s on %s\r\n' % (channel, botnick, channel, server)) def ex_start(): irc_connect() while 1: buffer = irc.recv(1024) msg = string.split(buffer) print >> sys.stdout, buffer global nick try: nick = msg[0].split('!')[0] # :nick nick = nick.strip(':') # nick except: pass; if len(msg) > 0: if msg[0] == 'PING': irc.send("PONG %s\r\n" % msg[1]) if msg[0] == "ERROR": irc.close() irc_connect() if len(msg) > 3: # [0] = Full user info, [1] = IRC Command, [2] = Channel, [3] 1st parameter, [4] second... if msg[3] == ':diemuch': print msg[0] irc.send('PRIVMSG %s Dies\r\n' % channel) sys.exit(0) if msg[3] == ':kimperhill': irc.send('PRIVMSG %s :tom tom bomberdill\r\n' % channel) if msg[3] == ':gle2': irc.send('PRIVMSG %s :%s\r\n' % (channel, mather1)) if msg[3] == ':moklop': irc.send('PRIVMSG %s :python > java\r\n' % channel) if msg[3] == ':peacey': irc.send('PRIVMSG %s :python fatty\r\n' % channel) if msg[3] == ':sqrt': try: sqrtnum = msg[4] sqrtsum = math.sqrt(float(sqrtnum)) irc.send('PRIVMSG %s :%s\r\n' % (channel, sqrtsum)) except: irc.send('PRIVMSG %s :Error: cannot calculate %s\r\n' % (channel, sqrtnum) pass; if msg[3] == ':multiply': try: multinum1 = msg[4] multinum2 = msg[5] multisum = multinum1 * multinum2 irc.send('PRIVMSG %s :%s\r\n' % (channel, multisum) except: irc.send('PRIVMSG %s :Error: cannot calculate %s * %s\r\n' % (channel, multinum1, multinum2)) pass; if msg[3] == ':add': try: addnum1 = msg[4] addnum2 = msg[5] addsum = addnum1 + addnum2 irc.send('PRIVMSG %s :%s\r\n' % (channel, addsum)) except: irc.send('PRIVMSG %s :Error: cannot calculate %s + %s\r\n' % (channel, addnum1, addnum2)) def main(): try: ex_start() except: main() ex_start()