From 3da63100651c79ebbc2df661165251a41e6e47f6 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 1 Apr 2003 08:38:53 +0000 Subject: [PATCH] Added some fixes; seen command works, and stats somewhat works. --- plugins/ChannelStats.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/plugins/ChannelStats.py b/plugins/ChannelStats.py index e59d77822..3d6ee9d45 100644 --- a/plugins/ChannelStats.py +++ b/plugins/ChannelStats.py @@ -45,6 +45,9 @@ import time import sqlite +import debug +import ircdb +import ircmsgs import privmsgs import ircutils import callbacks @@ -81,16 +84,18 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler): kicks INTEGER, kicked INTEGER, modes INTEGER, - topics INTEGER, + topics INTEGER )""") cursor.execute("""CREATE INDEX stats_username ON stats (username)""") db.commit() return db def doPrivmsg(self, irc, msg): + callbacks.Privmsg.doPrivmsg(self, irc, msg) if ircutils.isChannel(msg.args[0]): (channel, s) = msg.args db = self.getDb(channel) + cursor = db.cursor() try: name = ircdb.users.getUserName(msg.prefix) except KeyError: @@ -100,7 +105,7 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler): cursor.execute("""INSERT INTO stats VALUES ( NULL, %s, %s, %s, %s, %s, %s, %s, 1, %s, - 0, 0, 0, 0, 0 )""", + 0, 0, 0, 0, 0, 0 )""", name, int(time.time()), msg.args[1], len(smileyre.findall(s)), len(frownre.findall(s)), len(s), len(s.split()), @@ -117,12 +122,12 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler): WHERE username=%s""", int(time.time()), s, - values.chars + len(s), - values.words + len(s.split()), - values.msgs + 1, - values.actions + ircmsgs.isAction(msg), - values.smileys + len(smileyre.findall(s)), - values.frowns + len(frownre.findall(s)), + int(values.chars) + len(s), + int(values.words) + len(s.split()), + int(values.msgs) + 1, + int(values.actions) + ircmsgs.isAction(msg), + int(values.smileys) + len(smileyre.findall(s)), + int(values.frowns) + len(frownre.findall(s)), name) db.commit() @@ -220,7 +225,7 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler): "[] (if not sent on the channel itself) " channel = privmsgs.getChannel(msg, args) name = privmsgs.getArgs(args) - if not irc.users.hasUser(name): + if not ircdb.users.hasUser(name): hostmask = irc.state.nickToHostmask(name) try: name = irc.users.getUserName(hostmask) @@ -229,12 +234,13 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler): return db = self.getDb(channel) cursor = db.cursor() - cursor.execute("""SELECT (last_seen, last_msg) FROM stats + cursor.execute("""SELECT last_seen, last_msg FROM stats WHERE username=%s""", name) if cursor.rowcount == 0: irc.reply(msg, 'I have no stats for that user.') else: (seen, m) = cursor.fetchone() + seen = int(seen) ago = int(time.time()) - seen days = ago / 86400 ago %= 86400 @@ -242,19 +248,19 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler): ago %= 3600 minutes = ago / 60 seconds = ago % 60 - s = '%s day%s %s hour%s %s minute%s %s second%s ago' % \ + s = '%s day%s %s hour%s %s minute%s %s second%sago' % \ (days, days == 1 and ',' or 's,', hours, hours == 1 and ',' or 's,', minutes, minutes == 1 and ',' or 's,', - seconds, seconds == 1 and ',' or 's,') - irc.reply(msg, '%s was last seen here at %s saying %s' % \ + seconds, seconds == 1 and ' ' or 's ') + irc.reply(msg, '%s was last seen here at %s saying %r' % \ (name, s, m)) def stats(self, irc, msg, args): "[] (if not sent in the channel itself) " channel = privmsgs.getChannel(msg, args) name = privmsgs.getArgs(args) - if not irc.users.hasUser(name): + if not ircdb.users.hasUser(name): hostmask = irc.state.nickToHostmask(name) try: name = irc.users.getUserName(hostmask) @@ -270,14 +276,14 @@ class ChannelStats(callbacks.Privmsg, ChannelDBHandler): irc.reply(msg, 'I have no stats for that user.') return values = cursor.fetchone() - s = '%s has %s messages, with a total of %s chars, %s words, ' \ + s = '%s has sent %s messages; a total of %s characters, %s words, ' \ '%s smileys, and %s frowns; %s of those messages were ACTIONs. ' \ '%s has joined %s times, parted %s times, kicked someone %s times'\ ' been kicked %s times, changed the topic %s times, ' \ 'and changed the mode %s times.' % \ - (values.msgs, values.chars, values.words, + (name, values.msgs, values.chars, values.words, values.smileys, values.frowns, values.actions, - values.joins, values.parts, values.kicks, + name, values.joins, values.parts, values.kicks, values.kicked, values.topics, values.modes) irc.reply(msg, s)