Add deduplication precision toggle, fix printing odd characters and implement sending messages to all instances of a certain network, or all networks associated with a certain alias

This commit is contained in:
Mark Veidemanis 2019-08-16 21:27:23 +01:00
parent 22bd0d3ac6
commit 545282e201
5 changed files with 55 additions and 4 deletions

46
commands/allc.py Normal file
View File

@ -0,0 +1,46 @@
import main
from core.bot import deliverRelayCommands
class Allc:
def __init__(self, *args):
self.allc(*args)
def allc(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length > 4:
targets = []
if spl[1] == "network":
if spl[2] in main.network.keys():
for i in main.pool.keys():
if main.pool[i]["network"] == spl[2]:
targets.append(i)
else:
failure("No such network: %s" % spl[2])
return
elif spl[1] == "alias":
if spl[2] in main.alias.keys():
for i in main.pool.keys():
if main.pool[i]["alias"] == spl[2]:
targets.append(i)
else:
failure("No such alias: %s" % spl[2])
return
else:
incUsage("allc")
return
if len(targets) == 0:
failure("No matches found: %s" % spl[2])
return
for i in targets:
relay = main.pool[i]["relay"]
network = main.pool[i]["network"]
alias = main.pool[i]["alias"]
commands = {spl[3]: [" ".join(spl[4:])]}
success("Sending commands to relay %s as user %s" % (relay, alias+"/"+network))
deliverRelayCommands(relay, commands, user=alias+"/"+network)
return
else:
incUsage("allc")
return
else:
incUsage(None)

View File

@ -28,6 +28,7 @@
"Password": "s",
"Tweaks": {
"MaxHash": 10,
"DedupPrecision": 9,
"ZNC": {
"Prefix": "*"
},

View File

@ -25,5 +25,6 @@
"provision": "provision <relay> <alias> [<network>]",
"cmd": "cmd <relay> <user> <entity> <text ...>",
"token": "token <add|del|list> [<key>] [<relay>]",
"all": "all <entity> <text ...>"
"all": "all <entity> <text ...>",
"allc": "allc <network|alias> <(network)|(alias)> <entity> <text ...>"
}

View File

@ -1,11 +1,14 @@
#!/usr/bin/env python
from twisted.internet import reactor
from twisted.internet.ssl import DefaultOpenSSLContextFactory
from sys import argv
from sys import argv, stdout, stderr
#from twisted.python import log
#from sys import stdout
#log.startLogging(stdout)
from codecs import getwriter # fix printing odd shit to the terminal
stdout = getwriter("utf8")(stdout) # this is a generic fix but we all know
stderr = getwriter("utf8")(stderr) # it's just for the retards on Rizon using
# unicode quit messages for no reason
import main
main.initMain()

View File

@ -6,7 +6,7 @@ from utils.logging.debug import debug
def dedup(numName, c):
# deduplication
c["approxtime"] = int(datetime.utcnow().timestamp())
c["approxtime"] = str(datetime.utcnow().timestamp())[:main.config["Tweaks"]["DedupPrecision"]]
castHash = siphash24(main.hashKey, dumps(c, sort_keys=True).encode("utf-8"))
del c["approxtime"]
isDuplicate= any(castHash in main.lastEvents[x] for x in main.lastEvents.keys() if not x == numName)