2 import string, cPickle, random, urllib, sys
3 from irclib import irc_lower, nm_to_n
6 def karmaq(bot, cmd, nick, conn, public):
10 if bot.karma.dict.has_key(cmd.split()[1]):
11 conn.privmsg(bot.channel, "%s has karma %s."
13 bot.karma.dict[cmd.split()[1]]))
15 conn.privmsg(bot.channel, "%s has no karma set." %
18 conn.privmsg(bot.channel, "I have karma on %s items." %
19 len(bot.karma.dict.keys()))
23 if bot.karma.dict.has_key(cmd.split()[1]):
24 conn.notice(nick, "%s has karma %s." %
26 bot.karma.dict[cmd.split()[1]]))
28 conn.notice(nick, "I have karma on %s items." %
29 len(bot.karma.dict.keys()))
31 conn.notice(nick, "I have karma on %s items." %
32 len(bot.karma.dict.keys()))
34 def infoq(bot, cmd, nick, conn, public):
36 conn.privmsg(bot.channel,
37 "I am Acrobat %s, on %s, as nick %s." %
38 (bot.revision.split()[1], bot.channel, conn.get_nickname()))
39 conn.privmsg(bot.channel,
40 "My owner is %s; I have karma on %s items." %
41 (bot.owner, len(bot.karma.dict.keys())))
43 conn.notice(nick, "I am Acrobat %s, on %s, as nick %s." %
44 (bot.revision.split()[1], bot.channel, conn.get_nickname()))
45 conn.notice(nick, "My owner is %s; I have karma on %s items." %
46 (bot.owner, len(bot.karma.dict.keys())))
49 def troutq(bot, cmd, nick, conn, public):
51 target = string.join(cmd.split()[1:])
52 me = bot.connection.get_nickname()
53 trout_msg = random.choice(bot.trouts)
54 # The bot won't trout itself;
55 if irc_lower(me) == irc_lower(target):
57 conn.action(bot.channel, trout_msg % target)
59 if random.random() <= bot.config.selftroutrisk:
60 conn.action(bot.channel,
61 "notes %s is conducting a whispering campaign." % nick)
63 conn.notice(nick, "Who do you wish me to trout?")
66 def reloadq(bot, cmd, nick, conn, public):
67 if irc_lower(nick) == irc_lower(bot.owner):
70 bot.trouts = bot.config.trouts
71 conn.privmsg(nick, "Config reloaded.")
73 conn.notice(nick, "Config reloading failed!")
75 conn.notice(nick, "This command can only be invoked by my owner.")
78 def quitq(bot, cmd, nick, conn, public):
79 if irc_lower(nick) == irc_lower(bot.owner):
81 f = open(bot.karmafilename, "w")
82 cPickle.dump(bot.karma, f)
85 sys.stderr.write("Problems dumping karma: probably lost :(")
86 bot.die(msg = "I have been chosen!")
88 conn.privmsg(nick, "Such aggression in public!")
90 conn.notice(nick, "You're not my owner.")
92 # google for something
93 def googleq(bot, cmd, nick, conn, public):
94 cmdrest = string.join(cmd.split()[1:])
95 #sys.stderr.write(conn)
96 # "I'm Feeling Lucky" rather than try and parse the html
97 targ = ("http://www.google.com/search?q=%s&btnI=I'm+Feeling+Lucky"
98 % urllib.quote_plus(cmdrest))
100 # get redirected and grab the resulting url for returning
101 gsearch = urllib.urlopen(targ).geturl()
102 if gsearch != targ: # we've found something
104 conn.notice(nick, str(gsearch))
105 else: # we haven't found anything.
106 conn.privmsg(nick, str(gsearch))
109 conn.notice(nick, "No pages found.")
111 conn.privmsg(nick, "No pages found.")
112 except IOError: # if the connection times out. This blocks. :(
114 conn.notice(nick, "The web's broken. Waah!")
116 conn.privmsg(nick, "The web's broken. Waah!")
118 ### say to msg/channel
119 def sayq(bot, cmd, nick, conn, public):
120 if irc_lower(nick) == irc_lower(bot.owner):
121 conn.privmsg(bot.channel, string.join(cmd.split()[1:]))
123 conn.privmsg(nick, "You're not my owner!")
125 ### action to msg/channel
126 def doq(bot, cmd, nick, conn, public):
127 sys.stderr.write(irc_lower(bot.owner))
128 sys.stderr.write(irc_lower(nick))
130 if irc_lower(nick) == irc_lower(bot.owner):
131 conn.action(bot.channel, string.join(cmd.split()[1:]))
133 conn.privmsg(nick, "You're not my owner!")
136 def disconnq(bot, cmd, nick, conn, public):
137 if cmd == "disconnect": # hop off for 60s
138 bot.disconnect(msg="Be right back.")