chiark / gitweb /
Found in /home/matthew/programming/irc/bot - live version, all files as found
[irc.git] / commands.py.rej
diff --git a/commands.py.rej b/commands.py.rej
new file mode 100644 (file)
index 0000000..271ff08
--- /dev/null
@@ -0,0 +1,42 @@
+***************
+*** 133,138 ****
+              bot.automsg(public,nick,str(gsearch))
+          else: # we haven't found anything.
+             bot.automsg(public,nick,"No pages found.")
+      except IOError: # if the connection times out. This blocks. :(
+         bot.automsg(public,nick,"The web's broken. Waah!")
+  
+--- 133,165 ----
+              bot.automsg(public,nick,str(gsearch))
+          else: # we haven't found anything.
+             bot.automsg(public,nick,"No pages found.")
++     except IOError: # if the connection times out. This blocks. :(
++        bot.automsg(public,nick,"The web's broken. Waah!")
++ 
++ # Look up the definition of something using google
++ def defineq(bot, cmd, nick, conn, public):
++     cmdrest = string.join(cmd.split()[1:])
++     targ = ("http://www.google.com/search?q=define%%3A%s&ie=utf-8&oe=utf-8"
++             % urllib.quote_plus(cmdrest))
++     try:
++         # Just slurp everything into a string
++         defnpage = urllib.urlopen(targ).read()
++         # For definitions we really do have to parse the HTML, sadly.
++         # This is of course going to be a bit fragile. We first look for
++         # 'Definitions of %s on the Web' -- if this isn't present we
++         # assume we have the 'no definitions found page'.
++         # The first defn starts after the following <p> tag.
++         # Following that we assume that each definition is all the non-markup
++         # before a <br> tag. Currently we just dump out the first definition.
++         match = re.search(r"Definitions of <b>.*?</b> on the Web.*?<p>\s*([^>]*)<br>",defnpage,re.MULTILINE)
++         if match == None:
++            bot.automsg(public,nick,"Some things defy definition.")
++         else:
++            # We assume google has truncated the definition for us so this
++            # won't flood the channel with text...
++            defn = " ".join(match.group(1).split("\n"));
++            bot.automsg(public,nick,defn)
++ 
+      except IOError: # if the connection times out. This blocks. :(
+         bot.automsg(public,nick,"The web's broken. Waah!")
+