diff --git a/.gitignore b/.gitignore index 0f1e65e..f3d7146 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ conf/pool.json conf/wholist.json conf/keyword.json conf/counters.json +conf/masterbuf.json conf/dist.sh env/ diff --git a/commands/key.py b/commands/key.py index e523097..7a5ccb0 100644 --- a/commands/key.py +++ b/commands/key.py @@ -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: diff --git a/commands/save.py b/commands/save.py index 64c4cbf..7fbb85c 100644 --- a/commands/save.py +++ b/commands/save.py @@ -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") diff --git a/conf/example/counters.json b/conf/example/counters.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/conf/example/counters.json @@ -0,0 +1 @@ +{} diff --git a/conf/example/masterbuf.json b/conf/example/masterbuf.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/conf/example/masterbuf.json @@ -0,0 +1 @@ +[] diff --git a/conf/example/pool.json b/conf/example/pool.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/conf/example/pool.json @@ -0,0 +1 @@ +{} diff --git a/conf/example/wholist.json b/conf/example/wholist.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/conf/example/wholist.json @@ -0,0 +1 @@ +{} diff --git a/conf/help.json b/conf/help.json index 30ef842..e251599 100644 --- a/conf/help.json +++ b/conf/help.json @@ -13,8 +13,8 @@ "disable": "disable ", "list": "list", "stats": "stats []", - "save": "save ", - "load": "load ", + "save": "save ", + "load": "load ", "dist": "dist", "loadmod": "loadmod " } \ No newline at end of file diff --git a/conf/keyword.json b/conf/keyword.json index fc70716..3980412 100644 --- a/conf/keyword.json +++ b/conf/keyword.json @@ -1,4 +1,6 @@ { - "Keywords": [], + "Keywords": [ + "example" + ], "KeywordsExcept": {} } \ No newline at end of file diff --git a/core/bot.py b/core/bot.py index 4b33fce..b5f6acb 100644 --- a/core/bot.py +++ b/core/bot.py @@ -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: diff --git a/core/main.py b/core/main.py index b393d7f..17cfaef 100644 --- a/core/main.py +++ b/core/main.py @@ -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 = {} diff --git a/modules/keyword.py b/modules/keyword.py index 43547f6..25207bc 100644 --- a/modules/keyword.py +++ b/modules/keyword.py @@ -1,11 +1,36 @@ from core.main import * from utils.logging.log import * +import modules.counters as count def sendMaster(data): - if config["Master"][0] in IRCPool.keys(): - IRCPool[config["Master"][0]].msg(config["Master"][1], 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"]: diff --git a/modules/userinfo.py b/modules/userinfo.py index f0403fe..ad7fe04 100644 --- a/modules/userinfo.py +++ b/modules/userinfo.py @@ -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(): diff --git a/threshold b/threshold index eb72cf3..f83795b 100755 --- a/threshold +++ b/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() diff --git a/utils/fileutil/read_line.py b/utils/fileutil/read_line.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/fileutil/write_line.py b/utils/fileutil/write_line.py new file mode 100644 index 0000000..e69de29