Implement counting of various IRC events

This commit is contained in:
Mark Veidemanis 2018-02-24 12:42:27 +00:00
parent 378c4d9bba
commit 8dec0b6828
8 changed files with 71 additions and 8 deletions

View File

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

View File

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

View File

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

View File

@ -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>"
}
}

View File

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

View File

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

29
modules/counters.py Normal file
View File

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

View File

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