Implement counting keyword events and a unified buffers system for when the master channel is unavailable
This commit is contained in:
parent
eae4315562
commit
da6c45f093
|
@ -6,5 +6,6 @@ conf/pool.json
|
|||
conf/wholist.json
|
||||
conf/keyword.json
|
||||
conf/counters.json
|
||||
conf/masterbuf.json
|
||||
conf/dist.sh
|
||||
env/
|
||||
|
|
|
@ -97,6 +97,13 @@ class Key:
|
|||
if not obj.addr in MonitorPool:
|
||||
MonitorPool.append(obj.addr)
|
||||
success("Keyword monitoring enabled")
|
||||
if len(masterbuf) == 0:
|
||||
return
|
||||
rtrn = []
|
||||
for i in range(len(masterbuf)):
|
||||
rtrn.append(masterbuf.pop(0))
|
||||
saveConf("masterbuf")
|
||||
info("\n".join(rtrn))
|
||||
return
|
||||
else:
|
||||
failure("Keyword monitoring is already enabled")
|
||||
|
@ -129,7 +136,7 @@ class Key:
|
|||
info("\n".join(exceptMap))
|
||||
return
|
||||
elif spl[1] == "master":
|
||||
info(" - ".join(config["Master"]))
|
||||
info(" - ".join([str(i) for i in config["Master"]]))
|
||||
return
|
||||
elif spl[1] == "monitor":
|
||||
if obj.addr in MonitorPool:
|
||||
|
|
|
@ -14,7 +14,7 @@ class Save:
|
|||
elif spl[1] == "all":
|
||||
for i in filemap.keys():
|
||||
saveConf(i)
|
||||
success("Saved %s from %s" % (i, filemap[i][0]))
|
||||
success("Saved %s to %s" % (i, filemap[i][0]))
|
||||
return
|
||||
else:
|
||||
incUsage("save")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
[]
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -13,8 +13,8 @@
|
|||
"disable": "disable <name>",
|
||||
"list": "list",
|
||||
"stats": "stats [<name>]",
|
||||
"save": "save <config|keyconf|pool|help|wholist|counters|all>",
|
||||
"load": "load <config|keyconf|pool|help|wholist|counters|all>",
|
||||
"save": "save <config|keyconf|pool|help|wholist|counters|masterbuf|all>",
|
||||
"load": "load <config|keyconf|pool|help|wholist|counters|masterbuf|all>",
|
||||
"dist": "dist",
|
||||
"loadmod": "loadmod <module>"
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"Keywords": [],
|
||||
"Keywords": [
|
||||
"example"
|
||||
],
|
||||
"KeywordsExcept": {}
|
||||
}
|
|
@ -160,6 +160,10 @@ class IRCBot(IRCClient):
|
|||
self.channels.append(channel)
|
||||
self.who(channel).addCallback(self.got_who)
|
||||
count.event(self.name, "selfjoin")
|
||||
if self.name == config["Master"][0] and channel == config["Master"][1]:
|
||||
for i in range(len(masterbuf)):
|
||||
self.msg(channel, masterbuf.pop(0))
|
||||
saveConf("masterbuf")
|
||||
|
||||
def left(self, channel):
|
||||
if channel in self.channels:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from json import load, dump, loads
|
||||
|
||||
from utils.loaders.command_loader import loadCommands
|
||||
from utils.logging.log import *
|
||||
|
||||
|
@ -12,11 +13,9 @@ filemap = {
|
|||
"help": ["help.json", "command help"],
|
||||
"wholist": ["wholist.json", "WHO lists"],
|
||||
"counters": ["counters.json", "counters file"],
|
||||
"masterbuf": ["masterbuf.json", "master buffer"],
|
||||
}
|
||||
|
||||
numbers = "0123456789"
|
||||
|
||||
listener = None
|
||||
connections = {}
|
||||
IRCPool = {}
|
||||
ReactorPool = {}
|
||||
|
|
|
@ -1,11 +1,36 @@
|
|||
from core.main import *
|
||||
from utils.logging.log import *
|
||||
import modules.counters as count
|
||||
|
||||
def sendMaster(data):
|
||||
if not len(MonitorPool) == 0:
|
||||
hasMonitors = True
|
||||
else:
|
||||
hasMonitors = False
|
||||
|
||||
if config["Master"] == [None, None]:
|
||||
if hasMonitors:
|
||||
for i in MonitorPool:
|
||||
connections[i].send(data)
|
||||
return
|
||||
else:
|
||||
masterbuf.append(data)
|
||||
saveConf("masterbuf")
|
||||
return
|
||||
|
||||
if config["Master"][0] in IRCPool.keys():
|
||||
if config["Master"][1] in IRCPool[config["Master"][0]].channels:
|
||||
IRCPool[config["Master"][0]].msg(config["Master"][1], data)
|
||||
else:
|
||||
if not hasMonitors:
|
||||
masterbuf.append(data)
|
||||
saveConf("masterbuf")
|
||||
else:
|
||||
if not hasMonitors:
|
||||
masterbuf.append(data)
|
||||
saveConf("masterbuf")
|
||||
warn("Master with no IRC instance defined")
|
||||
|
||||
for i in MonitorPool:
|
||||
connections[i].send(data)
|
||||
|
||||
|
@ -52,8 +77,10 @@ def actKeyword(user, channel, message, nickname, actType, name):
|
|||
if nickLower in msgLower:
|
||||
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
||||
sendMaster("NICK %s %s (T:%s): (%s/%s) %s" % (actType, name, msgLower.count(nickLower), user, channel, msgLower))
|
||||
count.event(name, "nickhighlight")
|
||||
if toSend:
|
||||
sendMaster("MATCH %s %s (U:%s T:%s): (%s/%s) %s" % (actType, name, toSend[1], toSend[2], user, channel, toSend[0]))
|
||||
count.event(name, "keymatch")
|
||||
|
||||
def addKeyword(keyword):
|
||||
if keyword in keyconf["Keywords"]:
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from core.main import *
|
||||
from string import digits
|
||||
#from utils.logging.log import *
|
||||
|
||||
def setWho(network, newObjects):
|
||||
network = "".join([x for x in network if not x in numbers])
|
||||
network = "".join([x for x in network if not x in digits])
|
||||
if not network in wholist.keys():
|
||||
wholist[network] = {}
|
||||
for i in newObjects.keys():
|
||||
|
@ -11,7 +12,7 @@ def setWho(network, newObjects):
|
|||
return
|
||||
|
||||
def setWhoSingle(network, nick, ident, host):
|
||||
network = "".join([x for x in network if not x in numbers])
|
||||
network = "".join([x for x in network if not x in digits])
|
||||
|
||||
if network in wholist.keys():
|
||||
if nick in wholist[network].keys():
|
||||
|
|
10
threshold
10
threshold
|
@ -7,10 +7,8 @@ from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|||
#log.startLogging(stdout)
|
||||
|
||||
from core.main import (
|
||||
numbers,
|
||||
configPath,
|
||||
certPath,
|
||||
listener,
|
||||
connections,
|
||||
IRCPool,
|
||||
ReactorPool,
|
||||
|
@ -37,12 +35,7 @@ import modules.userinfo as userinfo
|
|||
import core.helper as helper
|
||||
from core.server import Server, ServerFactory
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for i in pool.keys():
|
||||
if pool[i]["enabled"] == True:
|
||||
helper.addBot(i)
|
||||
|
||||
listener = ServerFactory()
|
||||
if config["Listener"]["UseSSL"] == True:
|
||||
reactor.listenSSL(config["Listener"]["Port"], listener, DefaultOpenSSLContextFactory(certPath+config["Listener"]["Key"], certPath+config["Listener"]["Certificate"]), interface=config["Listener"]["Address"])
|
||||
|
@ -50,5 +43,8 @@ if __name__ == "__main__":
|
|||
else:
|
||||
reactor.listenTCP(config["Listener"]["Port"], listener, interface=config["Listener"]["Address"])
|
||||
log("Threshold running on %s:%s" % (config["Listener"]["Address"], config["Listener"]["Port"]))
|
||||
for i in pool.keys():
|
||||
if pool[i]["enabled"] == True:
|
||||
helper.addBot(i)
|
||||
|
||||
reactor.run()
|
||||
|
|
Loading…
Reference in New Issue