#!/usr/bin/python """ Teddybot Author: Sean B. Palmer, inamidst.com License: GPL 2; share and enjoy! """ nickname = 'teddybot`' import os, time, math, random from random import choice as rand import ircbot if os.path.exists('/home/sbp/info/enodeck.txt'): deck = open('/home/sbp/info/enodeck.txt').read().splitlines() else: deck = ['Hmm'] phatic = ( "Indeed", "Uh-huh", "Go on", "I see", "Right", "Okay", "Oh" ) rhetoric = ( "Are you sure?", "Really?", "Oh?", "Indeed?", "Yeah?" ) unsure = ( "Hmm", "Hm", "Er" ) def bot(host, port, channels, nick=nickname): p = ircbot.Bot(nick=nick, channels=channels) p.name = "Teddy Bot" p.info = {} p.prev = None def f_speak(m, origin, args, text, p=p): if p.info.has_key(origin.nick): timenow = time.time() p.info[origin.nick].append(timenow) p.info[origin.nick] = filter( lambda t: t > (timenow - 3600), p.info[origin.nick] ) n = len(p.info[origin.nick]) prob = 1.0 - math.sqrt(1.0 / n) else: p.info[origin.nick] = [time.time()] prob = 0.1 if random.random() < prob: if text.endswith('?'): reply = rand(unsure) + rand(('...', '')) elif random.random() > 0.95: reply = rand(("Think about this:", "Meditate on this:")) reply += ' ' + rand(deck) elif random.random() > 0.85: reply = rand(rhetoric) else: reply = rand(phatic) if text.endswith('!') and (random.random() > 0.25): reply += '!' if not reply == p.prev: p.msg(origin.sender, reply) p.prev = reply p.bind(f_speak, 'PRIVMSG', r"(?:teddybot|tb(?:\W|\Z))") p.run(host, port) def main(): channels = ['#teddybot'] bot('irc.freenode.net', 6667, channels) if __name__=='__main__': main()