chiark / gitweb /
more trouts from anon
[irc.git] / acrobat-chiark-0.2.py
index ccdf676052f578561113d53a3cdcc631ee934f03..7469ae7b0ac628be1be473e35b07e3b963411b25 100755 (executable)
@@ -1,7 +1,10 @@
-#!/usr/local/bin/python
+#!/usr/bin/env python2
+# $Id$
 #
 # Joel Rosdahl <joel@rosdahl.net>
 # Andrew Walkingshaw <andrew@lexical.org.uk>
+# Peter Corbett <ptc24@cam.ac.uk>
+# Matthew Vernon <matthew@debian.org>
 # 
 # This file is part of Acrobat.
 #
 # by the Free Software Foundation; either version 2 of the License,
 # or (at your option) any later version.
 #
-# Foobar is distributed in the hope that it will be useful,
+# Acrobat is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
 # You should have received a copy of the GNU General Public License
-# along with Foobar; if not, write to the Free Software
+# along with Acrobat; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 # USA.
 
               back with the url.
 """
 
-import string, urllib, sys, cPickle, os
+import string, urllib, sys, cPickle, os, random, re
 from ircbot import SingleServerIRCBot
 from irclib import nm_to_n, irc_lower
 
+
+
 class Karma:
     def __init__(self):
         self.dict = {}
@@ -51,6 +56,12 @@ class Acrobat(SingleServerIRCBot):
             f.close()
         except IOError:
             self.karma = Karma()
+        try:
+            f = open("trouts", "r")
+            self.trouts = [l.strip() for l in f.readlines() if l.find("%s") != -1]
+            f.close()
+        except IOError:
+            self.trouts = [ "hits %s with a wet trout.", "thwaps %s.", "questions %s's parentage.", "pokes its tounge out at %s.", "bites its thumb at %s."]
 
     ## EVENT HANDLERS
             
@@ -123,19 +134,57 @@ class Acrobat(SingleServerIRCBot):
                             len(self.karma.dict.keys()))
     # query bot status
     def infoq(self, cmd, nick, conn, public):
+        # version control magic
+        acrorevision="$Revision$"
+        acrorev1=re.sub(r'\$Revision: (.*)',r'\1',acrorevision)
+        acroversion=re.sub(r'(.*) \$',r'\1',acrorev1)
         if public == 1:
             conn.privmsg(self.channel,
-                         "I am Acrobat 0.2chiark, on %s, as nick %s." %
-                         (self.channel, self.connection.get_nickname()))
+                         "I am Acrobat %s, on %s, as nick %s." %
+                         (acroversion, self.channel, self.connection.get_nickname()))
             conn.privmsg(self.channel,
                          "My owner is %s; I have karma on %s items." %
                          (self.owner, len(self.karma.dict.keys())))
         else:
-            conn.notice(nick, "I am Acrobat 0.2chiark, on %s, as nick %s." %
-                        (self.channel, self.connection.get_nickname()))
+            conn.notice(nick, "I am Acrobat %s, on %s, as nick %s." %
+                        (acroversion, self.channel, self.connection.get_nickname()))
             conn.notice(nick, "My owner is %s; I have karma on %s items." %
                         (self.owner, len(self.karma.dict.keys())))
 
+    # trout someone
+    def troutq(self, cmd, nick, conn, public):
+            try:
+                target = string.join(cmd.split()[1:])
+                me = self.connection.get_nickname()
+                trout_msg = random.choice(self.trouts)
+#                # The bot is loyal(ish)...
+#                if target.lower() == self.owner.lower():
+#                    target = nick
+                # ...and touchy.
+                if me.lower() == target.lower():
+                    target = nick
+                conn.action(self.channel, trout_msg % target)
+                if public == 0:
+                    if random.random() <= 0.1:
+                        conn.action(self.channel, "notes %s is conducting a whispering campaign" % nick)
+            except IndexError:
+                conn.notice(nick, "Who do you wish me to trout?")
+
+    # stock up on trouts
+    def reloadq(self, cmd, nick, conn, public):
+        if irc_lower(nick) == irc_lower(self.owner):
+            tback = self.trouts
+            try:
+                f = open("trouts", "r")
+                self.trouts = [l.strip() for l in f.readlines() if l.find("%s") != -1]
+                f.close()
+                conn.notice(nick, "I am re-armed!")
+            except IOError:
+                conn.notice(nick, "Trout re-arming failed!")
+                self.trouts = tback
+        else:
+            conn.notice(nick, "This command can only be invoked by my owner.")
+
     # quit irc
     def quit(self, cmd, nick, conn, public):
         if irc_lower(nick) == irc_lower(self.owner):
@@ -192,6 +241,12 @@ class Acrobat(SingleServerIRCBot):
         if cmd == "info":
             self.infoq(cmd, nick, conn, public)
 
+        # weaponry
+        if cmd.split()[0] == "trout":
+            self.troutq(cmd, nick, conn, public)
+        if cmd == "reload":
+            self.reloadq(cmd, nick, conn, public)
+        
         #disconnect
         if cmd == "disconnect": # hop off for 60s
             self.disconnect(msg="Be right back.")