diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f3d74a9a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*~ diff --git a/bot.py b/bot.py index 453dbc4d7..b71270ccd 100755 --- a/bot.py +++ b/bot.py @@ -27,6 +27,7 @@ def __init__(self, config): self.config = config self.doc = {} self.stats = {} + self.internals = {} self.setup() def setup(self): diff --git a/modules/codepoints.py b/modules/codepoints.py index eb9c8bfa8..cfca1edf6 100755 --- a/modules/codepoints.py +++ b/modules/codepoints.py @@ -74,6 +74,10 @@ def u(phenny, input): if len(arg) > 1: return phenny.reply('%s SPACEs (U+0020)' % len(arg)) return phenny.reply('1 SPACE (U+0020)') + # Request from timotimo: + if arg.strip() == 'm': + return phenny.say("U+006D LATIN SMALL LIGATURE RN (m)") + # @@ space if set(arg.upper()) - set( 'ABCDEFGHIJKLMNOPQRSTUVWYXYZ0123456789- .?+*{}[]\\/^$'): diff --git a/modules/karma.py b/modules/karma.py new file mode 100644 index 000000000..50e0e06a5 --- /dev/null +++ b/modules/karma.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +""" +karma.py - Phenny karma module +By Ori Rawlings +""" + +import sqlite3 +import os +from itertools import imap +from functools import partial +from operator import add + + +ops = { '++':partial(add, 1), '+1':partial(add, 1), '--':partial(add, -1), '-1':partial(add, -1) } + +class KarmaDAO: + def __init__(self, path): + self.db_path = path + + def karmas(self, conn, limit=None): + comm='select name,score from karma order by abs(score) desc ' + if limit and int(limit)>0: + comm += 'limit %d'%int(limit) + return conn.execute(comm) + + def update_karma(self, conn, user, f, default=0): + user = str(user) + score = conn.execute('select score from karma where name = ?', (user,)).fetchone() + if score: + score = f(score[0] or default) + conn.execute('update karma set score=? where name=?', (score,user)) + else: + score = f(default) + conn.execute('insert into karma (name,score) values (?,?)', (user,score)) + conn.commit() + + def get_karma(self, conn, user): + user=str(user) + score = conn.execute('select score from karma where name = ?', (user,)).fetchone() + score=(score and score[0]) or 0 + return score + +def karma_point(phenny, input): + """ + This rule will detect and apply karma operations. + Usage: (++|--) + Example: + + orirawlings++ + Increases nick, orirawlings, karma score by 1 point + + foobar-- + Decreases nick, foobar, karma score by 1 point + """ + user = input.group(1) + op = input.group(2) + if input.nick == user: + if '+' in op: + phenny.reply("Silly, you can't award yourself karma...") + return + elif '-' in op: + phenny.reply("Wow, you must have really been bad to take karma from yourself...") + f = ops.get(op, lambda x: x) + conn = sqlite3.connect(phenny.karma_dao.db_path) + phenny.karma_dao.update_karma(conn, user, f, 0) +karma_point.rule = '^(\w+)(?::\s*)?(\+{2}|-{2})\s*$' + +def karma(phenny, input): + """ + .karma - prints all stored karma scores for various nicks to the channel + """ + who=input.group(1) + conn = sqlite3.connect(phenny.karma_dao.db_path) + if not who or (who.isdigit() and int(who)>5): + phenny.say("Sending you the list in private messages, "+input.nick) + for entry in phenny.karma_dao.karmas(conn,who): + # List of all is IMed to the questioner, so as not + # to spam the channel. + phenny.msg(input.nick,'\t'.join(imap(str,entry))) + elif who.isdigit(): + for entry in phenny.karma_dao.karmas(conn,who): + phenny.say("\t".join(imap(str,entry))) + else: + score = phenny.karma_dao.get_karma(conn, input.group(1)) + phenny.say("Karma for %s: %d"%(input.group(1), score)) + conn.close() + +karma.rule = '^\.karma\s*(\w*)' +karma.priority = 'medium' + +def path(self): + return os.path.join(os.path.expanduser('~/.phenny'),'karma','karma.db') + +def setup(phenny): + phenny.karma_dao = KarmaDAO(path(phenny)) + +if __name__ == '__main__': + print __doc__.strip() diff --git a/modules/tell.py b/modules/tell.py index d3ee609ed..d90ce4b16 100755 --- a/modules/tell.py +++ b/modules/tell.py @@ -72,32 +72,38 @@ def f_remind(phenny, input): if not os.path.exists(phenny.tell_filename): return - if len(tellee) > 20: - return phenny.reply('That nickname is too long.') - timenow = time.strftime('%d %b %H:%MZ', time.gmtime()) - if not tellee in (teller.lower(), phenny.nick, 'me'): # @@ - # @@ and year, if necessary - warn = False - if not phenny.reminders.has_key(tellee): - phenny.reminders[tellee] = [(teller, verb, timenow, msg)] - else: - # if len(phenny.reminders[tellee]) >= maximum: - # warn = True - phenny.reminders[tellee].append((teller, verb, timenow, msg)) - # @@ Stephanie's augmentation - response = "I'll pass that on when %s is around." % tellee_original - # if warn: response += (" I'll have to use a pastebin, though, so " + - # "your message may get lost.") - + whogets=[] + for tellee in tellee.split(','): + if len(tellee) > 20: + phenny.say('Nickname %s is too long.'%tellee) + continue + if not tellee in (teller.lower(), phenny.nick, 'me'): # @@ + warn = False + if not tellee in whogets: + whogets.append(tellee) + if not phenny.reminders.has_key(tellee): + phenny.reminders[tellee] = [(teller, verb, timenow, msg)] + else: + # if len(phenny.reminders[tellee]) >= maximum: + # warn = True + phenny.reminders[tellee].append((teller, verb, timenow, msg)) + if not whogets: # Only get cute if there are no legits rand = random.random() if rand > 0.9999: response = "yeah, yeah" elif rand > 0.999: response = "yeah, sure, whatever" - - phenny.reply(response) elif teller.lower() == tellee: phenny.say('You can %s yourself that.' % verb) - else: phenny.say("Hey, I'm not as stupid as Monty you know!") + elif teller.lower() == phenny.nick.lower(): + phenny.say("Hey, I'm not as stupid as Monty you know!") + else: + response="I'll pass that on when %s is around." + if len(whogets)>1: + listing=", ".join(whogets[:-1])+" or "+whogets[-1] + response=response%listing + else: + response=response%whogets[0] + phenny.reply(response) dumpReminders(phenny.tell_filename, phenny.reminders) # @@ tell f_remind.rule = ('$nick', ['tell', 'ask'], r'(\S+) (.*)') diff --git a/phenny b/phenny index 1bc110b32..f24bb5d69 100755 --- a/phenny +++ b/phenny @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.6 """ phenny - An IRC Bot Copyright 2008, Sean B. Palmer, inamidst.com