From 662920a9f46105e9a0402a90391046bd01ee8673 Mon Sep 17 00:00:00 2001 From: rootcoma Date: Sat, 16 Nov 2013 09:37:24 -0800 Subject: [PATCH] .info only shows active users from channel its called in --- plugin.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugin.py b/plugin.py index 7d7408e..d806ed1 100644 --- a/plugin.py +++ b/plugin.py @@ -301,12 +301,14 @@ class TriviaTime(callbacks.Plugin): """ Get TriviaTime information, how many questions/users in database, time, etc """ - numActiveThisWeek = self.storage.getNumActiveThisWeek() + channel = msg.args[0] + totalUsersEver = self.storage.getNumUser(channel) + numActiveThisWeek = self.storage.getNumActiveThisWeek(channel) infoText = ''' TriviaTime v1.0-beta by Trivialand on Freenode https://github.com/tannn/TriviaTime ''' irc.sendMsg(ircmsgs.privmsg(msg.args[0], infoText)) infoText = ''' Time is %s ''' % (time.asctime(time.localtime(),)) irc.sendMsg(ircmsgs.privmsg(msg.args[0], infoText)) - infoText = '''\x02 %d Users\x02 on scoreboard \x02%d Active This Week\x02''' % (self.storage.getNumUser(), numActiveThisWeek) + infoText = '''\x02 %d Users\x02 on scoreboard \x02%d Active This Week\x02''' % (totalUsersEver, numActiveThisWeek) irc.sendMsg(ircmsgs.privmsg(msg.args[0], infoText)) numKaos = self.storage.getNumKAOS() numQuestionTotal = self.storage.getNumQuestions() @@ -1855,9 +1857,10 @@ class TriviaTime(callbacks.Plugin): c.close() return data - def getNumUser(self): + def getNumUser(self, channel): + channelCanonical = ircutils.toLower(channel) c = self.conn.cursor() - result = c.execute('select count(*) from triviausers') + result = c.execute('select count(distinct(username_canonical)) from triviauserlog where channel_canonical=?', (channelCanonical,)) result = result.fetchone()[0] c.close() return result @@ -1885,7 +1888,8 @@ class TriviaTime(callbacks.Plugin): c.close() return data - def getNumActiveThisWeek(self): + def getNumActiveThisWeek(self, channel): + channelCanonical = ircutils.toLower(channel) d = datetime.date.today() weekday=d.weekday() d -= datetime.timedelta(weekday) @@ -1899,11 +1903,12 @@ class TriviaTime(callbacks.Plugin): and tl.day=%d)''' % (d.year, d.month, d.day) d += datetime.timedelta(1) c = self.conn.cursor() - weekSql = '''select count(distinct(tl.username)) + weekSql = '''select count(distinct(tl.username_canonical)) from triviauserlog tl - where ''' + where channel_canonical=? and (''' weekSql += weekSqlString - result = c.execute(weekSql) + weekSql += ''')''' + result = c.execute(weekSql, (channelCanonical,)) rows = result.fetchone()[0] return rows