2 from basic_commands
import reply
, troggie
3 from globals import commands
4 from throttle
import throttle
6 web_throttle
= throttle("web")
8 def title(who
, where
, args
, all
=False):
9 "$title <url>: Asks Hal to fetch the title of a given URL. Not very useful in a channel, where it's done implicitly whenever someone says a URL."
10 if html
.non_webpage(args
):
13 reply(who
, where
, "[%s]" % (html
.get_title(args
)), all
)
15 #if not html.is_webpage(args):
17 reply(who
, where
, "Error retrieving URL '%s'." % args
, all
)
18 title
= troggie(title
)
19 title
= throttle("web", quiet
=True)(title
)
20 commands
['title'] = (perms
.voice
, title
)
22 def title_implicit(who
, where
, args
):
23 "Implicit version of $title."
24 title(who
, where
, args
, all
=True)
25 commands
['title implicit'] = (perms
.voice
, title_implicit
)
27 def calc(who
, where
, args
):
28 "$calc <math>: Asks Google's calculator to do some math for you."
30 reply(who
, where
, "Google says: %s" % html
.google_calc(args
), all
=True)
33 reply(who
, where
, "Ewwww... Google barfed on me.", all
=True)
35 calc
= web_throttle(calc
)
36 commands
['calc'] = (perms
.voice
, calc
)
38 def google(who
, where
, args
):
39 "$google <search>: Asks Google for its first result for a given search."
41 url
= html
.first_google(args
)
42 reply(who
, where
, "Google says: %s [%s]." % (url
, html
.get_title(url
)), all
=True)
45 reply(who
, where
, "Ewwww... Google barfed on me.", all
=True)
46 #google = troggie(google)
47 google
= web_throttle(google
)
48 commands
['google'] = (perms
.voice
, google
)
50 def jig(who
, where
, args
):
51 "$jig <search>: Ask Google for its first result for a given search, restricted to Jayisgames."
52 google(who
, where
, args
+ " site:jayisgames.com")
54 commands
['jig'] = (perms
.voice
, jig
)
56 def wp(who
, where
, args
):
57 "$wp <search> or $wikipedia <search>: Asks Google for its first result for a given search, restricted to Wikipedia."
58 google(who
, where
, args
+ " site:en.wikipedia.org")
59 commands
['wp'] = (perms
.voice
, wp
)
60 commands
['wikipedia'] = (perms
.voice
, wp
)
62 def youtube(who
, where
, args
):
63 "$youtube <search>: Asks Google for its first result for a given search, restricted to YouTube."
64 google(who
, where
, args
+ " site:youtube.com")
65 commands
['youtube'] = (perms
.voice
, youtube
)
67 def onr(who
, where
, args
, comic
=None):
68 "$onr <search>: Searches OhNoRobot.com, returns the first result."
70 url
= html
.first_onr(args
, comic
)
71 reply(who
, where
, "OhNoRobot.com says: %s [%s]." % (url
, html
.get_title(url
)), all
=True)
74 reply(who
, where
, "Oh no! No luck.", all
=True)
75 onr
= web_throttle(onr
)
76 commands
['onr'] = (perms
.voice
, onr
)
78 def xkcd(who
, where
, args
):
79 "$xkcd <search>: Searches XKCD comics with OhNoRobot.com."
80 onr(who
, where
, args
, 56)
81 commands
['xkcd'] = (perms
.voice
, xkcd
)
83 def weather(who
, where
, args
):
84 "$weather <zipcode or location>: Asks Hal for the weather in a given location. Unfortunately, he doesn't know how yet."
85 reply(who
, where
, "I'm sorry, troggie isn't here, and I don't know how to do that.")
86 weather
= troggie(weather
)
87 commands
['weather'] = (perms
.voice
, weather
)
89 def reset_throttle(who
, where
, args
):
90 "$reset-throttle: Resets Hal's throttling mechanism for web requests."
91 reply(who
, where
, "Throttling reset.")
92 reset_throttle
= throttle("web", seconds_between
=.1)(reset_throttle
)
93 commands
['reset-throttle'] = (perms
.ircop
, reset_throttle
)