diff --git a/commands/list.py b/commands/list.py index e39ee95..996f5d1 100644 --- a/commands/list.py +++ b/commands/list.py @@ -10,7 +10,7 @@ class List: for i in pool.keys(): poolMap.append("Server: %s" % i) for x in pool[i].keys(): - poolMap.append("%s: %s" % (x, pool[i][x])) + poolMap.append(" %s: %s" % (x, pool[i][x])) poolMap.append("\n") info("\n".join(poolMap)) return diff --git a/commands/mod.py b/commands/mod.py index 8ffd9ad..6bb408a 100644 --- a/commands/mod.py +++ b/commands/mod.py @@ -13,7 +13,7 @@ class Mod: return optionMap = ["Viewing options for %s" % spl[1]] for i in pool[spl[1]].keys(): - optionMap.append("%s: %s" % (i, pool[spl[1]][i])) + optionMap.append(" %s: %s" % (i, pool[spl[1]][i])) info("\n".join(optionMap)) return diff --git a/commands/stats.py b/commands/stats.py index 9b1f76f..d1cc14e 100644 --- a/commands/stats.py +++ b/commands/stats.py @@ -1,4 +1,5 @@ from core.main import * +import modules.counters as count class Stats: def __init__(self, register): @@ -17,6 +18,13 @@ class Stats: stats.append("Servers: %s" % len(IRCPool.keys())) stats.append("Channels: %s" % numChannels) stats.append("User records: %s" % numWhoEntries) + counterEvents = count.getEvents() + if counterEvents == None: + stats.append("No counters records") + else: + stats.append("Counters:") + for i in counterEvents.keys(): + stats.append(" %s: %s" % (i, counterEvents[i])) info("\n".join(stats)) return @@ -41,6 +49,13 @@ class Stats: return stats.append("Channels: %s" % numChannels) stats.append("User records: %s" % numWhoEntries) + counterEvents = count.getEvents(spl[1]) + if counterEvents == None: + stats.append("No counters records") + else: + stats.append("Counters:") + for i in counterEvents.keys(): + stats.append(" %s: %s" % (i, counterEvents[i])) info("\n".join(stats)) return else: diff --git a/conf/help.json b/conf/help.json index dba2f80..30ef842 100644 --- a/conf/help.json +++ b/conf/help.json @@ -13,8 +13,8 @@ "disable": "disable ", "list": "list", "stats": "stats []", - "save": "save ", - "load": "load ", + "save": "save ", + "load": "load ", "dist": "dist", "loadmod": "loadmod " -} +} \ No newline at end of file diff --git a/core/bot.py b/core/bot.py index ec0894c..4b33fce 100644 --- a/core/bot.py +++ b/core/bot.py @@ -4,6 +4,7 @@ from twisted.internet.defer import Deferred import modules.keyword as keyword import modules.userinfo as userinfo +import modules.counters as count from core.main import * from utils.logging.log import * @@ -66,18 +67,21 @@ class IRCBot(IRCClient): def privmsg(self, user, channel, msg): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "privmsg") keyword.actKeyword(user, channel, msg, self.nickname, "PRV", self.name) def noticed(self, user, channel, msg): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "notice") keyword.actKeyword(user, channel, msg, self.nickname, "NOT", self.name) def action(self, user, channel, msg): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "action") keyword.actKeyword(user, channel, msg, self.nickname, "ACT", self.name) @@ -126,6 +130,7 @@ class IRCBot(IRCClient): return n = self._who[channel][1] n[nick] = [nick, user, host, server, status, realname] + count.event(self.name, "whoreply") def irc_RPL_ENDOFWHO(self, prefix, params): channel = params[1] @@ -148,38 +153,46 @@ class IRCBot(IRCClient): self.msg(self.authentity, "IDENTIFY %s" % self.nspass) for i in self.autojoin: self.join(i) + count.event(self.name, "signedon") def joined(self, channel): if not channel in self.channels: self.channels.append(channel) self.who(channel).addCallback(self.got_who) + count.event(self.name, "selfjoin") def left(self, channel): if channel in self.channels: self.channels.remove(channel) + count.event(self.name, "selfpart") def kickedFrom(self, channel, kicker, message): if channel in self.channels: self.channels.remove(channel) keyword.sendMaster("KICK %s: (%s/%s) %s" % (self.name, kicker, channel, message)) + count.event(self.name, "selfkick") def userJoined(self, user, channel): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "join") def userLeft(self, user, channel): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "part") def userQuit(self, user, quitMessage): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "quit") keyword.actKeyword(user, None, quitMessage, self.nickname, "QUT", self.name) def userKicked(self, kickee, channel, kicker, message): nick, ident, host = self.parsen(kicker) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "kick") keyword.actKeyword(kicker, channel, message, self.nickname, "KCK", self.name) @@ -187,16 +200,19 @@ class IRCBot(IRCClient): nick, ident, host = self.parsen(oldname) userinfo.setWhoSingle(self.name, nick, ident, host) userinfo.setWhoSingle(self.name, newname, ident, host) + count.event(self.name, "nick") def topicUpdated(self, user, channel, newTopic): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "topic") keyword.actKeyword(user, channel, newTopic, self.nickname, "TOP", self.name) def modeChanged(self, user, channel, toset, modes, args): nick, ident, host = self.parsen(user) userinfo.setWhoSingle(self.name, nick, ident, host) + count.event(self.name, "mode") class IRCBotFactory(ReconnectingClientFactory): def __init__(self, name): diff --git a/core/main.py b/core/main.py index c732c09..b393d7f 100644 --- a/core/main.py +++ b/core/main.py @@ -11,6 +11,7 @@ filemap = { "pool": ["pool.json", "pool"], "help": ["help.json", "command help"], "wholist": ["wholist.json", "WHO lists"], + "counters": ["counters.json", "counters file"], } numbers = "0123456789" @@ -28,7 +29,7 @@ CommandMap = {} def register(command, function): if not command in CommandMap: CommandMap[command] = function - log("Registering command %s" % command) + debug("Registered command: %s" % command) else: error("Duplicate command: %s" % (command)) diff --git a/modules/counters.py b/modules/counters.py new file mode 100644 index 0000000..d832d46 --- /dev/null +++ b/modules/counters.py @@ -0,0 +1,29 @@ +from core.main import * + +def event(name, eventType): + if not "local" in counters.keys(): + counters["local"] = {} + if not "global" in counters.keys(): + counters["global"] = {} + if not name in counters["local"].keys(): + counters["local"][name] = {} + if eventType not in counters["local"][name].keys(): + counters["local"][name][eventType] = 0 + + if eventType not in counters["global"]: + counters["global"][eventType] = 0 + + counters["local"][name][eventType] += 1 + counters["global"][eventType] += 1 + +def getEvents(name=None): + if name == None: + if "global" in counters.keys(): + return counters["global"] + else: + return None + else: + if name in counters["local"].keys(): + return counters["local"][name] + else: + return None diff --git a/threshold b/threshold index 9524f5a..0439b1a 100755 --- a/threshold +++ b/threshold @@ -20,7 +20,8 @@ from core.main import ( saveConf, loadConf, initMain, -) + ) + initMain() from core.main import ( @@ -29,7 +30,8 @@ from core.main import ( pool, help, wholist, -) + counters, + ) from utils.logging.log import * import modules.userinfo as userinfo