Implement delivery of keyword match notifications
This commit is contained in:
parent
b8e9efa41e
commit
742d9c0c91
|
@ -5,5 +5,8 @@
|
|||
"ListenerKey": "key.pem",
|
||||
"ListenerCertificate": "cert.pem",
|
||||
"UsePassword": true,
|
||||
"Password": "s"
|
||||
"ConnectOnCreate": false,
|
||||
"Password": "s",
|
||||
"Keywords": [],
|
||||
"Master": []
|
||||
}
|
||||
|
|
42
threshold
42
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]
|
||||
|
|
Loading…
Reference in New Issue