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-03-16 20:06:20 +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"
|
2014-01-14 21:12:37 +00:00
|
|
|
"(user_to, user_from, message, chan, time,"
|
|
|
|
"primary key(user_to, message))")
|
2010-03-16 20:06:20 +00:00
|
|
|
db.commit()
|
|
|
|
|
|
|
|
return db
|
|
|
|
|
|
|
|
|
|
|
|
def get_tells(db, user_to):
|
|
|
|
return db.execute("select user_from, message, time, chan from tell where"
|
2014-01-14 21:12:37 +00:00
|
|
|
" user_to=lower(?) order by time",
|
|
|
|
(user_to.lower(),)).fetchall()
|
2009-07-05 03:27:05 +00:00
|
|
|
|
|
|
|
|
2010-03-13 14:24:19 +00:00
|
|
|
@hook.singlethread
|
2010-03-11 23:34:54 +00:00
|
|
|
@hook.event('PRIVMSG')
|
2010-03-13 14:24:19 +00:00
|
|
|
def tellinput(paraml, input=None, db=None, bot=None):
|
2010-02-02 04:42:34 +00:00
|
|
|
if 'showtells' in input.msg.lower():
|
2010-02-01 07:29:50 +00:00
|
|
|
return
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-03-13 14:24:19 +00:00
|
|
|
db_init(db)
|
2009-07-08 17:28:15 +00:00
|
|
|
|
2010-03-16 20:06:20 +00:00
|
|
|
tells = get_tells(db, input.nick)
|
2009-07-05 15:03:24 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
if tells:
|
2010-03-16 20:06:20 +00:00
|
|
|
user_from, message, time, chan = tells[0]
|
2010-02-01 07:29:50 +00:00
|
|
|
reltime = timesince.timesince(time)
|
2009-07-05 15:03:24 +00:00
|
|
|
|
2010-04-23 03:50:56 +00:00
|
|
|
reply = "%s said %s ago in %s: %s" % (user_from, reltime, chan,
|
2010-03-27 08:42:27 +00:00
|
|
|
message)
|
2010-02-01 07:29:50 +00:00
|
|
|
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=?",
|
2014-01-14 21:12:37 +00:00
|
|
|
(input.nick, message))
|
2010-02-02 04:42:34 +00:00
|
|
|
db.commit()
|
2010-04-13 21:39:40 +00:00
|
|
|
input.notice(reply)
|
2009-10-18 22:39:37 +00:00
|
|
|
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-05-07 23:16:44 +00:00
|
|
|
@hook.command(autohelp=False)
|
2010-04-13 21:39:40 +00:00
|
|
|
def showtells(inp, nick='', chan='', notice=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-03-16 21:35:52 +00:00
|
|
|
tells = get_tells(db, nick)
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-02-01 07:29:50 +00:00
|
|
|
if not tells:
|
2010-04-13 21:39:40 +00:00
|
|
|
notice("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:
|
2010-03-16 20:06:20 +00:00
|
|
|
user_from, message, time, chan = tell
|
2010-04-23 03:50:56 +00:00
|
|
|
past = timesince.timesince(time)
|
|
|
|
notice("%s said %s ago in %s: %s" % (user_from, past, chan, message))
|
2010-03-01 02:32:41 +00:00
|
|
|
|
2010-03-16 20:06:20 +00:00
|
|
|
db.execute("delete from tell where user_to=lower(?)",
|
2014-01-14 21:12:37 +00:00
|
|
|
(nick,))
|
2010-02-02 04:42:34 +00:00
|
|
|
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-05-07 23:16:44 +00:00
|
|
|
if 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-03-16 20:06:20 +00:00
|
|
|
if chan.lower() == user_from.lower():
|
|
|
|
chan = 'a pm'
|
|
|
|
|
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=?",
|
2014-01-14 21:12:37 +00:00
|
|
|
(user_to,)).fetchone()[0] >= 5:
|
2010-02-01 07:29:50 +00:00
|
|
|
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,"
|
2014-01-14 21:12:37 +00:00
|
|
|
"time) values(?,?,?,?,?)", (user_to, user_from, message,
|
|
|
|
chan, time.time()))
|
2010-02-02 04:42:34 +00:00
|
|
|
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."
|