From: matthew Date: Sun, 3 Feb 2002 22:39:59 +0000 (+0000) Subject: improved trout functionality X-Git-Tag: upstream_0_3~20 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=commitdiff_plain;h=ee34a18a77adab30604f18c67f07c76e2f823516 improved trout functionality --- diff --git a/acrobat-chiark-0.2.py b/acrobat-chiark-0.2.py index ccdf676..851e5f4 100755 --- a/acrobat-chiark-0.2.py +++ b/acrobat-chiark-0.2.py @@ -1,4 +1,4 @@ -#!/usr/local/bin/python +#!/usr/bin/env python2 # # Joel Rosdahl # Andrew Walkingshaw @@ -30,10 +30,12 @@ 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.")