From 07e6316698a676c3ce0183c3f176d44d8fa44964 Mon Sep 17 00:00:00 2001 From: "charles@rokh.hsd1.wa.comcast.net" Date: Sun, 18 Oct 2009 15:39:37 -0700 Subject: [PATCH] Modified tell plugin to be less spammy. Added .showtells command to view all tells in PM. --- plugins/tell.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/plugins/tell.py b/plugins/tell.py index a8e64ae..38687f6 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -29,17 +29,48 @@ def tellinput(bot, input): if results[0] > 0: command = "select id, user_from, quote, date from tell " \ - "where name = ? and chan = ?" - tells = cursor.execute(command, (input.nick, input.chan)).fetchall() + "where name = ? and chan = ? limit 1" + tell = cursor.execute(command, (input.nick, input.chan)).fetchall()[0] + more = results[0] - 1; + reltime = timesince.timesince(datetime.fromtimestamp(tell[3])) + reply = "%(teller)s said %(reltime)s ago: %(quote)s" % + {"teller": tell[1], "quote": tell[2], "reltime": reltime} + if more: + reply += " (+%(more)d more, to view say .showtells.)" % more + + bot.reply(reply) + command = "delete from tell where id = ?" + cursor.execute(command, (tell[0], )) + + conn.commit() + conn.close() + +@hook.command +def showtells(bot, input): + ".showtells - View all pending tell messages (sent in PM)." + + dbpath = os.path.join(bot.persist_dir, dbname) + conn = dbconnect(dbpath) + + cursor = conn.cursor() + command = "select id, user_from, quote, date from tell " \ + "where name = ? and chan = ?" + tells = cursor.execute(command, (input.nick, input.chan)).fetchall() + + if(len(tells) > 0): for tell in tells: reltime = timesince.timesince(datetime.fromtimestamp(tell[3])) - bot.reply('%(teller)s said %(reltime)s ago: %(quote)s' % + bot.irc.msg(input.nick, '%(teller)s said %(reltime)s ago: %(quote)s' % {'teller': tell[1], 'quote': tell[2], 'reltime': reltime}) + command = "delete from tell where id = ?" cursor.execute(command, (tell[0], )) - + conn.commit() + else: + bot.irc.msg(input.nick, "You have no pending tells.") + conn.close()