+ Overall licensing information.
[halbot.git] / web.py
blobd81ff91b65b69862f22e296997169adec7bba690
1 import html, perms
2 from basic_commands import reply, troggie
3 from globals import commands
5 def title(who, where, args, all=False):
6 "$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."
7 if html.non_webpage(args):
8 return
9 try:
10 reply(who, where, "[%s]" % (html.get_title(args)), all)
11 except Exception, e:
12 #if not html.is_webpage(args):
13 print e
14 reply(who, where, "Error retrieving URL '%s'." % args, all)
15 title = troggie(title)
16 commands['title'] = (perms.voice, title)
18 def title_implicit(who, where, args):
19 "Implicit version of $title."
20 title(who, where, args, all=True)
21 commands['title implicit'] = (perms.voice, title_implicit)
23 def calc(who, where, args):
24 "$calc <math>: Asks Google's calculator to do some math for you."
25 try:
26 reply(who, where, "Google says: %s" % html.google_calc(args), all=True)
27 except Exception, e:
28 print e
29 reply(who, where, "Ewwww... Google barfed on me.", all=True)
30 #calc = troggie(calc)
31 commands['calc'] = (perms.voice, calc)
33 def google(who, where, args):
34 "$google <search>: Asks Google for its first result for a given search."
35 try:
36 url = html.first_google(args)
37 reply(who, where, "Google says: %s [%s]." % (url, html.get_title(url)), all=True)
38 except Exception, e:
39 print e
40 reply(who, where, "Ewwww... Google barfed on me.", all=True)
41 #google = troggie(google)
42 commands['google'] = (perms.voice, google)
44 def jig(who, where, args):
45 "$jig <search>: Ask Google for its first result for a given search, restricted to Jayisgames."
46 google(who, where, args + " site:jayisgames.com")
47 #jig = troggie(jig)
48 commands['jig'] = (perms.voice, jig)
50 def wp(who, where, args):
51 "$wp <search> or $wikipedia <search>: Asks Google for its first result for a given search, restricted to Wikipedia."
52 google(who, where, args + " site:en.wikipedia.org")
53 commands['wp'] = (perms.voice, wp)
54 commands['wikipedia'] = (perms.voice, wp)
56 def onr(who, where, args, comic=None):
57 "$onr <search>: Searches OhNoRobot.com, returns the first result."
58 try:
59 url = html.first_onr(args, comic)
60 reply(who, where, "OhNoRobot.com says: %s [%s]." % (url, html.get_title(url)), all=True)
61 except Exception, e:
62 print e
63 reply(who, where, "Oh no! No luck.", all=True)
64 commands['onr'] = (perms.voice, onr)
66 def xkcd(who, where, args):
67 "$xkcd <search>: Searches XKCD comics with OhNoRobot.com."
68 onr(who, where, args, 56)
69 commands['xkcd'] = (perms.voice, xkcd)
71 def weather(who, where, args):
72 "$weather <zipcode or location>: Asks Hal for the weather in a given location. Unfortunately, he doesn't know how yet."
73 reply(who, where, "I'm sorry, troggie isn't here, and I don't know how to do that.")
74 weather = troggie(weather)
75 commands['weather'] = (perms.voice, weather)