All pastes #1767444 Raw Edit

Anonymous

public python v1 · immutable
#1767444 ·published 2010-01-27 02:02 UTC
rendered paste body
import osimport randomimport syssys.path.insert(0, os.getenv("HOME") + '/.phenny')try:    import default as settingsexcept ImportError:    sys.stderr.write("Unable to load settings")LAST_BYTES = {}DB = {}def f_listen(phenny, input):    """ Listen on a channel recording the last thing anyone says """    def listen(phenny, input):        # ignore phenny commads,  This should really be in the rule        if input.bytes[0] == '.':            return        LAST_BYTES[input.nick] = input.bytes    try: listen(phenny, input)    except Exception, e: print ef_listen.rule = r'(.*)'f_listen.priority = 'low'def grab(phenny, input):    """ Save the last thing someone said """    grabbed_by = input.nick    nick = input.group(2)    if not nick:        return    # dont let the bot quote itself    if nick == settings.nick:        phenny.reply("Nice try, flesh bag")        return    # dont let people quote themselves    if nick == grabbed_by:        phenny.reply("Don't be lame and quote yourself!")        return    # this might be the first time `nick` has been grabbed.    if nick not in DB.keys():        DB[nick] = []    try:        last_said = LAST_BYTES[nick]    except KeyError:        phenny.reply("I have not seen %s say anything yet" % nick)        return    DB[nick].append(last_said)    phenny.reply("Tada!")    grab.commands = ['grab']grab.example = '.grab nick'grab.priority = 'low'def quote(phenny, input):    """ Reply (hopefully out of context) with the last thing someone said """    nick = input.group(2)    if not nick:        return    # This person must be boring because no one grabs their comments    if nick not in DB.keys():        return    try:        last_said = DB[nick][-1]    except IndexError:        phenny.reply("%s is not quotable" % nick)        return    phenny.reply("<%s> %s" % (nick, last_said))quote.commands = ['quote', 'q']quote.example = '.quote nick'quote.priority = 'low'def random_quote(phenny, input):    """ Return something random someone said once """    nick = input.group(2)    if not nick:        nick = random.choice(DB.keys()) # random key    if nick not in DB.keys():        return    # this is blowing up with an IndexError, but the stack trace is pointing to    # random.py in the python stdlib, not my code.    try:        last_said = random.choice(DB[nick])    except IndexError:        sys.stderr.write("...")        return            phenny.reply("<%s> %s" % (nick, last_said))random_quote.commands = ['rq']random_quote.example = '.rq nick'random_quote.priority = 'low'__author__ = ["mdg <miles@milesgroman.com>"]