From 213d304e548ea30cb85a901ccb21e21bd37d7e57 Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 27 Oct 2009 19:28:34 -0400 Subject: [PATCH] ChannelStats: Add tracking of max users for a channel. Closes Sf #1032038 Signed-off-by: James Vega --- plugins/ChannelStats/plugin.py | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/plugins/ChannelStats/plugin.py b/plugins/ChannelStats/plugin.py index baf768007..269f30b09 100644 --- a/plugins/ChannelStats/plugin.py +++ b/plugins/ChannelStats/plugin.py @@ -46,9 +46,10 @@ import supybot.callbacks as callbacks class ChannelStat(irclib.IrcCommandDispatcher): _values = ['actions', 'chars', 'frowns', 'joins', 'kicks','modes', - 'msgs', 'parts', 'quits', 'smileys', 'topics', 'words'] + 'msgs', 'parts', 'quits', 'smileys', 'topics', 'words', 'users'] def __init__(self, actions=0, chars=0, frowns=0, joins=0, kicks=0, modes=0, - msgs=0, parts=0, quits=0, smileys=0, topics=0, words=0): + msgs=0, parts=0, quits=0, smileys=0, topics=0, words=0, + users=0): self.actions = actions self.chars = chars self.frowns = frowns @@ -61,6 +62,7 @@ class ChannelStat(irclib.IrcCommandDispatcher): self.smileys = smileys self.topics = topics self.words = words + self.users = users def values(self): return [getattr(self, s) for s in self._values] @@ -101,6 +103,7 @@ class ChannelStat(irclib.IrcCommandDispatcher): if len(msg.args) == 2: self.doPayload(*msg.args) self.joins += 1 + # Handle max-users in the plugin since we need an irc object def doMode(self, msg): self.modes += 1 @@ -193,6 +196,19 @@ class ChannelStats(callbacks.Plugin): self.outFiltering = False return msg + def _setUsers(self, irc, channel): + if (channel, 'channelStats') not in self.db: + self.db[channel, 'channelStats'] = ChannelStat() + oldUsers = self.db[channel, 'channelStats'].users + newUsers = len(irc.state.channels[channel].users) + self.db[channel, 'channelStats'].users = max(oldUsers, newUsers) + + def doJoin(self, irc, msg): + self._setUsers(irc, msg.args[0]) + + def do366(self, irc, msg): + self._setUsers(irc, msg.args[1]) + def doQuit(self, irc, msg): try: id = ircdb.users.getUserId(msg.prefix) @@ -215,10 +231,8 @@ class ChannelStats(callbacks.Plugin): id = ircdb.users.getUserId(hostmask) except KeyError: return - if channel not in self.db.channels: - self.db.channels[channel] = {} - if id not in self.db.channels[channel]: - self.db.channels[channel][id] = UserStat() + if (channel, id) not in self.db: + self.db[channel, id] = UserStat() self.db.channels[channel][id].kicked += 1 def stats(self, irc, msg, args, channel, name): @@ -326,11 +340,13 @@ class ChannelStats(callbacks.Plugin): """ try: stats = self.db.getChannelStats(channel) - s = format('On %s there have been %i messages, containing %i ' + curUsers = len(irc.state.channels[channel].users) + s = format('On %s there %h been %i messages, containing %i ' 'characters, %n, %n, and %n; ' '%i of those messages %s. There have been ' - '%n, %n, %n, %n, %n, and %n.', - channel, stats.msgs, stats.chars, + '%n, %n, %n, %n, %n, and %n. There %b currently %n ' + 'and the channel has peaked at %n.', + channel, stats.msgs, stats.msgs, stats.chars, (stats.words, 'word'), (stats.smileys, 'smiley'), (stats.frowns, 'frown'), @@ -341,7 +357,10 @@ class ChannelStats(callbacks.Plugin): (stats.quits, 'quit'), (stats.kicks, 'kick'), (stats.modes, 'mode', 'change'), - (stats.topics, 'topic', 'change')) + (stats.topics, 'topic', 'change'), + curUsers, + (curUsers, 'user'), + (stats.users, 'user')) irc.reply(s) except KeyError: irc.error(format('I\'ve never been on %s.', channel))