chiark / gitweb /
improved trout functionality
authormatthew <matthew>
Sun, 3 Feb 2002 22:39:59 +0000 (22:39 +0000)
committermatthew <matthew>
Sun, 3 Feb 2002 22:39:59 +0000 (22:39 +0000)
acrobat-chiark-0.2.py

index ccdf676..851e5f4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/local/bin/python
+#!/usr/bin/env python2
 #
 # Joel Rosdahl <joel@rosdahl.net>
 # Andrew Walkingshaw <andrew@lexical.org.uk>
               back with the url.
 """
 
-import string, urllib, sys, cPickle, os
+import string, urllib, sys, cPickle, os, random
 from ircbot import SingleServerIRCBot
 from irclib import nm_to_n, irc_lower
 
+
+
 class Karma:
     def __init__(self):
         self.dict = {}
@@ -51,6 +53,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
             
@@ -125,17 +133,51 @@ class Acrobat(SingleServerIRCBot):
     def infoq(self, cmd, nick, conn, public):
         if public == 1:
             conn.privmsg(self.channel,
-                         "I am Acrobat 0.2chiark, on %s, as nick %s." %
+                         "I am Acrobat 0.2.1chiark, on %s, as nick %s." %
                          (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." %
+            conn.notice(nick, "I am Acrobat 0.2.1chiark, on %s, as nick %s." %
                         (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 +234,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.")