diff --git a/commands/add.py b/commands/add.py index 946bd8a..e2eac5d 100644 --- a/commands/add.py +++ b/commands/add.py @@ -13,6 +13,9 @@ class Add: if length > 1: name = spl[1] + if name.isdigit(): + failure("Network name is all numbers. This will break things.") + return else: incUsage("add") return @@ -71,9 +74,7 @@ class Add: failure("Protocol must be ssl or plain, not %s" % protocol) return - try: - int(port) - except: + if not port.isdigit(): failure("Port must be an integer, not %s" % port) return diff --git a/commands/delete.py b/commands/delete.py index 18d2189..fb57b71 100644 --- a/commands/delete.py +++ b/commands/delete.py @@ -10,7 +10,7 @@ class Delete: if not spl[1] in main.pool.keys(): failure("Name does not exist: %s" % spl[1]) return - del pool[spl[1]] + del main.pool[spl[1]] if spl[1] in main.ReactorPool.keys(): if spl[1] in main.FactoryPool.keys(): main.FactoryPool[spl[1]].stopTrying() diff --git a/commands/key.py b/commands/key.py index 943d03e..20f1b2a 100644 --- a/commands/key.py +++ b/commands/key.py @@ -48,7 +48,7 @@ class Key: return else: 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 main.keyconf["KeywordsExcept"][spl[2]] = [] diff --git a/commands/msg.py b/commands/msg.py new file mode 100644 index 0000000..a3bad7e --- /dev/null +++ b/commands/msg.py @@ -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) diff --git a/conf/example/config.json b/conf/example/config.json index f7bc320..ecd781d 100644 --- a/conf/example/config.json +++ b/conf/example/config.json @@ -8,14 +8,25 @@ }, "UsePassword": true, "ConnectOnCreate": false, - "HighlightNotifications": true, - "ConnectionNotifications": true, + "Notifications": { + "Highlight": true, + "Connection": true, + "Query": true + }, + "Compat": { + "ZNC": true + }, "Dist": { "Enabled": true, "SendOutput": false, "File": "conf/dist.sh" }, "Password": "s", + "Tweaks": { + "ZNC": { + "Prefix": "*" + } + }, "Default": { "host": null, "port": null, diff --git a/conf/help.json b/conf/help.json index e251599..f0b512a 100644 --- a/conf/help.json +++ b/conf/help.json @@ -6,7 +6,7 @@ "mod": "mod [] []", "default": "default [] []", "get": "get ", - "key": "key [] [] [] []", + "key": "key [] [] [] []", "who": "who ", "join": "join []", "enable": "enable ", @@ -16,5 +16,6 @@ "save": "save ", "load": "load ", "dist": "dist", - "loadmod": "loadmod " -} \ No newline at end of file + "loadmod": "loadmod ", + "msg": "msg " +} diff --git a/core/bot.py b/core/bot.py index 68250a8..4c9cbc7 100644 --- a/core/bot.py +++ b/core/bot.py @@ -220,7 +220,7 @@ class IRCBot(IRCClient): def signedOn(self): self.connected = True log("signed on: %s" % self.name) - if main.config["ConnectionNotifications"]: + if main.config["Notifications"]["Connection"]: keyword.sendMaster("SIGNON: %s" % self.name) if self.authtype == "ns": self.msg(self.authentity, "IDENTIFY %s" % self.nspass) @@ -316,7 +316,7 @@ class IRCBotFactory(ReconnectingClientFactory): error = reason.getErrorMessage() log("%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)) self.retry(connector) #ReconnectingClientFactory.clientConnectionLost(self, connector, reason) @@ -328,7 +328,7 @@ class IRCBotFactory(ReconnectingClientFactory): error = reason.getErrorMessage() log("%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)) self.retry(connector) #ReconnectingClientFactory.clientConnectionFailed(self, connector, reason) diff --git a/modules/keyword.py b/modules/keyword.py index 36e9f9b..4d7cd9c 100644 --- a/modules/keyword.py +++ b/modules/keyword.py @@ -75,13 +75,30 @@ def actKeyword(user, channel, message, nickname, actType, name): if name == main.config["Master"][0] and channel == main.config["Master"][1]: pass else: - if main.config["HighlightNotifications"]: - msgLower = message.lower() - nickLower = nickname.lower() - if nickLower in msgLower: - msgLower = msgLower.replace(nickLower, "{"+nickLower+"}") + msgLower = message.lower() + nickLower = nickname.lower() + if nickLower in msgLower: # Someone has said the bot's nickname + 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)) - 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: 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")