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):
16 reply(who
, where
, "Error retrieving URL '%s'." % args
, all
)
17 title
= troggie(title
)
18 title
= throttle("web", quiet
=True)(title
)
19 commands
['title'] = (perms
.voice
, title
)
21 def title_implicit(who
, where
, args
):
22 "Implicit version of $title."
23 title(who
, where
, args
, all
=True)
24 commands
['title implicit'] = (perms
.voice
, title_implicit
)
26 def calc(who
, where
, args
):
27 "$calc <math>: Asks Google's calculator to do some math for you."
29 reply(who
, where
, "Google says: %s" % html
.google_calc(args
), all
=True)
31 reply(who
, where
, "Ewwww... Google barfed on me.", all
=True)
33 calc
= web_throttle(calc
)
34 commands
['calc'] = (perms
.voice
, calc
)
36 def google(who
, where
, args
):
37 "$google <search>: Asks Google for its first result for a given search."
39 url
= html
.first_google(args
)
40 reply(who
, where
, "Google says: %s [%s]." % (url
, html
.get_title(url
)), all
=True)
42 reply(who
, where
, "Ewwww... Google barfed on me.", all
=True)
43 #google = troggie(google)
44 google
= web_throttle(google
)
45 commands
['google'] = (perms
.voice
, google
)
47 def jig(who
, where
, args
):
48 "$jig <search>: Ask Google for its first result for a given search, restricted to Jayisgames."
49 google(who
, where
, args
+ " site:jayisgames.com")
51 commands
['jig'] = (perms
.voice
, jig
)
53 def wp(who
, where
, args
):
54 "$wp <search> or $wikipedia <search>: Asks Google for its first result for a given search, restricted to Wikipedia."
55 google(who
, where
, args
+ " site:en.wikipedia.org")
56 commands
['wp'] = (perms
.voice
, wp
)
57 commands
['wikipedia'] = (perms
.voice
, wp
)
59 def youtube(who
, where
, args
):
60 "$youtube <search>: Asks Google for its first result for a given search, restricted to YouTube."
61 google(who
, where
, args
+ " site:youtube.com")
62 commands
['youtube'] = (perms
.voice
, youtube
)
64 def onr(who
, where
, args
, comic
=None):
65 "$onr <search>: Searches OhNoRobot.com, returns the first result."
67 url
= html
.first_onr(args
, comic
)
68 reply(who
, where
, "OhNoRobot.com says: %s [%s]." % (url
, html
.get_title(url
)), all
=True)
70 reply(who
, where
, "Oh no! No luck.", all
=True)
71 onr
= web_throttle(onr
)
72 commands
['onr'] = (perms
.voice
, onr
)
74 def xkcd(who
, where
, args
):
75 "$xkcd <search>: Searches XKCD comics with OhNoRobot.com."
76 onr(who
, where
, args
, 56)
77 commands
['xkcd'] = (perms
.voice
, xkcd
)
79 def weather(who
, where
, args
):
80 "$weather <zipcode or location>: Asks Hal for the weather in a given location. Unfortunately, he doesn't know how yet."
81 reply(who
, where
, "I'm sorry, troggie isn't here, and I don't know how to do that.")
82 weather
= troggie(weather
)
83 commands
['weather'] = (perms
.voice
, weather
)
85 def reset_throttle(who
, where
, args
):
86 "$reset-throttle: Resets Hal's throttling mechanism for web requests."
87 reply(who
, where
, "Throttling reset.")
88 reset_throttle
= throttle("web", seconds_between
=.1)(reset_throttle
)
89 commands
['reset-throttle'] = (perms
.ircop
, reset_throttle
)