From 742d9c0c91cfaddf344a9748c583fa5dad2d8582 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 25 Nov 2017 18:42:32 +0000 Subject: [PATCH] Implement delivery of keyword match notifications --- example.json | 5 ++++- threshold | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/example.json b/example.json index 78f64ce..685e4fd 100644 --- a/example.json +++ b/example.json @@ -5,5 +5,8 @@ "ListenerKey": "key.pem", "ListenerCertificate": "cert.pem", "UsePassword": true, - "Password": "s" + "ConnectOnCreate": false, + "Password": "s", + "Keywords": [], + "Master": [] } diff --git a/threshold b/threshold index 66af64d..c1795aa 100755 --- a/threshold +++ b/threshold @@ -67,6 +67,21 @@ class IRCBot(IRCClient): else: self.password = instance["password"] + def privmsg(self, user, channel, msg): + toSend = helper.isKeyword(msg) + if toSend: + helper.sendMaster("MATCH PRV %s (U:%s T:%s): (%s/%s) %s" % (self.name, toSend[1], toSend[2], user, channel, toSend[0])) + + def noticed(self, user, channel, msg): + toSend = helper.isKeyword(msg) + 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): + toSend = helper.isKeyword(msg) + 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 refresh(self): instance = pool[self.name] if not instance["nickname"] == self.nickname: @@ -87,15 +102,6 @@ class IRCBot(IRCClient): result = None return result - def sanitize(self, user): - user = user.replace("!", "") - user = user.replace("~", "") - user = user.replace("&", "") - user = user.replace("@", "") - user = user.replace("%", "") - user = user.replace("+", "") - return user - def setNick(self, nickname): self._attemptedNick = nickname self.sendLine("NICK %s" % nickname) @@ -282,6 +288,24 @@ class Helper(object): connections[i].send(data) return + def sendMaster(self, data): + if config["Master"][0] in IRCPool.keys(): + IRCPool[config["Master"][0]].msg(config["Master"][1], data) + + def isKeyword(self, msg): + message = msg.lower() + uniqueNum = 0 + totalNum = 0 + for i in config["Keywords"]: + if i in message: + totalNum += message.count(i) + message = message.replace(i, "{"+i+"}") + uniqueNum += 1 + if message == msg: + return False + else: + return [message, uniqueNum, totalNum] + def addBot(self, name): global IRCPool instance = pool[name]