""" rePYbot2.py (C)2008 Don A. Hanlen I make no claims, and take no reponsibility, for use or abuse of this code! I require those who DO use it to cite its source! If this code is used for commercial purposes I expect a (negotiable) cut! This is the main() for rePYbot, a reputation and saved-games bot for FIBS. It is written in Python 2.5.2, retrofitted for Python 1.5.2 (OWT's v) file hierarchy: rePYbot2 RBhandler FIBStn15 RBcommand(RBhandler.whois, RBhandler.query, RBhandler.tell) RepList(RBhandler.tell) rbos SavedGames RBhelp """ from RBhandler import RBhandler from RBcommand import RBcommand from string import find, lower import time True = 1==1 False = not True shoutLimit = 100 ## time allowed between shouts lastMod = "June 01, 2008" master = 'don' ## the only user who can 'tell' special commands DEBUG = 'rePYbot' DEBUG = 'PYbot' ## uncomment this to use for PYbot testing: DEBUG DEBUG = 'check' ## uncomment this for simple diagnostic compile: DEBUG if DEBUG=='PYbot': ## DEBUG UID = 'PYbot' UPWORD = '' ## PASSWORD !!!!!!!!!!!!!!!!!!!! UCLIENT = '=US_don_PYbot!!!!!!!' OUTFILE = 'PYbotout.txt' REPFILE = 'PYrepDict' PRINTER = 'console' elif DEBUG=='rePYbot': UID = 'rePYbot' UPWORD = '' ## PASSWORD !!!!!!!!!!!!!!!!!!!! UCLIENT = '=US_don_rePYbot!!!!!' OUTFILE = 'rePYbotout.txt' REPFILE = 'repDict' PRINTER = '' def reconstruct(line): """ return str:list separated by ' 's, [chop:] """ output = "" for x in line[2:]: output = output + x + ' ' return output if DEBUG != 'check': intro = "*** Hi! I'm don's reputation and saved-games bot.\ 'tell %s help' for information. ***" %UID def rbmain(): """ duh, main() >>direct traffic and 'live' commands: master tell botName CC FIBS command... >> execute FIBS' command master tell botName SG >> update Saved Games from FIBS.com master tell botName EX >> logout tell botName WH >> RBhandler.whoami """ RBhh = RBhandler(UID, UPWORD, UCLIENT, PRINTER) RBcc = RBcommand(REPFILE, UID, RBhh.tell, RBhh.whois, RBhh.query) if not PRINTER: logger = open(OUTFILE, 'w') if DEBUG=='rePYbot': RBhh.command("shout "+intro) else: RBhh.command("tell %s " %master + intro) lastShout = time.time() while True: tell = RBhh.getRequest() ## ['user', 'blah'(, ...)] if tell: if PRINTER: print "main tell:%s" %reconstruct(tell)[:68] else: logger.write(reconstruct(tell)) if len(tell)==2 and tell[1]=="EX" and tell[0]==master: RBhh.logout() elif len(tell)>=2 and tell[1]=="CC" and tell[0]==master: RBhh.command(reconstruct(tell)) elif len(tell)==2 and tell[1]=="SG" and tell[0]==master: RBhh.tell(master, RBcc.updateSavedGames()) elif len(tell)==2 and tell[1]=="WH": RBhh.tell(tell[0], RBhh.whoami()) elif len(tell)>1: RBcc.command(tell) shout = RBhh.getShout if shout: pass if DEBUG !='check': rbmain()