Implement counting of various IRC events
This commit is contained in:
parent
378c4d9bba
commit
8dec0b6828
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
"disable": "disable <name>",
|
||||
"list": "list",
|
||||
"stats": "stats [<name>]",
|
||||
"save": "save <config|keyconf|pool|help|wholist|all>",
|
||||
"load": "load <config|keyconf|pool|help|wholist|all>",
|
||||
"save": "save <config|keyconf|pool|help|wholist|counters|all>",
|
||||
"load": "load <config|keyconf|pool|help|wholist|counters|all>",
|
||||
"dist": "dist",
|
||||
"loadmod": "loadmod <module>"
|
||||
}
|
||||
}
|
16
core/bot.py
16
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):
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue