def procinput(inp): """ processes data received from eotl for potential user requests """ buf = "" # Define scope for the buffer global feed #print inp # extract tells from input and acts on them, output is buffered # and returned in a block for delivery m = re.findall('^([A-Za-z]+) tells you: (.*)$', inp, re.M) m += re.findall('^\[-Gamez-\] ([A-Za-z]+): (.*)$', inp, re.M) for data in m: plname = string.lower(data[0]) s = data[1][:-1].lstrip().rstrip() rg = re.match('!help$', s) if rg: buf += "echo ' Get a tinyurl with !tiny <url>' "+plname+"\n" \ "echo ' ??foo search by entry title' "+plname+"\n" \ "echo ' **bar search for bar within entry bodies' "+plname+"\n" \ "echo ' - Multipe search terms can be seperated by &&' "+plname+"\n" \ "echo ' - ie: tell rodney ** fire resistance && eating' "+plname+"\n" \ "echo ' !rank player rankings by ascensions' "+plname+"\n" \ "echo ' !moonphase lists current effects from the moon if any' "+plname+"\n" \ "echo ' !gamesby <player> shows statistics from players games' "+plname+"\n" \ "echo ' -- Ascension gamedumps available at:' "+plname+"\n" \ "echo ' 'http://nethack.eotl.org/~tylinial/' "+plname+"\n" continue rg = re.match('!rank$', s) if rg: count = 0 foo = halloffame() buf += "tell " + plname + " Ranking by Ascensions\n" for [name, score] in foo: count += 1 buf += "tell " + plname + " " + str( count) + ".. " + name + ": " + str(score) + "\n" rg = re.match('!gamesby (.*)$', s) if rg: foo = gamesby(rg.group(1)) buf += "tell "+plname+" "+rg.group(1).capitalize()+" has played "+str(foo[0])+ \ " with highest score "+str(foo[1])+", ascended "+str(foo[2])+", died "+str(foo[3])+\ ", lifesaved "+str(foo[4])+", quit "+str(foo[5])+", escaped "+str(foo[6])+" times." rg = re.match('^\?\?(.*)\[(\d)\]$', s) if rg: d = rodlib.find(rg.group(1).lstrip(), int(rg.group(2))) for item in d: buf += "tell " + plname + " " + item[1] + ": " + item[2] + "\n" if not d: buf += "tell " + plname + " No results, try without the index.\n" continue rg = re.match('^\?\?(.*)$', s) if rg: d = rodlib.find(rg.group(1).lstrip()) for item in d: buf += "tell " + plname + " " + item[1] + ": " + item[2] + "\n" if not d: buf += "tell " + plname + " No results, try a search.\n" continue rg = re.match('^\*\*(.*)$', s) if rg: d = rodlib.search(rg.group(1).lstrip()) for item in d: buf += "tell " + plname + " " + item[1] + ": " + item[2] + "\n" if not d: buf += "tell " + plname + " No results.\n" continue rg = re.match('^!tiny (.*)$', s) if rg: buf += "tell " + plname + " " + tinyurl.getTinyurl( rg.group(1)) + "\n" continue rg = re.match('^!doupdatenow$', s) if rg: buf += "tell " + plname + " " if rodlib.update(True): rodlib.loaddata() buf += "Update complete.\n" else: buf += "Update failed.\n" continue rg = re.match('^!lastupdate$', s) if rg: buf += "tell " + plname + " Last update : " + time.ctime( rodlib.lastupdate()) + "\n" buf += "tell " + plname + " Current time: " + time.ctime() + "\n" continue rg = re.match('^!lastgame (.*)$', s) if rg: s = lastgame(rg.group(1)) if s: buf += "tell " + plname + " " + s + "\n" else: buf += "tell " + plname + " Couldn't find a lastgame for " + rg.group( 1) + "\n" continue rg = re.match('^!moonphase$', s) if rg: if luckmsg: buf += "tell " + plname + " " + luckmsg + '\n' else: buf += "tell " + plname + " No unusual moon phase info right now\n" continue rg = re.match('^!updatefeed$', s) if rg: try: del feed reload(rodfeed) feed = rodfeed.Feed() buf += "tell " + plname + " Reloaded.\n" except: buf += "tell " + plname + " Reload failed.\n" continue rg = re.match('^!updatelib$', s) if rg: try: reload(rodlib) buf += "tell " + plname + " Reloaded.\n" except: buf += "tell " + plname + " Reload failed.\n" continue rg = re.match('^!clearfeed$', s) if rg: feedpoll = [] buf += "tell " + plname + " Feeds cleared.\n" continue return buf
def procinput(inp): """ processes data received from eotl for potential user requests """ buf = "" # Define scope for the buffer global feed #print inp # extract tells from input and acts on them, output is buffered # and returned in a block for delivery m = re.findall('^([A-Za-z]+) tells you: (.*)$', inp, re.M) m += re.findall('^\[-Gamez-\] ([A-Za-z]+): (.*)$', inp, re.M) for data in m: plname = string.lower(data[0]) s = data[1][:-1].lstrip().rstrip() rg = re.match('!help$', s) if rg: buf += "echo ' Get a tinyurl with !tiny <url>' "+plname+"\n" \ "echo ' ??foo search by entry title' "+plname+"\n" \ "echo ' **bar search for bar within entry bodies' "+plname+"\n" \ "echo ' - Multipe search terms can be seperated by &&' "+plname+"\n" \ "echo ' - ie: tell rodney ** fire resistance && eating' "+plname+"\n" \ "echo ' !rank player rankings by ascensions' "+plname+"\n" \ "echo ' !moonphase lists current effects from the moon if any' "+plname+"\n" \ "echo ' !gamesby <player> shows statistics from players games' "+plname+"\n" \ "echo ' -- Ascension gamedumps available at:' "+plname+"\n" \ "echo ' 'http://nethack.eotl.org/~tylinial/' "+plname+"\n" continue rg = re.match('!rank$', s) if rg: count = 0 foo = halloffame() buf += "tell "+plname+" Ranking by Ascensions\n" for [name,score] in foo: count += 1 buf += "tell "+plname+" "+str(count)+".. "+name+": "+str(score)+"\n" rg = re.match('!gamesby (.*)$', s) if rg: foo = gamesby(rg.group(1)) buf += "tell "+plname+" "+rg.group(1).capitalize()+" has played "+str(foo[0])+ \ " with highest score "+str(foo[1])+", ascended "+str(foo[2])+", died "+str(foo[3])+\ ", lifesaved "+str(foo[4])+", quit "+str(foo[5])+", escaped "+str(foo[6])+" times." rg = re.match('^\?\?(.*)\[(\d)\]$', s) if rg: d = rodlib.find(rg.group(1).lstrip(), int(rg.group(2))) for item in d: buf += "tell "+plname+" "+item[1]+": "+item[2]+"\n" if not d: buf += "tell "+plname+" No results, try without the index.\n" continue rg = re.match('^\?\?(.*)$', s) if rg: d = rodlib.find(rg.group(1).lstrip()) for item in d: buf += "tell "+plname+" "+item[1]+": "+item[2]+"\n" if not d: buf += "tell "+plname+" No results, try a search.\n" continue rg = re.match('^\*\*(.*)$', s) if rg: d = rodlib.search(rg.group(1).lstrip()) for item in d: buf += "tell "+plname+" "+item[1]+": "+item[2]+"\n" if not d: buf += "tell "+plname+" No results.\n" continue rg = re.match('^!tiny (.*)$', s) if rg: buf += "tell "+plname+" "+tinyurl.getTinyurl(rg.group(1))+"\n" continue rg = re.match('^!doupdatenow$', s) if rg: buf += "tell "+plname+" " if rodlib.update(True): rodlib.loaddata() buf += "Update complete.\n" else: buf += "Update failed.\n" continue rg = re.match('^!lastupdate$', s) if rg: buf += "tell "+plname+" Last update : "+time.ctime(rodlib.lastupdate())+"\n" buf += "tell "+plname+" Current time: "+time.ctime()+"\n" continue rg = re.match('^!lastgame (.*)$', s) if rg: s = lastgame(rg.group(1)) if s: buf += "tell "+plname+" "+s+"\n" else: buf += "tell "+plname+" Couldn't find a lastgame for "+rg.group(1)+"\n" continue rg = re.match('^!moonphase$', s) if rg: if luckmsg: buf += "tell "+plname+" "+luckmsg+'\n' else: buf += "tell "+plname+" No unusual moon phase info right now\n" continue rg = re.match('^!updatefeed$', s) if rg: try: del feed reload(rodfeed) feed = rodfeed.Feed() buf += "tell "+plname+" Reloaded.\n" except: buf += "tell "+plname+" Reload failed.\n" continue rg = re.match('^!updatelib$', s) if rg: try: reload(rodlib) buf += "tell "+plname+" Reloaded.\n" except: buf += "tell "+plname+" Reload failed.\n" continue rg = re.match('^!clearfeed$', s) if rg: feedpoll = [] buf += "tell "+plname+" Feeds cleared.\n" continue return buf
tmp = hackmoon.luckmsg() if tmp != luckmsg: # Dont show normal scenarios, no msg if tmp: EOTLSock.send(ESC + "game " + tmp + '\n') if luckmsg and not tmp: EOTLSock.send(ESC+"game The moon moves into its " +\ numsuffix(hackmoon.phase_of_the_moon())+" phase.\n") luckmsg = tmp else: # if its not yet time increment the timer moonchk = moonchk + 1 #request update, if done advise if rodlib.update(): rodlib.loaddata() print "Rodney: Done update.\n" # if theres some new feed items add them to poll # for display feeditems = feed.update() if feeditems: feedpoll += feeditems # if there is news outstanding and its been more than 45 secs since the last display item if feedpoll and feedtimer < time.time(): entry = feedpoll.pop(0) # hack because some feeds have some antiascii bs - if it doesnt work, forget it try: EOTLSock.send(ESC + 'channel ' + entry[2] + ' ' +
tmp = hackmoon.luckmsg() if tmp != luckmsg: # Dont show normal scenarios, no msg if tmp: EOTLSock.send(ESC+"game "+tmp+'\n') if luckmsg and not tmp: EOTLSock.send(ESC+"game The moon moves into its " +\ numsuffix(hackmoon.phase_of_the_moon())+" phase.\n") luckmsg = tmp else: # if its not yet time increment the timer moonchk = moonchk + 1 #request update, if done advise if rodlib.update(): rodlib.loaddata() print "Rodney: Done update.\n" # if theres some new feed items add them to poll # for display feeditems = feed.update() if feeditems: feedpoll += feeditems # if there is news outstanding and its been more than 45 secs since the last display item if feedpoll and feedtimer < time.time(): entry = feedpoll.pop(0) # hack because some feeds have some antiascii bs - if it doesnt work, forget it try: EOTLSock.send(ESC+'channel '+entry[2]+' '+toascii(entry[1]['title'] +' '+tinyurl.getTinyurl(entry[1]['link'])+'\n'))