Implement statistics and shorten some functions
This commit is contained in:
parent
5b6bf59d7a
commit
bef1875186
|
@ -8,9 +8,10 @@
|
||||||
"key": "key <master|show|add|del|except|unexcept|showexcept|monitor> [<name>] [<target>] [<key>] [<on|off>]",
|
"key": "key <master|show|add|del|except|unexcept|showexcept|monitor> [<name>] [<target>] [<key>] [<on|off>]",
|
||||||
"who": "who <nick>",
|
"who": "who <nick>",
|
||||||
"join": "join <name> <channel> [<key>]",
|
"join": "join <name> <channel> [<key>]",
|
||||||
"enable": "enable <name",
|
"enable": "enable <name>",
|
||||||
"disable": "disable <name>",
|
"disable": "disable <name>",
|
||||||
"list": "list",
|
"list": "list",
|
||||||
|
"stats": "stats",
|
||||||
"rehash": "rehash",
|
"rehash": "rehash",
|
||||||
"rekey": "rekey",
|
"rekey": "rekey",
|
||||||
"dist": "dist"
|
"dist": "dist"
|
||||||
|
|
148
threshold
148
threshold
|
@ -91,47 +91,35 @@ class IRCBot(IRCClient):
|
||||||
self.versionEnv = None
|
self.versionEnv = None
|
||||||
self.sourceURL = instance["source"]
|
self.sourceURL = instance["source"]
|
||||||
|
|
||||||
def privmsg(self, user, channel, msg):
|
def parsen(self, user):
|
||||||
toSend = helper.isKeyword(msg)
|
step = user.split("!")
|
||||||
if self.name == config["Master"][0] and channel == config["Master"][1]:
|
nick = step[0]
|
||||||
pass
|
if len(step) == 2:
|
||||||
|
step2 = step[1].split("@")
|
||||||
|
ident, host = step2
|
||||||
else:
|
else:
|
||||||
if config["HighlightNotifications"]:
|
ident = nick
|
||||||
msgLower = msg.lower()
|
host = nick
|
||||||
nickLower = self.nickname.lower()
|
|
||||||
if nickLower in msgLower:
|
return [nick, ident, host]
|
||||||
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
|
||||||
helper.sendMaster("NICK PRV %s (T:%s): (%s/%s) %s" % (self.name, msgLower.count(nickLower), user, channel, msgLower))
|
def privmsg(self, user, channel, msg):
|
||||||
if toSend:
|
nick, ident, host = self.parsen(user)
|
||||||
helper.sendMaster("MATCH PRV %s (U:%s T:%s): (%s/%s) %s" % (self.name, toSend[1], toSend[2], user, channel, toSend[0]))
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
|
||||||
|
helper.actKeyword(user, channel, msg, self.nickname, "PRV", self.name)
|
||||||
|
|
||||||
def noticed(self, user, channel, msg):
|
def noticed(self, user, channel, msg):
|
||||||
toSend = helper.isKeyword(msg)
|
nick, ident, host = self.parsen(user)
|
||||||
if self.name == config["Master"][0] and channel == config["Master"][1]:
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
pass
|
|
||||||
else:
|
helper.actKeyword(user, channel, msg, self.nickname, "NOT", self.name)
|
||||||
if config["HighlightNotifications"]:
|
|
||||||
msgLower = msg.lower()
|
|
||||||
nickLower = self.nickname.lower()
|
|
||||||
if nickLower in msgLower:
|
|
||||||
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
|
||||||
helper.sendMaster("NICK NOT %s (T:%s): (%s/%s) %s" % (self.name, msgLower.count(nickLower), user, channel, msgLower))
|
|
||||||
if toSend:
|
|
||||||
helper.sendMaster("MATCH NOT %s (U:%s T:%s): (%s/%s) %s" % (self.name, toSend[1], toSend[2], user, channel, toSend[0]))
|
|
||||||
|
|
||||||
def action(self, user, channel, msg):
|
def action(self, user, channel, msg):
|
||||||
toSend = helper.isKeyword(msg)
|
nick, ident, host = self.parsen(user)
|
||||||
if self.name == config["Master"][0] and channel == config["Master"][1]:
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
pass
|
|
||||||
else:
|
helper.actKeyword(user, channel, msg, self.nickname, "ACT", self.name)
|
||||||
if config["HighlightNotifications"]:
|
|
||||||
msgLower = msg.lower()
|
|
||||||
nickLower = self.nickname.lower()
|
|
||||||
if nickLower in msgLower:
|
|
||||||
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
|
||||||
helper.sendMaster("NICK ACT %s (T:%s): (%s/%s) %s" % (self.name, msgLower.count(nickLower), user, channel, msgLower))
|
|
||||||
if toSend:
|
|
||||||
helper.sendMaster("MATCH ACT %s (U:%s T:%s): (%s/%s) %s" % (self.name, toSend[1], toSend[2], user, channel, toSend[0]))
|
|
||||||
|
|
||||||
def get(self, var):
|
def get(self, var):
|
||||||
try:
|
try:
|
||||||
|
@ -214,6 +202,33 @@ class IRCBot(IRCClient):
|
||||||
self.channels.remove(channel)
|
self.channels.remove(channel)
|
||||||
helper.sendMaster("KICK %s: (%s/%s) %s" % (self.name, kicker, channel, message))
|
helper.sendMaster("KICK %s: (%s/%s) %s" % (self.name, kicker, channel, message))
|
||||||
|
|
||||||
|
def userJoined(self, user, channel):
|
||||||
|
nick, ident, host = self.parsen(user)
|
||||||
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
|
||||||
|
def userLeft(self, user, channel):
|
||||||
|
nick, ident, host = self.parsen(user)
|
||||||
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
|
||||||
|
def userQuit(self, user, quitMessage):
|
||||||
|
nick, ident, host = self.parsen(user)
|
||||||
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
|
||||||
|
helper.actKeyword(user, None, quitMessage, self.nickname, "QUT", self.name)
|
||||||
|
|
||||||
|
def userKicked(self, kickee, channel, kicker, message):
|
||||||
|
helper.actKeyword(kicker, channel, message, self.nickname, "KCK", self.name)
|
||||||
|
|
||||||
|
def topicUpdated(self, user, channel, newTopic):
|
||||||
|
nick, ident, host = self.parsen(user)
|
||||||
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
|
||||||
|
helper.actKeyword(user, channel, newTopic, self.nickname, "TOP", self.name)
|
||||||
|
|
||||||
|
def modeChanged(self, user, channel, toset, modes, args):
|
||||||
|
nick, ident, host = self.parsen(user)
|
||||||
|
helper.setWhoSingle(self.name, nick, ident, host)
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.channels = []
|
self.channels = []
|
||||||
|
@ -420,6 +435,20 @@ class Helper(object):
|
||||||
else:
|
else:
|
||||||
return [message, uniqueNum, totalNum]
|
return [message, uniqueNum, totalNum]
|
||||||
|
|
||||||
|
def actKeyword(self, user, channel, message, nickname, actType, name):
|
||||||
|
toSend = self.isKeyword(message)
|
||||||
|
if name == config["Master"][0] and channel == config["Master"][1]:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if config["HighlightNotifications"]:
|
||||||
|
msgLower = message.lower()
|
||||||
|
nickLower = nickname.lower()
|
||||||
|
if nickLower in msgLower:
|
||||||
|
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
||||||
|
self.sendMaster("NICK %s %s (T:%s): (%s/%s) %s" % (actType, name, msgLower.count(nickLower), user, channel, msgLower))
|
||||||
|
if toSend:
|
||||||
|
helper.sendMaster("MATCH %s %s (U:%s T:%s): (%s/%s) %s" % (actType, name, toSend[1], toSend[2], user, channel, toSend[0]))
|
||||||
|
|
||||||
def addBot(self, name):
|
def addBot(self, name):
|
||||||
global IRCPool
|
global IRCPool
|
||||||
instance = pool[name]
|
instance = pool[name]
|
||||||
|
@ -471,7 +500,7 @@ class Helper(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def parseCommand(self, addr, authed, data):
|
def parseCommand(self, addr, authed, data):
|
||||||
global pool, MonitorPool
|
global pool, MonitorPool, wholist
|
||||||
spl = data.split()
|
spl = data.split()
|
||||||
if addr in connections.keys():
|
if addr in connections.keys():
|
||||||
obj = connections[addr]
|
obj = connections[addr]
|
||||||
|
@ -541,6 +570,47 @@ class Helper(object):
|
||||||
info("\n".join(poolMap))
|
info("\n".join(poolMap))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
elif cmd == "stats":
|
||||||
|
if length == 1:
|
||||||
|
stats = []
|
||||||
|
numChannels = 0
|
||||||
|
numWhoEntries = 0
|
||||||
|
for i in IRCPool.keys():
|
||||||
|
numChannels += len(IRCPool[i].channels)
|
||||||
|
for i in wholist.keys():
|
||||||
|
numWhoEntries += len(wholist[i].keys())
|
||||||
|
stats.append("Servers: %s" % len(IRCPool.keys()))
|
||||||
|
stats.append("Channels: %s" % numChannels)
|
||||||
|
stats.append("User records: %s" % numWhoEntries)
|
||||||
|
info("\n".join(stats))
|
||||||
|
return
|
||||||
|
|
||||||
|
elif length == 2:
|
||||||
|
stats = []
|
||||||
|
numChannels = 0
|
||||||
|
numWhoEntries = 0
|
||||||
|
|
||||||
|
failures = 0
|
||||||
|
if spl[1] in IRCPool.keys():
|
||||||
|
numChannels += len(IRCPool[spl[1]].channels)
|
||||||
|
else:
|
||||||
|
failure("Name does not exist: %s" % spl[1])
|
||||||
|
failures += 1
|
||||||
|
if spl[1] in wholist.keys():
|
||||||
|
numWhoEntries += len(wholist[spl[1]].keys())
|
||||||
|
else:
|
||||||
|
failure("Who entry does not exist: %s" % spl[1])
|
||||||
|
failures += 1
|
||||||
|
if failures == 2:
|
||||||
|
failure("No information found, aborting")
|
||||||
|
return
|
||||||
|
stats.append("Channels: %s" % numChannels)
|
||||||
|
stats.append("User records: %s" % numWhoEntries)
|
||||||
|
info("\n".join(stats))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
incUsage("stats")
|
||||||
|
|
||||||
elif cmd == "enable":
|
elif cmd == "enable":
|
||||||
if length == 2:
|
if length == 2:
|
||||||
if not spl[1] in pool.keys():
|
if not spl[1] in pool.keys():
|
||||||
|
@ -630,7 +700,6 @@ class Helper(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
elif cmd == "who":
|
elif cmd == "who":
|
||||||
global wholist
|
|
||||||
if length == 2:
|
if length == 2:
|
||||||
result = self.getWho(spl[1])
|
result = self.getWho(spl[1])
|
||||||
rtrn = ""
|
rtrn = ""
|
||||||
|
@ -638,7 +707,8 @@ class Helper(object):
|
||||||
rtrn += "Matches from: %s" % i
|
rtrn += "Matches from: %s" % i
|
||||||
rtrn += "\n"
|
rtrn += "\n"
|
||||||
for x in result[i]:
|
for x in result[i]:
|
||||||
rtrn += (", ".join(x))
|
x = [y for y in x if not y == None]
|
||||||
|
rtrn += str((", ".join(x)))
|
||||||
rtrn += "\n"
|
rtrn += "\n"
|
||||||
info(rtrn)
|
info(rtrn)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue