2 import string, cPickle, random, urllib, sys, time
3 from irclib import irc_lower, nm_to_n
6 def karmaq(bot, cmd, nick, conn, public, karma):
8 item=cmd.split()[1].lower()
12 bot.automsg(public,nick,"I have karma on %s items." %
14 elif karma.has_key(item):
15 bot.automsg(public,nick,"%s has karma %s."
18 bot.automsg(public,nick, "%s has no karma set." % item)
21 def karmadelq(bot, cmd, nick, conn, public, karma):
23 item=cmd.split()[1].lower()
25 conn.notice(nick, "What should I delete?")
28 conn.notice(nick, "You are not my owner.")
30 if karma.has_key(item):
32 conn.notice(nick, "Item %s deleted."%item)
34 conn.notice(nick, "There is no karma stored for %s."%item)
37 def infoq(bot, cmd, nick, conn, public, karma):
38 bot.automsg(public,nick,
39 ("I am Acrobat %s, on %s, as nick %s. "+
40 "My owner is %s; I have karma on %s items.") %
41 (bot.revision.split()[1], bot.channel, conn.get_nickname(),
42 bot.owner, len(karma.keys())))
44 # Check on fish stocks
47 if time.time()>=pond.quotatime:
51 if (time.time()-pond.quotatime)>pond.fish_time_inc:
52 pond.cur_fish+=(((time.time()-pond.quotatime)
53 /pond.fish_time_inc)*pond.fish_inc)
54 if pond.cur_fish>pond.max_fish:
55 pond.cur_fish=pond.max_fish
56 pond.quotatime=time.time()
58 # trout someone, or flirt with them
59 def troutq(bot, cmd, nick, conn, public, cfg):
66 selftroutchance=cfg[6]
70 conn.notice(nick, quietmsg%fishpond.Boring_Git)
72 if fishpond.cur_fish<=0:
73 conn.notice(nick, nofishmsg)
75 target = string.join(cmd.split()[1:])
77 conn.notice(nick, notargetmsg)
79 me = bot.connection.get_nickname()
80 trout_msg = random.choice(fishlist)
81 # The bot won't trout or flirt with itself;
82 if irc_lower(me) == irc_lower(target):
84 # There's a chance the game may be given away if the request was not
87 if random.random()<=selftroutchance:
88 trout_msg=trout_msg+(selftrout%nick)
90 conn.action(bot.channel, trout_msg % target)
93 # Shut up trouting for a minute
94 def nofishq(bot, cmd, nick, conn, public, fish):
98 fish.quotatime=time.time()
99 fish.quotatime+=fish.nofish_time
100 conn.notice(nick, "Fish stocks depleted, as you wish.")
103 def reloadq(bot, cmd, nick, conn, public):
104 if not public and irc_lower(nick) == irc_lower(bot.owner):
107 conn.notice(nick, "Config reloaded.")
109 conn.notice(nick, "Config reloading failed!")
111 bot.automsg(public,nick,
112 "Configuration can only be reloaded by my owner, by /msg.")
115 def quitq(bot, cmd, nick, conn, public):
116 if irc_lower(nick) == irc_lower(bot.owner):
117 bot.die(msg = "I have been chosen!")
119 conn.notice(nick, "Such aggression in public!")
121 conn.notice(nick, "You're not my owner.")
123 # google for something
124 def googleq(bot, cmd, nick, conn, public):
125 cmdrest = string.join(cmd.split()[1:])
126 # "I'm Feeling Lucky" rather than try and parse the html
127 targ = ("http://www.google.com/search?q=%s&btnI=I'm+Feeling+Lucky"
128 % urllib.quote_plus(cmdrest))
130 # get redirected and grab the resulting url for returning
131 gsearch = urllib.urlopen(targ).geturl()
132 if gsearch != targ: # we've found something
133 bot.automsg(public,nick,str(gsearch))
134 else: # we haven't found anything.
135 bot.automsg(public,nick,"No pages found.")
136 except IOError: # if the connection times out. This blocks. :(
137 bot.automsg(public,nick,"The web's broken. Waah!")
139 ### say to msg/channel
140 def sayq(bot, cmd, nick, conn, public):
141 if irc_lower(nick) == irc_lower(bot.owner):
142 conn.privmsg(bot.channel, string.join(cmd.split()[1:]))
145 conn.notice(nick, "You're not my owner!")
147 ### action to msg/channel
148 def doq(bot, cmd, nick, conn, public):
149 sys.stderr.write(irc_lower(bot.owner))
150 sys.stderr.write(irc_lower(nick))
152 if irc_lower(nick) == irc_lower(bot.owner):
153 conn.action(bot.channel, string.join(cmd.split()[1:]))
155 conn.notice(nick, "You're not my owner!")
158 def disconnq(bot, cmd, nick, conn, public):
159 if cmd == "disconnect": # hop off for 60s
160 bot.disconnect(msg="Be right back.")
162 ### list keys of a dictionary
163 def listkeysq(bot, cmd, nick, conn, public, dict):
164 bot.automsg(public,nick,string.join(dict.keys()))