Implement counting of various IRC events
This commit is contained in:
parent
378c4d9bba
commit
8dec0b6828
|
@ -1,4 +1,5 @@
|
||||||
from core.main import *
|
from core.main import *
|
||||||
|
import modules.counters as count
|
||||||
|
|
||||||
class Stats:
|
class Stats:
|
||||||
def __init__(self, register):
|
def __init__(self, register):
|
||||||
|
@ -17,6 +18,13 @@ class Stats:
|
||||||
stats.append("Servers: %s" % len(IRCPool.keys()))
|
stats.append("Servers: %s" % len(IRCPool.keys()))
|
||||||
stats.append("Channels: %s" % numChannels)
|
stats.append("Channels: %s" % numChannels)
|
||||||
stats.append("User records: %s" % numWhoEntries)
|
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))
|
info("\n".join(stats))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -41,6 +49,13 @@ class Stats:
|
||||||
return
|
return
|
||||||
stats.append("Channels: %s" % numChannels)
|
stats.append("Channels: %s" % numChannels)
|
||||||
stats.append("User records: %s" % numWhoEntries)
|
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))
|
info("\n".join(stats))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
"disable": "disable <name>",
|
"disable": "disable <name>",
|
||||||
"list": "list",
|
"list": "list",
|
||||||
"stats": "stats [<name>]",
|
"stats": "stats [<name>]",
|
||||||
"save": "save <config|keyconf|pool|help|wholist|all>",
|
"save": "save <config|keyconf|pool|help|wholist|counters|all>",
|
||||||
"load": "load <config|keyconf|pool|help|wholist|all>",
|
"load": "load <config|keyconf|pool|help|wholist|counters|all>",
|
||||||
"dist": "dist",
|
"dist": "dist",
|
||||||
"loadmod": "loadmod <module>"
|
"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.keyword as keyword
|
||||||
import modules.userinfo as userinfo
|
import modules.userinfo as userinfo
|
||||||
|
import modules.counters as count
|
||||||
|
|
||||||
from core.main import *
|
from core.main import *
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
|
@ -66,18 +67,21 @@ class IRCBot(IRCClient):
|
||||||
def privmsg(self, user, channel, msg):
|
def privmsg(self, user, channel, msg):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "privmsg")
|
||||||
|
|
||||||
keyword.actKeyword(user, channel, msg, self.nickname, "PRV", self.name)
|
keyword.actKeyword(user, channel, msg, self.nickname, "PRV", self.name)
|
||||||
|
|
||||||
def noticed(self, user, channel, msg):
|
def noticed(self, user, channel, msg):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "notice")
|
||||||
|
|
||||||
keyword.actKeyword(user, channel, msg, self.nickname, "NOT", self.name)
|
keyword.actKeyword(user, channel, msg, self.nickname, "NOT", self.name)
|
||||||
|
|
||||||
def action(self, user, channel, msg):
|
def action(self, user, channel, msg):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "action")
|
||||||
|
|
||||||
keyword.actKeyword(user, channel, msg, self.nickname, "ACT", self.name)
|
keyword.actKeyword(user, channel, msg, self.nickname, "ACT", self.name)
|
||||||
|
|
||||||
|
@ -126,6 +130,7 @@ class IRCBot(IRCClient):
|
||||||
return
|
return
|
||||||
n = self._who[channel][1]
|
n = self._who[channel][1]
|
||||||
n[nick] = [nick, user, host, server, status, realname]
|
n[nick] = [nick, user, host, server, status, realname]
|
||||||
|
count.event(self.name, "whoreply")
|
||||||
|
|
||||||
def irc_RPL_ENDOFWHO(self, prefix, params):
|
def irc_RPL_ENDOFWHO(self, prefix, params):
|
||||||
channel = params[1]
|
channel = params[1]
|
||||||
|
@ -148,38 +153,46 @@ class IRCBot(IRCClient):
|
||||||
self.msg(self.authentity, "IDENTIFY %s" % self.nspass)
|
self.msg(self.authentity, "IDENTIFY %s" % self.nspass)
|
||||||
for i in self.autojoin:
|
for i in self.autojoin:
|
||||||
self.join(i)
|
self.join(i)
|
||||||
|
count.event(self.name, "signedon")
|
||||||
|
|
||||||
def joined(self, channel):
|
def joined(self, channel):
|
||||||
if not channel in self.channels:
|
if not channel in self.channels:
|
||||||
self.channels.append(channel)
|
self.channels.append(channel)
|
||||||
self.who(channel).addCallback(self.got_who)
|
self.who(channel).addCallback(self.got_who)
|
||||||
|
count.event(self.name, "selfjoin")
|
||||||
|
|
||||||
def left(self, channel):
|
def left(self, channel):
|
||||||
if channel in self.channels:
|
if channel in self.channels:
|
||||||
self.channels.remove(channel)
|
self.channels.remove(channel)
|
||||||
|
count.event(self.name, "selfpart")
|
||||||
|
|
||||||
def kickedFrom(self, channel, kicker, message):
|
def kickedFrom(self, channel, kicker, message):
|
||||||
if channel in self.channels:
|
if channel in self.channels:
|
||||||
self.channels.remove(channel)
|
self.channels.remove(channel)
|
||||||
keyword.sendMaster("KICK %s: (%s/%s) %s" % (self.name, kicker, channel, message))
|
keyword.sendMaster("KICK %s: (%s/%s) %s" % (self.name, kicker, channel, message))
|
||||||
|
count.event(self.name, "selfkick")
|
||||||
|
|
||||||
def userJoined(self, user, channel):
|
def userJoined(self, user, channel):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "join")
|
||||||
|
|
||||||
def userLeft(self, user, channel):
|
def userLeft(self, user, channel):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "part")
|
||||||
|
|
||||||
def userQuit(self, user, quitMessage):
|
def userQuit(self, user, quitMessage):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "quit")
|
||||||
|
|
||||||
keyword.actKeyword(user, None, quitMessage, self.nickname, "QUT", self.name)
|
keyword.actKeyword(user, None, quitMessage, self.nickname, "QUT", self.name)
|
||||||
|
|
||||||
def userKicked(self, kickee, channel, kicker, message):
|
def userKicked(self, kickee, channel, kicker, message):
|
||||||
nick, ident, host = self.parsen(kicker)
|
nick, ident, host = self.parsen(kicker)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "kick")
|
||||||
|
|
||||||
keyword.actKeyword(kicker, channel, message, self.nickname, "KCK", self.name)
|
keyword.actKeyword(kicker, channel, message, self.nickname, "KCK", self.name)
|
||||||
|
|
||||||
|
@ -187,16 +200,19 @@ class IRCBot(IRCClient):
|
||||||
nick, ident, host = self.parsen(oldname)
|
nick, ident, host = self.parsen(oldname)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
userinfo.setWhoSingle(self.name, newname, ident, host)
|
userinfo.setWhoSingle(self.name, newname, ident, host)
|
||||||
|
count.event(self.name, "nick")
|
||||||
|
|
||||||
def topicUpdated(self, user, channel, newTopic):
|
def topicUpdated(self, user, channel, newTopic):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "topic")
|
||||||
|
|
||||||
keyword.actKeyword(user, channel, newTopic, self.nickname, "TOP", self.name)
|
keyword.actKeyword(user, channel, newTopic, self.nickname, "TOP", self.name)
|
||||||
|
|
||||||
def modeChanged(self, user, channel, toset, modes, args):
|
def modeChanged(self, user, channel, toset, modes, args):
|
||||||
nick, ident, host = self.parsen(user)
|
nick, ident, host = self.parsen(user)
|
||||||
userinfo.setWhoSingle(self.name, nick, ident, host)
|
userinfo.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
count.event(self.name, "mode")
|
||||||
|
|
||||||
class IRCBotFactory(ReconnectingClientFactory):
|
class IRCBotFactory(ReconnectingClientFactory):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
|
|
@ -11,6 +11,7 @@ filemap = {
|
||||||
"pool": ["pool.json", "pool"],
|
"pool": ["pool.json", "pool"],
|
||||||
"help": ["help.json", "command help"],
|
"help": ["help.json", "command help"],
|
||||||
"wholist": ["wholist.json", "WHO lists"],
|
"wholist": ["wholist.json", "WHO lists"],
|
||||||
|
"counters": ["counters.json", "counters file"],
|
||||||
}
|
}
|
||||||
|
|
||||||
numbers = "0123456789"
|
numbers = "0123456789"
|
||||||
|
@ -28,7 +29,7 @@ CommandMap = {}
|
||||||
def register(command, function):
|
def register(command, function):
|
||||||
if not command in CommandMap:
|
if not command in CommandMap:
|
||||||
CommandMap[command] = function
|
CommandMap[command] = function
|
||||||
log("Registering command %s" % command)
|
debug("Registered command: %s" % command)
|
||||||
else:
|
else:
|
||||||
error("Duplicate command: %s" % (command))
|
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
|
|
@ -21,6 +21,7 @@ from core.main import (
|
||||||
loadConf,
|
loadConf,
|
||||||
initMain,
|
initMain,
|
||||||
)
|
)
|
||||||
|
|
||||||
initMain()
|
initMain()
|
||||||
|
|
||||||
from core.main import (
|
from core.main import (
|
||||||
|
@ -29,6 +30,7 @@ from core.main import (
|
||||||
pool,
|
pool,
|
||||||
help,
|
help,
|
||||||
wholist,
|
wholist,
|
||||||
|
counters,
|
||||||
)
|
)
|
||||||
|
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
|
|
Loading…
Reference in New Issue