X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=blobdiff_plain;f=commands.py;h=38769876bff1ff5a4a730f78f6f95c729952475c;hp=637ec5fddffbbb14f4d1d9c0b5c2b302f2c48753;hb=426774374f607b0961b9ea30cee0fa8ae4927441;hpb=9e280b60903fa9ce16809540ec6c8174adb762cd diff --git a/commands.py b/commands.py old mode 100644 new mode 100755 index 637ec5f..3876987 --- a/commands.py +++ b/commands.py @@ -1,5 +1,5 @@ # Part of Acrobat. -import string, cPickle, random, urllib, sys, time, re, os +import string, cPickle, random, urllib, sys, time, re, os, twitter, subprocess, datetime from irclib import irc_lower, nm_to_n # query karma @@ -36,7 +36,7 @@ def karmadelq(bot, cmd, nick, conn, public, karma): # help - provides the URL of the help file def helpq(bot, cmd, nick, conn, public): bot.automsg(public,nick, - "For help see http://www.pick.ucam.org/~matthew/irc/servus.html") + "For help see http://www.chiark.greenend.org.uk/~matthewv/irc/servus.html") # query bot status @@ -61,6 +61,9 @@ def fish_quota(pond): pond.cur_fish=pond.max_fish pond.quotatime=time.time() +# List of things the bot might be called to work round the self-trouting code +synonyms=["itself","the bot","themself"] + # trout someone, or flirt with them def troutq(bot, cmd, nick, conn, public, cfg): fishlist=cfg[0] @@ -84,8 +87,9 @@ def troutq(bot, cmd, nick, conn, public, cfg): return me = bot.connection.get_nickname() trout_msg = random.choice(fishlist) + fishpond.last=trout_msg # The bot won't trout or flirt with itself; - if irc_lower(me) == irc_lower(target): + if irc_lower(me) == irc_lower(target) or irc_lower(target) in synonyms: target = nick # There's a chance the game may be given away if the request was not # public... @@ -124,13 +128,14 @@ def slashq(bot, cmd, nick, conn, public, cfg): return me = bot.connection.get_nickname() slash_msg = random.choice(fishlist) + fishpond.last=slash_msg # The bot won't slash people with themselves if irc_lower(who[0]) == irc_lower(who[1]): conn.notice(nick, "oooooh no missus!") return # The bot won't slash with itself, instead slashing the requester for n in [0,1]: - if irc_lower(me) == irc_lower(who[n]): + if irc_lower(me) == irc_lower(who[n]) or irc_lower(who[n]) in synonyms: who[n] = nick # Perhaps someone asked to slash themselves with the bot then we get if irc_lower(who[0]) == irc_lower(who[1]): @@ -154,9 +159,9 @@ def unitq(bot, cmd, nick, conn, public): conn.notice(nick, "syntax: units arg1 as arg2") return if args[1]=='?': - sin,sout=os.popen2(["units","--verbose",args[0]],"r") + sin,sout=os.popen4(["units","--verbose","--",args[0]],"r") else: - sin,sout=os.popen2(["units","--verbose",args[0],args[1]],"r") + sin,sout=os.popen4(["units","--verbose","--",args[0],args[1]],"r") sin.close() res=sout.readlines() #popen2 doesn't clean up the child properly. Do this by hand @@ -187,24 +192,6 @@ def reloadq(bot, cmd, nick, conn, public): bot.automsg(public,nick, "Configuration can only be reloaded by my owner, by /msg.") -# lose the game and/or install a new trigger word -def gameq(bot, cmd, nick, conn, public, game): - #only install a new trigger if it's not too short. - if len(' '.join(cmd.split()[1:]))>2: - game.trigger=' '.join(cmd.split()[1:]) - if (time.time()> game.grace): - if not public: - if irc_lower(nick) == irc_lower(bot.owner): - conn.action(bot.channel,"loses the game!") - else: - conn.privmsg(bot.channel,nick+" just lost the game!") - else: - if not public: - conn.notice(nick, "It's a grace period!") - game.grace=time.time()+60*20 #20 minutes' grace - game.losetime=time.time()+random.randrange(game.minlose,game.maxlose) - conn.notice(bot.owner, str(game.losetime-time.time())+" "+game.trigger) - # quit irc def quitq(bot, cmd, nick, conn, public): if irc_lower(nick) == irc_lower(bot.owner): @@ -232,8 +219,11 @@ def googleq(bot, cmd, nick, conn, public): # Look up the definition of something using google def defineq(bot, cmd, nick, conn, public): + #this doesn't work any more + bot.automsg(public,nick,"'define' is broken because google are bastards :(") + return cmdrest = string.join(cmd.split()[1:]) - targ = ("http://www.google.com/search?q=define%%3A%s&ie=utf-8&oe=utf-8" + targ = ("http://www.google.co.uk/search?q=define%%3A%s&ie=utf-8&oe=utf-8" % urllib.quote_plus(cmdrest)) try: # Just slurp everything into a string @@ -242,10 +232,11 @@ def defineq(bot, cmd, nick, conn, public): # This is of course going to be a bit fragile. We first look for # 'Definitions of %s on the Web' -- if this isn't present we # assume we have the 'no definitions found page'. - # The first defn starts after the following

tag. + # The first defn starts after the following

tag, but as the + # first

  • in a