Implement query notifications and recognise ZNC's messages
This commit is contained in:
parent
2e2e35cad7
commit
66e7785f6f
|
@ -13,6 +13,9 @@ class Add:
|
||||||
|
|
||||||
if length > 1:
|
if length > 1:
|
||||||
name = spl[1]
|
name = spl[1]
|
||||||
|
if name.isdigit():
|
||||||
|
failure("Network name is all numbers. This will break things.")
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
incUsage("add")
|
incUsage("add")
|
||||||
return
|
return
|
||||||
|
@ -71,9 +74,7 @@ class Add:
|
||||||
failure("Protocol must be ssl or plain, not %s" % protocol)
|
failure("Protocol must be ssl or plain, not %s" % protocol)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
if not port.isdigit():
|
||||||
int(port)
|
|
||||||
except:
|
|
||||||
failure("Port must be an integer, not %s" % port)
|
failure("Port must be an integer, not %s" % port)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Delete:
|
||||||
if not spl[1] in main.pool.keys():
|
if not spl[1] in main.pool.keys():
|
||||||
failure("Name does not exist: %s" % spl[1])
|
failure("Name does not exist: %s" % spl[1])
|
||||||
return
|
return
|
||||||
del pool[spl[1]]
|
del main.pool[spl[1]]
|
||||||
if spl[1] in main.ReactorPool.keys():
|
if spl[1] in main.ReactorPool.keys():
|
||||||
if spl[1] in main.FactoryPool.keys():
|
if spl[1] in main.FactoryPool.keys():
|
||||||
main.FactoryPool[spl[1]].stopTrying()
|
main.FactoryPool[spl[1]].stopTrying()
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Key:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if not spl[2] in spl[3]:
|
if not spl[2] in spl[3]:
|
||||||
failure("Keyword %s not in exception %s. This won't work" % (spl[2], spl[3]))
|
failure("Keyword %s not in exception %s. This won't work." % (spl[2], spl[3]))
|
||||||
return
|
return
|
||||||
main.keyconf["KeywordsExcept"][spl[2]] = []
|
main.keyconf["KeywordsExcept"][spl[2]] = []
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import main
|
||||||
|
|
||||||
|
class Msg:
|
||||||
|
def __init__(self, register):
|
||||||
|
register("msg", self.msg)
|
||||||
|
|
||||||
|
def msg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||||
|
if authed:
|
||||||
|
if length >= 4:
|
||||||
|
if not spl[1] in main.pool.keys():
|
||||||
|
failure("Name does not exist: %s" % spl[1])
|
||||||
|
return
|
||||||
|
if not spl[1] in main.IRCPool.keys():
|
||||||
|
failure("Name has no instance: %s" % spl[1])
|
||||||
|
return
|
||||||
|
if not spl[2] in main.IRCPool[spl[1]].channels:
|
||||||
|
info("Bot not on channel: %s" % spl[2])
|
||||||
|
main.IRCPool[spl[1]].msg(spl[2], " ".join(spl[3:]))
|
||||||
|
success("Sent %s to %s on %s" % (" ".join(spl[3:]), spl[2], spl[1]))
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
incUsage("msg")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
incUsage(None)
|
|
@ -8,14 +8,25 @@
|
||||||
},
|
},
|
||||||
"UsePassword": true,
|
"UsePassword": true,
|
||||||
"ConnectOnCreate": false,
|
"ConnectOnCreate": false,
|
||||||
"HighlightNotifications": true,
|
"Notifications": {
|
||||||
"ConnectionNotifications": true,
|
"Highlight": true,
|
||||||
|
"Connection": true,
|
||||||
|
"Query": true
|
||||||
|
},
|
||||||
|
"Compat": {
|
||||||
|
"ZNC": true
|
||||||
|
},
|
||||||
"Dist": {
|
"Dist": {
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"SendOutput": false,
|
"SendOutput": false,
|
||||||
"File": "conf/dist.sh"
|
"File": "conf/dist.sh"
|
||||||
},
|
},
|
||||||
"Password": "s",
|
"Password": "s",
|
||||||
|
"Tweaks": {
|
||||||
|
"ZNC": {
|
||||||
|
"Prefix": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"Default": {
|
"Default": {
|
||||||
"host": null,
|
"host": null,
|
||||||
"port": null,
|
"port": null,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"mod": "mod <name> [<key>] [<value>]",
|
"mod": "mod <name> [<key>] [<value>]",
|
||||||
"default": "default [<key>] [<value>]",
|
"default": "default [<key>] [<value>]",
|
||||||
"get": "get <name> <variable>",
|
"get": "get <name> <variable>",
|
||||||
"key": "key <master|show|add|del|except|unexcept|showexcept|monitor> [<name>] [<target>] [<key>] [<on|off>]",
|
"key": "key <master|show|add|del|except|unexcept|showexcept|monitor> [<name>] [<target>] [<key...>] [<on|off>]",
|
||||||
"who": "who <nick>",
|
"who": "who <nick>",
|
||||||
"join": "join <name> <channel> [<key>]",
|
"join": "join <name> <channel> [<key>]",
|
||||||
"enable": "enable <name>",
|
"enable": "enable <name>",
|
||||||
|
@ -16,5 +16,6 @@
|
||||||
"save": "save <config|keyconf|pool|help|wholist|counters|masterbuf|all>",
|
"save": "save <config|keyconf|pool|help|wholist|counters|masterbuf|all>",
|
||||||
"load": "load <config|keyconf|pool|help|wholist|counters|masterbuf|all>",
|
"load": "load <config|keyconf|pool|help|wholist|counters|masterbuf|all>",
|
||||||
"dist": "dist",
|
"dist": "dist",
|
||||||
"loadmod": "loadmod <module>"
|
"loadmod": "loadmod <module>",
|
||||||
|
"msg": "msg <name> <target> <message...>"
|
||||||
}
|
}
|
|
@ -220,7 +220,7 @@ class IRCBot(IRCClient):
|
||||||
def signedOn(self):
|
def signedOn(self):
|
||||||
self.connected = True
|
self.connected = True
|
||||||
log("signed on: %s" % self.name)
|
log("signed on: %s" % self.name)
|
||||||
if main.config["ConnectionNotifications"]:
|
if main.config["Notifications"]["Connection"]:
|
||||||
keyword.sendMaster("SIGNON: %s" % self.name)
|
keyword.sendMaster("SIGNON: %s" % self.name)
|
||||||
if self.authtype == "ns":
|
if self.authtype == "ns":
|
||||||
self.msg(self.authentity, "IDENTIFY %s" % self.nspass)
|
self.msg(self.authentity, "IDENTIFY %s" % self.nspass)
|
||||||
|
@ -316,7 +316,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
error = reason.getErrorMessage()
|
error = reason.getErrorMessage()
|
||||||
log("%s: connection lost: %s" % (self.name, error))
|
log("%s: connection lost: %s" % (self.name, error))
|
||||||
sendAll("%s: connection lost: %s" % (self.name, error))
|
sendAll("%s: connection lost: %s" % (self.name, error))
|
||||||
if main.config["ConnectionNotifications"]:
|
if main.config["Notifications"]["Connection"]:
|
||||||
keyword.sendMaster("CONNLOST %s: %s" % (self.name, error))
|
keyword.sendMaster("CONNLOST %s: %s" % (self.name, error))
|
||||||
self.retry(connector)
|
self.retry(connector)
|
||||||
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
||||||
|
@ -328,7 +328,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
error = reason.getErrorMessage()
|
error = reason.getErrorMessage()
|
||||||
log("%s: connection failed: %s" % (self.name, error))
|
log("%s: connection failed: %s" % (self.name, error))
|
||||||
sendAll("%s: connection failed: %s" % (self.name, error))
|
sendAll("%s: connection failed: %s" % (self.name, error))
|
||||||
if main.config["ConnectionNotifications"]:
|
if main.config["Notifications"]["Connection"]:
|
||||||
keyword.sendMaster("CONNFAIL %s: %s" % (self.name, error))
|
keyword.sendMaster("CONNFAIL %s: %s" % (self.name, error))
|
||||||
self.retry(connector)
|
self.retry(connector)
|
||||||
#ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
#ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
||||||
|
|
|
@ -75,13 +75,30 @@ def actKeyword(user, channel, message, nickname, actType, name):
|
||||||
if name == main.config["Master"][0] and channel == main.config["Master"][1]:
|
if name == main.config["Master"][0] and channel == main.config["Master"][1]:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if main.config["HighlightNotifications"]:
|
msgLower = message.lower()
|
||||||
msgLower = message.lower()
|
nickLower = nickname.lower()
|
||||||
nickLower = nickname.lower()
|
if nickLower in msgLower: # Someone has said the bot's nickname
|
||||||
if nickLower in msgLower:
|
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
||||||
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
count.event(name, "nickhighlight")
|
||||||
|
if main.config["Notifications"]["Highlight"]:
|
||||||
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 not channel == None:
|
||||||
|
chanLower = channel.lower()
|
||||||
|
if nickLower == chanLower: # I received a message directed only at me
|
||||||
|
ZNCAlreadySent = False
|
||||||
|
if main.config["Notifications"]["Query"]:
|
||||||
|
if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in":
|
||||||
|
if main.config["Compat"]["ZNC"]:
|
||||||
|
sendMaster("ZNC %s %s: (%s/%s) %s" % (actType, name, user, channel, msgLower))
|
||||||
|
ZNCAlreadySent = True
|
||||||
|
else:
|
||||||
|
sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower))
|
||||||
|
else:
|
||||||
|
sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower))
|
||||||
|
if not ZNCAlreadySent == True:
|
||||||
|
if main.config["Compat"]["ZNC"]:
|
||||||
|
if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in":
|
||||||
|
sendMaster("ZNC %s %s: (%s/%s) %s" % (actType, name, user, channel, msgLower))
|
||||||
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")
|
count.event(name, "keymatch")
|
||||||
|
|
Loading…
Reference in New Issue