Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-tell #21

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
*~
1 change: 1 addition & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, config):
self.config = config
self.doc = {}
self.stats = {}
self.internals = {}
self.setup()

def setup(self):
Expand Down
4 changes: 4 additions & 0 deletions modules/codepoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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- .?+*{}[]\\/^$'):
Expand Down
98 changes: 98 additions & 0 deletions modules/karma.py
Original file line number Diff line number Diff line change
@@ -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: <nick>(++|--)
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()
46 changes: 26 additions & 20 deletions modules/tell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'): # @@
# @@ <deltab> 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+) (.*)')
Expand Down
2 changes: 1 addition & 1 deletion phenny
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2.6
"""
phenny - An IRC Bot
Copyright 2008, Sean B. Palmer, inamidst.com
Expand Down