2009-07-05 03:27:05 +00:00
|
|
|
" tell.py: written by sklnd in July 2009"
|
2010-02-01 07:29:50 +00:00
|
|
|
" 2010.01.25 - modified by Scaevolus"
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
import time
|
2009-07-08 17:04:30 +00:00
|
|
|
|
|
|
|
from util import hook, timesince
|
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
def get_tells(db, user_to, chan):
|
|
|
|
return db.execute("select user_from, message, time from tell where"
|
2010-03-01 02:32:41 +00:00
|
|
|
" user_to=lower(?) and chan=? order by time",
|
2010-02-01 07:29:50 +00:00
|
|
|
(user_to.lower(), chan)).fetchall()
|
2009-07-05 03:27:05 +00:00
|
|
|
|
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
@hook.tee
|
2010-02-01 07:29:50 +00:00
|
|
|
def tellinput(bot, input):
|
2010-02-02 04:42:34 +00:00
|
|
|
if input.command != 'PRIVMSG':
|
|
|
|
return
|
|
|
|
|
|
|
|
if 'showtells' in input.msg.lower():
|
2010-02-01 07:29:50 +00:00
|
|
|
return
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
db = bot.get_db_connection(input.server)
|
|
|
|
db = db_init(db)
|
2009-07-08 17:28:15 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
tells = get_tells(db, input.nick, input.chan)
|
2009-07-05 15:03:24 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
if tells:
|
|
|
|
user_from, message, time = tells[0]
|
|
|
|
reltime = timesince.timesince(time)
|
2009-07-05 15:03:24 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
reply = "%s said %s ago: %s" % (user_from, reltime, message)
|
|
|
|
if len(tells) > 1:
|
|
|
|
reply += " (+%d more, .showtells to view)" % (len(tells) - 1)
|
2009-07-08 17:28:15 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
db.execute("delete from tell where user_to=lower(?) and message=?",
|
2010-02-01 07:29:50 +00:00
|
|
|
(input.nick, message))
|
2010-02-02 04:42:34 +00:00
|
|
|
db.commit()
|
|
|
|
input.reply(reply)
|
2009-10-18 22:39:37 +00:00
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2009-10-18 22:39:37 +00:00
|
|
|
@hook.command
|
2010-02-02 04:42:34 +00:00
|
|
|
def showtells(inp, nick='', chan='', pm=None, db=None):
|
2009-11-19 03:20:59 +00:00
|
|
|
".showtells -- view all pending tell messages (sent in PM)."
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
db_init(db)
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
tells = get_tells(db, nick, chan)
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
if not tells:
|
2010-02-02 04:42:34 +00:00
|
|
|
pm("You have no pending tells.")
|
2010-02-01 07:29:50 +00:00
|
|
|
return
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
for tell in tells:
|
|
|
|
user_from, message, time = tell
|
|
|
|
reltime = timesince.timesince(time)
|
2010-02-02 04:42:34 +00:00
|
|
|
pm("%s said %s ago: %s" % (user_from, reltime, message))
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
db.execute("delete from tell where user_to=lower(?) and chan=?",
|
|
|
|
(nick, chan))
|
|
|
|
db.commit()
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2009-07-05 03:27:05 +00:00
|
|
|
@hook.command
|
2010-02-02 04:42:34 +00:00
|
|
|
def tell(inp, nick='', chan='', db=None):
|
2009-11-19 03:20:59 +00:00
|
|
|
".tell <nick> <message> -- relay <message> to <nick> when <nick> is around"
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
query = inp.split(' ', 1)
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
if not inp or len(query) != 2:
|
2010-02-01 07:29:50 +00:00
|
|
|
return tell.__doc__
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
user_to = query[0].lower()
|
|
|
|
message = query[1].strip()
|
2010-02-02 04:42:34 +00:00
|
|
|
user_from = nick
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
if user_to == user_from.lower():
|
2009-07-05 03:27:05 +00:00
|
|
|
return "No."
|
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
db_init(db)
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
if db.execute("select count() from tell where user_to=?",
|
2010-02-01 07:29:50 +00:00
|
|
|
(user_to,)).fetchone()[0] >= 5:
|
|
|
|
return "That person has too many things queued."
|
2009-07-08 17:28:15 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
try:
|
2010-02-02 04:42:34 +00:00
|
|
|
db.execute("insert into tell(user_to, user_from, message, chan,"
|
2010-02-01 07:29:50 +00:00
|
|
|
"time) values(?,?,?,?,?)", (user_to, user_from, message,
|
2010-02-02 04:42:34 +00:00
|
|
|
chan, time.time()))
|
|
|
|
db.commit()
|
|
|
|
except db.IntegrityError:
|
2010-02-01 07:29:50 +00:00
|
|
|
return "Message has already been queued."
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
return "I'll pass that along."
|
2009-07-05 03:27:05 +00:00
|
|
|
|
2009-07-08 17:28:15 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
def db_init(db):
|
|
|
|
"check to see that our db has the tell table and return a dbection."
|
|
|
|
db.execute("create table if not exists tell"
|
2010-02-01 07:29:50 +00:00
|
|
|
"(user_to, user_from, message, chan, time,"
|
|
|
|
"primary key(user_to, message))")
|
2010-02-02 04:42:34 +00:00
|
|
|
db.commit()
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-02 04:42:34 +00:00
|
|
|
return db
|