ChannelStats: Add tracking of max users for a channel.

Closes Sf #1032038

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
James Vega 2009-10-27 19:28:34 -04:00
parent e393ea5917
commit 213d304e54
1 changed files with 29 additions and 10 deletions

View File

@ -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))