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