3 bot.automsg(public,nick,str(gsearch))
4 else: # we haven't found anything.
5 bot.automsg(public,nick,"No pages found.")
6 except IOError: # if the connection times out. This blocks. :(
7 bot.automsg(public,nick,"The web's broken. Waah!")
10 bot.automsg(public,nick,str(gsearch))
11 else: # we haven't found anything.
12 bot.automsg(public,nick,"No pages found.")
13 + except IOError: # if the connection times out. This blocks. :(
14 + bot.automsg(public,nick,"The web's broken. Waah!")
16 + # Look up the definition of something using google
17 + def defineq(bot, cmd, nick, conn, public):
18 + cmdrest = string.join(cmd.split()[1:])
19 + targ = ("http://www.google.com/search?q=define%%3A%s&ie=utf-8&oe=utf-8"
20 + % urllib.quote_plus(cmdrest))
22 + # Just slurp everything into a string
23 + defnpage = urllib.urlopen(targ).read()
24 + # For definitions we really do have to parse the HTML, sadly.
25 + # This is of course going to be a bit fragile. We first look for
26 + # 'Definitions of %s on the Web' -- if this isn't present we
27 + # assume we have the 'no definitions found page'.
28 + # The first defn starts after the following <p> tag.
29 + # Following that we assume that each definition is all the non-markup
30 + # before a <br> tag. Currently we just dump out the first definition.
31 + match = re.search(r"Definitions of <b>.*?</b> on the Web.*?<p>\s*([^>]*)<br>",defnpage,re.MULTILINE)
33 + bot.automsg(public,nick,"Some things defy definition.")
35 + # We assume google has truncated the definition for us so this
36 + # won't flood the channel with text...
37 + defn = " ".join(match.group(1).split("\n"));
38 + bot.automsg(public,nick,defn)
40 except IOError: # if the connection times out. This blocks. :(
41 bot.automsg(public,nick,"The web's broken. Waah!")