diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 11c38e8..98fa1cb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,21 +1,13 @@ repos: - - repo: https://github.com/psf/black - rev: 22.6.0 +- repo: https://github.com/ambv/black + rev: 22.3.0 hooks: - id: black - exclude: ^core/migrations - - repo: https://github.com/PyCQA/isort - rev: 5.10.1 - hooks: - - id: isort - - repo: https://github.com/PyCQA/flake8 + args: + - --line-length=120 +- repo: https://gitlab.com/pycqa/flake8 rev: 4.0.1 hooks: - - id: flake8 - args: [--max-line-length=88] - exclude: ^core/migrations - - repo: https://github.com/thibaudcolas/curlylint - rev: v0.13.1 - hooks: - - id: curlylint - files: \.(html|sls)$ + - id: flake8 + args: + - "--max-line-length=120" diff --git a/commands/admall.py b/commands/admall.py index cb0c009..8d74545 100644 --- a/commands/admall.py +++ b/commands/admall.py @@ -6,9 +6,7 @@ class AdmallCommand: def __init__(self, *args): self.admall(*args) - def admall( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def admall(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length > 2: for i in main.network.keys(): diff --git a/commands/alias.py b/commands/alias.py index 5bc12bf..d04cfdf 100644 --- a/commands/alias.py +++ b/commands/alias.py @@ -1,6 +1,5 @@ -from yaml import dump - import main +from yaml import dump from modules import alias @@ -8,9 +7,7 @@ class AliasCommand: def __init__(self, *args): self.alias(*args) - def alias( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: info(dump(main.alias)) diff --git a/commands/all.py b/commands/all.py index 16a6721..a2994e9 100644 --- a/commands/all.py +++ b/commands/all.py @@ -6,9 +6,7 @@ class AllCommand: def __init__(self, *args): self.all(*args) - def all( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def all(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length > 2: for i in main.network.keys(): @@ -17,10 +15,7 @@ class AllCommand: net = main.network[i].relays[x]["net"] alias = main.alias[x]["nick"] commands = {spl[1]: [" ".join(spl[2:])]} - success( - "Sending commands to relay %s as user %s" - % (num, alias + "/" + net) - ) + success("Sending commands to relay %s as user %s" % (num, alias + "/" + net)) deliverRelayCommands(num, commands, user=alias + "/" + net) return else: diff --git a/commands/allc.py b/commands/allc.py index 01698e5..7a7b5fd 100644 --- a/commands/allc.py +++ b/commands/allc.py @@ -6,9 +6,7 @@ class AllcCommand: def __init__(self, *args): self.allc(*args) - def allc( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def allc(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length > 4: targets = [] @@ -22,8 +20,7 @@ class AllcCommand: [ targets.append((i, x)) for x in main.alias.keys() - if main.alias[x]["nick"] == spl[2] - and x in main.network[i].aliases.keys() + if main.alias[x]["nick"] == spl[2] and x in main.network[i].aliases.keys() ] else: incUsage("allc") @@ -36,10 +33,7 @@ class AllcCommand: num = i[1] alias = main.alias[num]["nick"] commands = {spl[3]: [" ".join(spl[4:])]} - success( - "Sending commands to relay %i as user %s" - % (num, alias + "/" + net) - ) + success("Sending commands to relay %i as user %s" % (num, alias + "/" + net)) deliverRelayCommands(num, commands, user=alias + "/" + net) return else: diff --git a/commands/authcheck.py b/commands/authcheck.py index 7c41dd1..26cc14e 100644 --- a/commands/authcheck.py +++ b/commands/authcheck.py @@ -5,9 +5,7 @@ class AuthcheckCommand: def __init__(self, *args): self.authcheck(*args) - def authcheck( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def authcheck(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: results = [] @@ -15,9 +13,7 @@ class AuthcheckCommand: num = main.IRCPool[i].num net = main.IRCPool[i].net if not main.IRCPool[i].authenticated: - results.append( - "%s - %s: %s" % (net, num, main.alias[num]["nick"]) - ) + results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"])) info("\n".join(results)) return elif length == 2: @@ -31,9 +27,7 @@ class AuthcheckCommand: if not net == spl[1]: continue if not main.IRCPool[i].authenticated: - results.append( - "%s - %s: %s" % (net, num, main.alias[num]["nick"]) - ) + results.append("%s - %s: %s" % (net, num, main.alias[num]["nick"])) info("\n".join(results)) return else: diff --git a/commands/auto.py b/commands/auto.py index 378a102..ffc6df5 100644 --- a/commands/auto.py +++ b/commands/auto.py @@ -6,9 +6,7 @@ class AutoCommand: def __init__(self, *args): self.auto(*args) - def auto( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def auto(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: for i in main.network.keys(): @@ -16,15 +14,9 @@ class AutoCommand: info("Skipping %s - first relay exists" % i) else: num, alias = main.network[i].add_relay(1) - success( - "Successfully created first relay on network %s with alias %s" - % (i, alias) - ) + success("Successfully created first relay on network %s with alias %s" % (i, alias)) provision.provisionRelay(num, i) - success( - "Started provisioning network %s on first relay for alias %s" - % (i, alias) - ) + success("Started provisioning network %s on first relay for alias %s" % (i, alias)) main.saveConf("network") return elif length == 2: @@ -35,15 +27,9 @@ class AutoCommand: failure("First relay exists on %s" % spl[1]) return num, alias = main.network[spl[1]].add_relay(1) - success( - "Successfully created relay %i on network %s with alias %s" - % (num, spl[1], alias) - ) + success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias)) provision.provisionRelay(num, spl[1]) - success( - "Started provisioning network %s on relay %s for alias %s" - % (spl[1], num, alias) - ) + success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, alias)) main.saveConf("network") return else: diff --git a/commands/blacklist.py b/commands/blacklist.py index 858da28..42684a6 100644 --- a/commands/blacklist.py +++ b/commands/blacklist.py @@ -1,15 +1,12 @@ -from yaml import dump - import main +from yaml import dump class BlacklistCommand: def __init__(self, *args): self.blacklist(*args) - def blacklist( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def blacklist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: info(dump(main.blacklist)) diff --git a/commands/chans.py b/commands/chans.py index 8b820ff..1ccf710 100644 --- a/commands/chans.py +++ b/commands/chans.py @@ -6,9 +6,7 @@ class ChansCommand: def __init__(self, *args): self.chans(*args) - def chans( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def chans(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if len(spl) < 2: incUsage("chans") diff --git a/commands/cmd.py b/commands/cmd.py index f2706db..babdb2d 100644 --- a/commands/cmd.py +++ b/commands/cmd.py @@ -6,9 +6,7 @@ class CmdCommand: def __init__(self, *args): self.cmd(*args) - def cmd( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def cmd(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length > 4: if not spl[1].isdigit(): diff --git a/commands/confirm.py b/commands/confirm.py index 53a70a2..86d657c 100644 --- a/commands/confirm.py +++ b/commands/confirm.py @@ -6,9 +6,7 @@ class ConfirmCommand: def __init__(self, *args): self.confirm(*args) - def confirm( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def confirm(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 4: if not spl[1] in main.network.keys(): @@ -21,10 +19,7 @@ class ConfirmCommand: failure("No such relay on %s: %s" % (spl[1], spl[2])) return regproc.confirmAccount(spl[1], int(spl[2]), spl[3]) - success( - "Requested confirmation on %s - %s with token %s" - % (spl[1], spl[2], spl[3]) - ) + success("Requested confirmation on %s - %s with token %s" % (spl[1], spl[2], spl[3])) return else: incUsage("confirm") diff --git a/commands/disable.py b/commands/disable.py index 9a56fb4..9c52234 100644 --- a/commands/disable.py +++ b/commands/disable.py @@ -6,9 +6,7 @@ class DisableCommand: def __init__(self, *args): self.disable(*args) - def disable( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 3: if not spl[1] in main.network.keys(): diff --git a/commands/dist.py b/commands/dist.py index 7e94c4e..2348e29 100644 --- a/commands/dist.py +++ b/commands/dist.py @@ -1,15 +1,12 @@ -from subprocess import PIPE, run - import main +from subprocess import run, PIPE class DistCommand: def __init__(self, *args): self.dist(*args) - def dist( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def dist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if main.config["Dist"]["Enabled"]: rtrn = run([main.config["Dist"]["File"]], shell=True, stdout=PIPE) diff --git a/commands/email.py b/commands/email.py index 3b78931..4817988 100644 --- a/commands/email.py +++ b/commands/email.py @@ -1,15 +1,12 @@ -from yaml import dump - import main +from yaml import dump class EmailCommand: def __init__(self, *args): self.email(*args) - def email( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def email(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 4: if spl[1] == "add": @@ -22,16 +19,10 @@ class EmailCommand: return if not domain in main.irc["_"]["domains"]: main.irc["_"]["domains"].append(domain) - success( - "Successfully added domain %s to default config" - % domain - ) + success("Successfully added domain %s to default config" % domain) main.saveConf("irc") else: - failure( - "Domain already exists in default config: %s" - % domain - ) + failure("Domain already exists in default config: %s" % domain) return elif spl[1] == "del": if not spl[2].isdigit(): @@ -41,16 +32,10 @@ class EmailCommand: if domain in main.irc["_"]["domains"]: main.irc["_"]["domains"].remove(domain) - success( - "Successfully removed domain %s to default config" - % domain - ) + success("Successfully removed domain %s to default config" % domain) main.saveConf("irc") else: - failure( - "Domain does not exist in default config: %s" - % domain - ) + failure("Domain does not exist in default config: %s" % domain) return else: @@ -62,15 +47,10 @@ class EmailCommand: if not spl[3] in main.alias[num]["emails"]: main.alias[num]["emails"].append(spl[3]) main.saveConf("alias") - success( - "Successfully added email %s to alias %i" - % (spl[3], num) - ) + success("Successfully added email %s to alias %i" % (spl[3], num)) return else: - failure( - "Email already exists in alias %i: %s" % (num, spl[3]) - ) + failure("Email already exists in alias %i: %s" % (num, spl[3])) return elif spl[1] == "del": if not num in main.alias.keys(): @@ -79,15 +59,10 @@ class EmailCommand: if spl[3] in main.alias[num]["emails"]: main.alias[num]["emails"].remove(spl[3]) main.saveConf("alias") - success( - "Successfully removed email %s from alias %i" - % (spl[3], num) - ) + success("Successfully removed email %s from alias %i" % (spl[3], num)) return else: - failure( - "Email does not exist in alias %i: %s" % (spl[3], num) - ) + failure("Email does not exist in alias %i: %s" % (spl[3], num)) return elif length == 2: if spl[1] == "list": @@ -99,12 +74,7 @@ class EmailCommand: elif length == 3: if spl[1] == "list": if spl[2] == "domain": - filtered = { - f"{k}:{k2}": v2 - for k, v in main.irc.items() - for k2, v2 in v.items() - if k2 == "domains" - } + filtered = {f"{k}:{k2}":v2 for k,v in main.irc.items() for k2,v2 in v.items() if k2 == "domains"} info(dump(filtered)) return else: diff --git a/commands/enable.py b/commands/enable.py index 1cfb0e4..439b26c 100644 --- a/commands/enable.py +++ b/commands/enable.py @@ -6,9 +6,7 @@ class EnableCommand: def __init__(self, *args): self.enable(*args) - def enable( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def enable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 3: if not spl[1] in main.network.keys(): diff --git a/commands/exec.py b/commands/exec.py index 6f7a924..c2a5598 100644 --- a/commands/exec.py +++ b/commands/exec.py @@ -5,9 +5,7 @@ class ExecCommand: def __init__(self, *args): self.exec(*args) - def exec( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def exec(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length > 1: try: diff --git a/commands/help.py b/commands/help.py index 0ca3ff7..6dcf937 100644 --- a/commands/help.py +++ b/commands/help.py @@ -5,9 +5,7 @@ class HelpCommand: def __init__(self, *args): self.help(*args) - def help( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def help(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: helpMap = [] for i in main.help.keys(): diff --git a/commands/join.py b/commands/join.py index d6147a0..e6cbc20 100644 --- a/commands/join.py +++ b/commands/join.py @@ -6,9 +6,7 @@ class JoinCommand: def __init__(self, *args): self.join(*args) - def join( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def join(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 3: if not spl[1] in main.network.keys(): diff --git a/commands/list.py b/commands/list.py index 7fbc616..217b051 100644 --- a/commands/list.py +++ b/commands/list.py @@ -5,9 +5,7 @@ class ListCommand: def __init__(self, *args): self.list(*args) - def list( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: for i in main.network.keys(): diff --git a/commands/load.py b/commands/load.py index b62da89..31e66f4 100644 --- a/commands/load.py +++ b/commands/load.py @@ -5,9 +5,7 @@ class LoadCommand: def __init__(self, *args): self.load(*args) - def load( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def load(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 2: if spl[1] in main.filemap.keys(): diff --git a/commands/loadmod.py b/commands/loadmod.py index e440b58..2923fd7 100644 --- a/commands/loadmod.py +++ b/commands/loadmod.py @@ -6,9 +6,7 @@ class LoadmodCommand: def __init__(self, *args): self.loadmod(*args) - def loadmod( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def loadmod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 2: rtrn = loadSingle(spl[1]) diff --git a/commands/logout.py b/commands/logout.py index 06bd437..61cb834 100644 --- a/commands/logout.py +++ b/commands/logout.py @@ -5,9 +5,7 @@ class LogoutCommand: def __init__(self, *args): self.logout(*args) - def logout( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def logout(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: obj.authed = False success("Logged out") diff --git a/commands/mod.py b/commands/mod.py index 94d3a7a..10a19e1 100644 --- a/commands/mod.py +++ b/commands/mod.py @@ -1,6 +1,5 @@ -from yaml import dump - import main +from yaml import dump class ModCommand: @@ -8,9 +7,7 @@ class ModCommand: def __init__(self, *args): self.mod(*args) - def mod( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 4: if not spl[1] in main.network.keys(): @@ -24,9 +21,7 @@ class ModCommand: return main.saveConf("network") - success( - "Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]) - ) + success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1])) return # Find a better way to do this # elif length == 6: diff --git a/commands/msg.py b/commands/msg.py index 754176c..d92494a 100644 --- a/commands/msg.py +++ b/commands/msg.py @@ -5,9 +5,7 @@ class MsgCommand: def __init__(self, *args): self.msg(*args) - def msg( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def msg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length >= 5: if not spl[1] in main.network.keys(): @@ -22,10 +20,7 @@ class MsgCommand: if not spl[3] in main.IRCPool[spl[1] + spl[2]].channels: info("Bot not on channel: %s" % spl[3]) main.IRCPool[spl[1] + spl[2]].msg(spl[3], " ".join(spl[4:])) - success( - "Sent %s to %s on relay %s on network %s" - % (" ".join(spl[4:]), spl[3], spl[2], spl[1]) - ) + success("Sent %s to %s on relay %s on network %s" % (" ".join(spl[4:]), spl[3], spl[2], spl[1])) return else: incUsage("msg") diff --git a/commands/network.py b/commands/network.py index 13b23bd..4a6bdf2 100644 --- a/commands/network.py +++ b/commands/network.py @@ -1,18 +1,14 @@ -from string import digits - -from yaml import dump - import main +from yaml import dump from modules.network import Network +from string import digits class NetworkCommand: def __init__(self, *args): self.network(*args) - def network( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def network(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 7: if spl[1] == "add": @@ -32,9 +28,7 @@ class NetworkCommand: failure("Auth must be sasl, ns or none, not %s" % spl[5]) return else: - main.network[spl[2]] = Network( - spl[2], spl[3], int(spl[4]), spl[5].lower(), spl[6].lower() - ) + main.network[spl[2]] = Network(spl[2], spl[3], int(spl[4]), spl[5].lower(), spl[6].lower()) success("Successfully created network: %s" % spl[2]) main.saveConf("network") return diff --git a/commands/part.py b/commands/part.py index 5a2de7e..249c32a 100644 --- a/commands/part.py +++ b/commands/part.py @@ -5,9 +5,7 @@ class PartCommand: def __init__(self, *args): self.part(*args) - def part( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def part(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 4: if not spl[1] in main.network.keys(): diff --git a/commands/pass.py b/commands/pass.py index 4b9e601..e37a51e 100644 --- a/commands/pass.py +++ b/commands/pass.py @@ -5,9 +5,7 @@ class PassCommand: def __init__(self, *args): self.password(*args) - def password( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def password(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: info("You are already authenticated") return diff --git a/commands/pending.py b/commands/pending.py index 5f962dd..b65f2ad 100644 --- a/commands/pending.py +++ b/commands/pending.py @@ -5,19 +5,14 @@ class PendingCommand: def __init__(self, *args): self.pending(*args) - def pending( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def pending(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: results = [] for i in main.network.keys(): for x in main.network[i].relays.keys(): if not main.network[i].relays[x]["registered"]: - results.append( - "%s: confirm %s %s [code]" - % (main.alias[x]["nick"], i, x) - ) + results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], i, x)) info("\n".join(results)) return elif length == 2: @@ -27,10 +22,7 @@ class PendingCommand: results = [] for x in main.network[spl[1]].relays.keys(): if not main.network[spl[1]].relays[x]["registered"]: - results.append( - "%s: confirm %s %s [code]" - % (main.alias[x]["nick"], spl[1], x) - ) + results.append("%s: confirm %s %s [code]" % (main.alias[x]["nick"], spl[1], x)) info("\n".join(results)) return else: diff --git a/commands/recheckauth.py b/commands/recheckauth.py index 6cea741..ab4b5b0 100644 --- a/commands/recheckauth.py +++ b/commands/recheckauth.py @@ -5,9 +5,7 @@ class RecheckauthCommand: def __init__(self, *args): self.recheckauth(*args) - def recheckauth( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def recheckauth(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: results = [] diff --git a/commands/reg.py b/commands/reg.py index fb3794a..41bb5f0 100644 --- a/commands/reg.py +++ b/commands/reg.py @@ -6,9 +6,7 @@ class RegCommand: def __init__(self, *args): self.reg(*args) - def reg( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def reg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 2: if not spl[1] in main.network.keys(): diff --git a/commands/relay.py b/commands/relay.py index 7bfc3d8..34bbd70 100644 --- a/commands/relay.py +++ b/commands/relay.py @@ -1,24 +1,18 @@ -from yaml import dump - import main +from yaml import dump class RelayCommand: def __init__(self, *args): self.relay(*args) - def relay( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 3: if spl[1] == "add": if spl[2] in main.network.keys(): id, alias = main.network[spl[2]].add_relay() - success( - "Successfully created relay %s on network %s with alias %s" - % (str(id), spl[2], alias) - ) + success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias)) main.saveConf("network") return else: @@ -41,10 +35,7 @@ class RelayCommand: failure("Must be a number, not %s" % spl[3]) return id, alias = main.network[spl[2]].add_relay(int(spl[3])) - success( - "Successfully created relay %s on network %s with alias %s" - % (str(id), spl[2], alias) - ) + success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias)) main.saveConf("network") return else: @@ -61,9 +52,7 @@ class RelayCommand: failure("No such relay: %s on network %s" % (spl[3], spl[2])) return main.network[spl[2]].delete_relay(int(spl[3])) - success( - "Successfully deleted relay %s on network %s" % (spl[3], spl[2]) - ) + success("Successfully deleted relay %s on network %s" % (spl[3], spl[2])) main.saveConf("network") return else: diff --git a/commands/save.py b/commands/save.py index 0dd22b6..12624cd 100644 --- a/commands/save.py +++ b/commands/save.py @@ -5,9 +5,7 @@ class SaveCommand: def __init__(self, *args): self.save(*args) - def save( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def save(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 2: if spl[1] in main.filemap.keys(): diff --git a/commands/stats.py b/commands/stats.py index ab6e686..a396f12 100644 --- a/commands/stats.py +++ b/commands/stats.py @@ -1,17 +1,14 @@ -from string import digits - import main import modules.counters as count import modules.userinfo as userinfo +from string import digits class StatsCommand: def __init__(self, *args): self.stats(*args) - def stats( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def stats(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 1: stats = [] diff --git a/commands/swho.py b/commands/swho.py index aa3a78c..18dbc12 100644 --- a/commands/swho.py +++ b/commands/swho.py @@ -5,9 +5,7 @@ class SwhoCommand: def __init__(self, *args): self.swho(*args) - def swho( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def swho(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 2: if not spl[1] in main.network.keys(): diff --git a/commands/token.py b/commands/token.py index 8d95394..7d38eac 100644 --- a/commands/token.py +++ b/commands/token.py @@ -1,17 +1,13 @@ -from uuid import uuid4 - -from yaml import dump - import main +from yaml import dump +from uuid import uuid4 class TokenCommand: def __init__(self, *args): self.token(*args) - def token( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def token(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 2: if spl[1] == "list": diff --git a/commands/users.py b/commands/users.py index 6ba7563..7d80e84 100644 --- a/commands/users.py +++ b/commands/users.py @@ -6,9 +6,7 @@ class UsersCommand: def __init__(self, *args): self.users(*args) - def users( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def users(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if len(spl) < 2: incUsage("users") diff --git a/commands/who.py b/commands/who.py index 8273ef4..e80f488 100644 --- a/commands/who.py +++ b/commands/who.py @@ -6,9 +6,7 @@ class WhoCommand: def __init__(self, *args): self.who(*args) - def who( - self, addr, authed, data, obj, spl, success, failure, info, incUsage, length - ): + def who(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 2: result = userinfo.getWho(spl[1]) diff --git a/core/bot.py b/core/bot.py index 31ff5d5..375703d 100644 --- a/core/bot.py +++ b/core/bot.py @@ -1,38 +1,45 @@ +from twisted.internet.protocol import ReconnectingClientFactory +from twisted.words.protocols.irc import IRCClient +from twisted.internet.defer import Deferred +from twisted.internet.task import LoopingCall +from twisted.internet import reactor, task +from twisted.words.protocols.irc import ( + symbolic_to_numeric, + numeric_to_symbolic, + lowDequote, + IRCBadMessage, +) + import sys +from string import digits +from random import randint from copy import deepcopy from datetime import datetime -from random import randint -from string import digits -from twisted.internet import reactor, task -from twisted.internet.defer import Deferred -from twisted.internet.protocol import ReconnectingClientFactory -from twisted.internet.ssl import DefaultOpenSSLContextFactory -from twisted.internet.task import LoopingCall -from twisted.words.protocols.irc import (IRCBadMessage, IRCClient, lowDequote, - numeric_to_symbolic, - symbolic_to_numeric) +from modules import userinfo +from modules import counters +from modules import monitor +from modules import chankeep +from modules import regproc -import main from core.relay import sendRelayNotification -from modules import chankeep, counters, monitor, regproc, userinfo from utils.dedup import dedup from utils.get import getRelay -from utils.logging.debug import * + +import main from utils.logging.log import * +from utils.logging.debug import * from utils.logging.send import * from utils.parsing import parsen +from twisted.internet.ssl import DefaultOpenSSLContextFactory + def deliverRelayCommands(num, relayCommands, user=None, stage2=None): keyFN = main.certPath + main.config["Key"] certFN = main.certPath + main.config["Certificate"] - contextFactory = DefaultOpenSSLContextFactory( - keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace") - ) - bot = IRCBotFactory( - net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2 - ) + contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")) + bot = IRCBotFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2) host, port = getRelay(num) rct = reactor.connectSSL(host, port, bot, contextFactory) @@ -158,9 +165,7 @@ class IRCBot(IRCClient): self.listAttempted = False # we asked for a list self.listSimple = False # after asking again we got the list, so use the simple # syntax from now on - self.wantList = ( - False # we want to send a LIST, but not all relays are active yet - ) + self.wantList = False # we want to send a LIST, but not all relays are active yet self.chanlimit = 0 self.prefix = {} self.servername = None @@ -192,14 +197,9 @@ class IRCBot(IRCClient): if not i in self.channels: if self.net in main.blacklist.keys(): if i in main.blacklist[self.net]: - debug( - "Not joining blacklisted channel %s on %s - %i" - % (i, self.net, self.num) - ) + debug("Not joining blacklisted channel %s on %s - %i" % (i, self.net, self.num)) continue - debug( - self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds" - ) + debug(self.net, "-", self.num, ": joining", i, "in", sleeptime, "seconds") reactor.callLater(sleeptime, self.join, i) sleeptime += increment if sleeptime == 10: @@ -207,17 +207,11 @@ class IRCBot(IRCClient): increment = 0.7 increment += 0.1 else: - error( - "%s - Cannot join channel we are already on: %s - %i" - % (i, self.net, self.num) - ) + error("%s - Cannot join channel we are already on: %s - %i" % (i, self.net, self.num)) def checkChannels(self): if not chankeep.allRelaysActive(self.net): - debug( - "Skipping channel check as we have inactive relays: %s - %i" - % (self.net, self.num) - ) + debug("Skipping channel check as we have inactive relays: %s - %i" % (self.net, self.num)) return if self.net in main.TempChan.keys(): if self.num in main.TempChan[self.net].keys(): @@ -231,9 +225,7 @@ class IRCBot(IRCClient): cast["ts"] = str(datetime.now().isoformat()) # remove odd stuff - for i in list( - cast.keys() - ): # Make a copy of the .keys() as Python 3 cannot handle iterating over + for i in list(cast.keys()): # Make a copy of the .keys() as Python 3 cannot handle iterating over if cast[i] == "": # a dictionary that changes length with each iteration del cast[i] # remove server stuff @@ -367,9 +359,7 @@ class IRCBot(IRCClient): def irc_ERR_PASSWDMISMATCH(self, prefix, params): log("%s - %i: password mismatch as %s" % (self.net, self.num, self.username)) - sendAll( - "%s - %i: password mismatch as %s" % (self.net, self.num, self.username) - ) + sendAll("%s - %i: password mismatch as %s" % (self.net, self.num, self.username)) def _who(self, channel): d = Deferred() @@ -484,17 +474,12 @@ class IRCBot(IRCClient): debug("Will not send LIST, unauthenticated: %s - %i" % (self.net, self.num)) return if self.listAttempted: - debug( - "List request dropped, already asked for LIST - %s - %i" - % (self.net, self.num) - ) + debug("List request dropped, already asked for LIST - %s - %i" % (self.net, self.num)) return else: self.listAttempted = True if self.listOngoing: - debug( - "LIST request dropped, already ongoing - %s - %i" % (self.net, self.num) - ) + debug("LIST request dropped, already ongoing - %s - %i" % (self.net, self.num)) return else: if nocheck: @@ -519,9 +504,7 @@ class IRCBot(IRCClient): self._tempList[1].append([channel, users, topic]) def irc_RPL_LISTEND(self, prefix, params): - if ( - not len(self._tempList[0]) > 0 - ): # there are no callbacks, can't do anything there + if not len(self._tempList[0]) > 0: # there are no callbacks, can't do anything there debug("We didn't ask for this LIST, discarding") self._tempList[0].clear() self._tempList[1].clear() @@ -546,10 +529,7 @@ class IRCBot(IRCClient): else: if self.listRetried: self.listRetried = False - debug( - "List received after retry - defaulting to simple list syntax: %s - %i" - % (self.net, self.num) - ) + debug("List received after retry - defaulting to simple list syntax: %s - %i" % (self.net, self.num)) self.listSimple = True def got_list(self, listinfo): @@ -563,10 +543,7 @@ class IRCBot(IRCClient): name = self.net + "1" if main.IRCPool[name].wantList == True: main.IRCPool[name].list(nocheck=True) - debug( - "Asking for a list for %s after final relay %i connected" - % (self.net, self.num) - ) + debug("Asking for a list for %s after final relay %i connected" % (self.net, self.num)) if self.num == 1: # Only one instance should do a list if self.chanlimit: if allRelays: @@ -583,9 +560,7 @@ class IRCBot(IRCClient): ]: # TODO: add check for register request sent, only send it once if main.config["AutoReg"]: if not self.authenticated: - self._regAttempt = reactor.callLater( - 5, regproc.registerAccount, self.net, self.num - ) + self._regAttempt = reactor.callLater(5, regproc.registerAccount, self.net, self.num) # regproc.registerAccount(self.net, self.num) try: self.chanlimit = int(chanlimit) @@ -593,9 +568,7 @@ class IRCBot(IRCClient): warn("Invalid chanlimit: %s" % i) if self.chanlimit == 0: self.chanlimit = 200 # don't take the piss if it's not limited - if not regproc.needToRegister( - self.net - ): # if we need to register, only recheck on auth confirmation + if not regproc.needToRegister(self.net): # if we need to register, only recheck on auth confirmation self.recheckList() def seed_prefix(self, prefix): @@ -696,9 +669,7 @@ class IRCBot(IRCClient): if negativepass == True: if self._negativePass == None: self._negativePass = True - debug( - "Positive registration check - %s - %i" % (self.net, self.num) - ) + debug("Positive registration check - %s - %i" % (self.net, self.num)) if sinst["ping"]: debug("Sending ping - %s - %i" % (self.net, self.num)) self.msg(sinst["entity"], sinst["pingmsg"]) @@ -754,9 +725,7 @@ class IRCBot(IRCClient): lc = self._getWho[channel] lc.stop() del self._getWho[channel] - userinfo.delChannels( - self.net, [channel] - ) # < we do not need to deduplicate this + userinfo.delChannels(self.net, [channel]) # < we do not need to deduplicate this # log("Can no longer cover %s, removing records" % channel)# as it will only be matched once -- # other bots have different nicknames so diff --git a/core/logstash.py b/core/logstash.py index 66cded9..17e8dfd 100644 --- a/core/logstash.py +++ b/core/logstash.py @@ -1,8 +1,7 @@ -import logging -from json import dumps, loads - import logstash +import logging +from json import dumps, loads import main from utils.logging.log import * diff --git a/core/parser.py b/core/parser.py index 8d7c635..1eb34c5 100644 --- a/core/parser.py +++ b/core/parser.py @@ -24,9 +24,7 @@ def parseCommand(addr, authed, data): failure("No text was sent") return if spl[0] in main.CommandMap.keys(): - main.CommandMap[spl[0]]( - addr, authed, data, obj, spl, success, failure, info, incUsage, length - ) + main.CommandMap[spl[0]](addr, authed, data, obj, spl, success, failure, info, incUsage, length) return incUsage(None) return diff --git a/core/relay.py b/core/relay.py index 7f63209..66a9830 100644 --- a/core/relay.py +++ b/core/relay.py @@ -1,7 +1,6 @@ -from copy import deepcopy +from twisted.internet.protocol import Protocol, Factory, ClientFactory from json import dumps, loads - -from twisted.internet.protocol import ClientFactory, Factory, Protocol +from copy import deepcopy import main from utils.logging.log import * @@ -115,13 +114,8 @@ class Relay(Protocol): def handleHello(self, parsed): if parsed["key"] in main.tokens.keys(): - if ( - parsed["hello"] == main.tokens[parsed["key"]]["hello"] - and main.tokens[parsed["key"]]["usage"] == "relay" - ): - self.sendMsg( - {"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]} - ) + if parsed["hello"] == main.tokens[parsed["key"]]["hello"] and main.tokens[parsed["key"]]["usage"] == "relay": + self.sendMsg({"type": "hello", "hello": main.tokens[parsed["key"]]["counter"]}) self.authed = True else: self.transport.loseConnection() @@ -136,10 +130,7 @@ class Relay(Protocol): def connectionLost(self, reason): self.authed = False - log( - "Relay connection lost from %s:%s -- %s" - % (self.addr.host, self.addr.port, reason.getErrorMessage()) - ) + log("Relay connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage())) if self.addr in main.relayConnections.keys(): del main.relayConnections[self.addr] else: diff --git a/core/server.py b/core/server.py index 6b7a25d..94af7a0 100644 --- a/core/server.py +++ b/core/server.py @@ -1,9 +1,9 @@ -from twisted.internet.protocol import ClientFactory, Factory, Protocol - +from twisted.internet.protocol import Protocol, Factory, ClientFactory import main -from core.parser import parseCommand from utils.logging.log import * +from core.parser import parseCommand + class Server(Protocol): def __init__(self, addr): @@ -34,10 +34,7 @@ class Server(Protocol): def connectionLost(self, reason): self.authed = False - log( - "Connection lost from %s:%s -- %s" - % (self.addr.host, self.addr.port, reason.getErrorMessage()) - ) + log("Connection lost from %s:%s -- %s" % (self.addr.host, self.addr.port, reason.getErrorMessage())) if self.addr in main.connections.keys(): del main.connections[self.addr] else: diff --git a/main.py b/main.py index 103c15a..473fd3e 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,8 @@ import json import pickle -from os import urandom -from string import digits - from redis import StrictRedis +from string import digits +from os import urandom from utils.logging.log import * @@ -107,9 +106,5 @@ def initConf(): def initMain(): global r, g initConf() - r = StrictRedis( - unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"] - ) # Ephemeral - flushed on quit - g = StrictRedis( - unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"] - ) # Persistent + r = StrictRedis(unix_socket_path=config["RedisSocket"], db=config["RedisDBEphemeral"]) # Ephemeral - flushed on quit + g = StrictRedis(unix_socket_path=config["RedisSocket"], db=config["RedisDBPersistent"]) # Persistent diff --git a/modules/alias.py b/modules/alias.py index 6417e29..1961ec6 100644 --- a/modules/alias.py +++ b/modules/alias.py @@ -1,8 +1,7 @@ +import main import random import re -import main - def generate_password(): return "".join([chr(random.randint(0, 74) + 48) for i in range(32)]) diff --git a/modules/chankeep.py b/modules/chankeep.py index fdbe974..ec43b0f 100644 --- a/modules/chankeep.py +++ b/modules/chankeep.py @@ -1,12 +1,10 @@ +import main +from utils.logging.log import * +from utils.logging.debug import * from copy import deepcopy from math import ceil - -from twisted.internet.threads import deferToThread - -import main import modules.provision -from utils.logging.debug import * -from utils.logging.log import * +from twisted.internet.threads import deferToThread def allRelaysActive(net): @@ -48,10 +46,7 @@ def emptyChanAllocate(net, flist, relay, new): if toalloc > sum(chanfree[0].values()): correction = round(toalloc - sum(chanfree[0].values()) / chanfree[1]) # print("correction", correction) - warn( - "Ran out of channel spaces, provisioning additional %i relays for %s" - % (correction, net) - ) + warn("Ran out of channel spaces, provisioning additional %i relays for %s" % (correction, net)) # newNums = modules.provision.provisionMultipleRelays(net, correction) return False for i in chanfree[0].keys(): @@ -104,18 +99,12 @@ def keepChannels(net, listinfo, mean, sigrelay, relay): listinfo = minifyChans(net, listinfo) if not listinfo: return - if ( - relay <= main.config["ChanKeep"]["SigSwitch"] - ): # we can cover all of the channels + if relay <= main.config["ChanKeep"]["SigSwitch"]: # we can cover all of the channels coverAll = True - elif ( - relay > main.config["ChanKeep"]["SigSwitch"] - ): # we cannot cover all of the channels + elif relay > main.config["ChanKeep"]["SigSwitch"]: # we cannot cover all of the channels coverAll = False if not sigrelay <= main.config["ChanKeep"]["MaxRelay"]: - error( - "Network %s is too big to cover: %i relays required" % (net, sigrelay) - ) + error("Network %s is too big to cover: %i relays required" % (net, sigrelay)) return if coverAll: needed = relay - len(main.network[net].relays.keys()) diff --git a/modules/counters.py b/modules/counters.py index 5d51a52..a088cc3 100644 --- a/modules/counters.py +++ b/modules/counters.py @@ -1,6 +1,5 @@ -from twisted.internet.task import LoopingCall - import main +from twisted.internet.task import LoopingCall def event(name, eventType): diff --git a/modules/monitor.py b/modules/monitor.py index e1c16a7..f174a80 100644 --- a/modules/monitor.py +++ b/modules/monitor.py @@ -2,9 +2,10 @@ from copy import deepcopy from json import dumps import main -from core.logstash import sendLogstashNotification from core.relay import sendRelayNotification -from modules import regproc, userinfo +from core.logstash import sendLogstashNotification +from modules import userinfo +from modules import regproc from utils.dedup import dedup order = [ @@ -67,9 +68,7 @@ def parsemeta(numName, c): ) -def event( - numName, c -): # yes I'm using a short variable because otherwise it goes off the screen +def event(numName, c): # yes I'm using a short variable because otherwise it goes off the screen if dedup(numName, c): return diff --git a/modules/network.py b/modules/network.py index 5652120..21f1753 100644 --- a/modules/network.py +++ b/modules/network.py @@ -1,15 +1,14 @@ -import json - -from twisted.internet import reactor from twisted.internet.ssl import DefaultOpenSSLContextFactory +import json -import main -from core.bot import IRCBot, IRCBotFactory from modules import alias from modules.chankeep import nukeNetwork from modules.regproc import needToRegister -from utils.get import getRelay +from twisted.internet import reactor +from core.bot import IRCBot, IRCBotFactory +import main from utils.logging.log import * +from utils.get import getRelay class Network: @@ -78,9 +77,7 @@ class Network: # e.g. freenode1 for the first relay on freenode network keyFN = main.certPath + main.config["Key"] certFN = main.certPath + main.config["Certificate"] - contextFactory = DefaultOpenSSLContextFactory( - keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace") - ) + contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")) bot = IRCBotFactory(self.net, num) # host, port = self.relays[num]["host"], self.relays[num]["port"] host, port = getRelay(num) diff --git a/modules/provision.py b/modules/provision.py index 9e93236..1f17a20 100644 --- a/modules/provision.py +++ b/modules/provision.py @@ -1,25 +1,11 @@ -from twisted.internet import reactor - import main -import modules.regproc from core.bot import deliverRelayCommands from utils.logging.log import * +from twisted.internet import reactor +import modules.regproc -def provisionUserNetworkData( - num, - nick, - altnick, - ident, - realname, - emails, - network, - host, - port, - security, - auth, - password, -): +def provisionUserNetworkData(num, nick, altnick, ident, realname, emails, network, host, port, security, auth, password): print("nick", nick) print("altnick", altnick) print("emails", emails) @@ -30,25 +16,17 @@ def provisionUserNetworkData( stage2commands["status"] = [] commands["controlpanel"] = [] user = nick.lower() - commands["controlpanel"].append( - "AddUser %s %s" % (user, main.config["Relay"]["Password"]) - ) + commands["controlpanel"].append("AddUser %s %s" % (user, main.config["Relay"]["Password"])) commands["controlpanel"].append("AddNetwork %s %s" % (user, network)) commands["controlpanel"].append("Set Nick %s %s" % (user, nick)) commands["controlpanel"].append("Set Altnick %s %s" % (user, altnick)) commands["controlpanel"].append("Set Ident %s %s" % (user, ident)) commands["controlpanel"].append("Set RealName %s %s" % (user, realname)) if security == "ssl": - commands["controlpanel"].append( - "SetNetwork TrustAllCerts %s %s true" % (user, network) - ) # Don't judge me - commands["controlpanel"].append( - "AddServer %s %s %s +%s" % (user, network, host, port) - ) + commands["controlpanel"].append("SetNetwork TrustAllCerts %s %s true" % (user, network)) # Don't judge me + commands["controlpanel"].append("AddServer %s %s %s +%s" % (user, network, host, port)) elif security == "plain": - commands["controlpanel"].append( - "AddServer %s %s %s %s" % (user, network, host, port) - ) + commands["controlpanel"].append("AddServer %s %s %s %s" % (user, network, host, port)) if not main.config["ConnectOnCreate"]: stage2commands["status"].append("Disconnect") if main.config["Toggles"]["CycleChans"]: diff --git a/modules/regproc.py b/modules/regproc.py index 353c5e6..ce0e5a2 100644 --- a/modules/regproc.py +++ b/modules/regproc.py @@ -1,11 +1,9 @@ -from copy import deepcopy -from random import choice - import main from modules import provision -from utils.logging.debug import * from utils.logging.log import * - +from utils.logging.debug import * +from copy import deepcopy +from random import choice def needToRegister(net): # Check if the network does not support authentication @@ -53,7 +51,7 @@ def substitute(net, num, token=None): nickname = alias["nick"] username = nickname + "/" + net password = main.network[net].aliases[num]["password"] - # inst["email"] = inst["email"].replace("{nickname}", nickname) + #inst["email"] = inst["email"].replace("{nickname}", nickname) for i in inst.keys(): if not isinstance(inst[i], str): continue @@ -114,12 +112,8 @@ def enableAuthentication(net, num): auth = obj.auth password = obj.aliases[num]["password"] uname = main.alias[num]["nick"] + "/" + net - provision.provisionAuthenticationData( - num, nick, net, security, auth, password - ) # Set up for auth - main.IRCPool[net + str(num)].msg( - main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump" - ) + provision.provisionAuthenticationData(num, nick, net, security, auth, password) # Set up for auth + main.IRCPool[net + str(num)].msg(main.config["Tweaks"]["ZNC"]["Prefix"] + "status", "Jump") if selectInst(net)["check"] == False: confirmRegistration(net, num) @@ -135,14 +129,10 @@ def registerTest(c): if not main.IRCPool[name]._negativePass == True: if c["type"] == "query" and c["nick"] == sinst["entity"]: if sinst["checknegativemsg"] in c["msg"]: - confirmRegistration( - c["net"], c["num"], negativepass=False - ) # Not passed negative check, report back + confirmRegistration(c["net"], c["num"], negativepass=False) # Not passed negative check, report back return if sinst["checkendnegative"] in c["msg"]: - confirmRegistration( - c["net"], c["num"], negativepass=True - ) # Passed the negative check, report back + confirmRegistration(c["net"], c["num"], negativepass=True) # Passed the negative check, report back return if sinst["ping"]: if sinst["checkmsg2"] in c["msg"] and c["nick"] == sinst["entity"]: diff --git a/modules/userinfo.py b/modules/userinfo.py index 94c0833..1722cb3 100644 --- a/modules/userinfo.py +++ b/modules/userinfo.py @@ -1,10 +1,9 @@ -from string import digits - from twisted.internet.threads import deferToThread +from string import digits import main -from utils.logging.debug import debug, trace from utils.logging.log import * +from utils.logging.debug import debug, trace from utils.parsing import parsen @@ -146,9 +145,7 @@ def delUser(name, channel, nick, user): p.srem(namespace, nick) if channels == {channel.encode()}: # can we only see them on this channel? p.delete(chanspace) # remove channel tracking entry - p.hdel( - "live.prefix." + name + "." + channel, nick - ) # remove prefix tracking entry + p.hdel("live.prefix." + name + "." + channel, nick) # remove prefix tracking entry p.hdel(mapspace, nick) # remove nick mapping entry if user: p.srem(gnamespace, user) # remove global userinfo entry @@ -173,10 +170,7 @@ def getUserByNick(name, nick): if main.r.hexists(mapspace, nick): return main.r.hget(mapspace, nick) else: - warn( - "Entry doesn't exist: %s on %s - attempting auxiliary lookup" - % (nick, mapspace) - ) + warn("Entry doesn't exist: %s on %s - attempting auxiliary lookup" % (nick, mapspace)) # return False # legacy code below - remove when map is reliable usermatch = main.r.sscan(gnamespace, match=escape(nick) + "!*", count=999999999) @@ -206,18 +200,10 @@ def renameUser(name, oldnick, olduser, newnick, newuser): p.sadd("live.who." + name + "." + i, newnick) p.hdel(mapspace, oldnick) p.hset(mapspace, newnick, newuser) - if main.r.exists( - "live.prefix." + name + "." + i - ): # if there's a prefix entry for the channel - if main.r.hexists( - "live.prefix." + name + "." + i, oldnick - ): # if the old nick is in it - mode = main.r.hget( - "live.prefix." + name + "." + i, oldnick - ) # retrieve old modes - p.hset( - "live.prefix." + name + "." + i, newnick, mode - ) # set old modes to new nickname + if main.r.exists("live.prefix." + name + "." + i): # if there's a prefix entry for the channel + if main.r.hexists("live.prefix." + name + "." + i, oldnick): # if the old nick is in it + mode = main.r.hget("live.prefix." + name + "." + i, oldnick) # retrieve old modes + p.hset("live.prefix." + name + "." + i, newnick, mode) # set old modes to new nickname if main.r.exists(chanspace): p.rename(chanspace, newchanspace) else: diff --git a/threshold b/threshold index b7c6f78..dc186b4 100755 --- a/threshold +++ b/threshold @@ -1,14 +1,14 @@ #!/usr/bin/env python +from twisted.internet import reactor +from twisted.internet.ssl import DefaultOpenSSLContextFactory import sys -from codecs import getwriter # fix printing odd shit to the terminal -from signal import SIGINT, signal +from signal import signal, SIGINT + # from twisted.python import log # from sys import stdout # log.startLogging(stdout) -from sys import stderr, stdout # Import again because we want to override - -from twisted.internet import reactor -from twisted.internet.ssl import DefaultOpenSSLContextFactory +from sys import stdout, stderr # Import again because we want to override +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 @@ -23,11 +23,11 @@ if "--debug" in sys.argv: # yes really main.config["Debug"] = True if "--trace" in sys.argv: main.config["Trace"] = True -import modules.counters -from core.relay import Relay, RelayFactory -from core.server import Server, ServerFactory -from utils.loaders.command_loader import loadCommands from utils.logging.log import * +from utils.loaders.command_loader import loadCommands +from core.server import Server, ServerFactory +from core.relay import Relay, RelayFactory +import modules.counters loadCommands() import core.logstash @@ -46,20 +46,14 @@ if __name__ == "__main__": ), interface=main.config["Listener"]["Address"], ) - log( - "Threshold running with SSL on %s:%s" - % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]) - ) + log("Threshold running with SSL on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"])) else: reactor.listenTCP( main.config["Listener"]["Port"], listener, interface=main.config["Listener"]["Address"], ) - log( - "Threshold running on %s:%s" - % (main.config["Listener"]["Address"], main.config["Listener"]["Port"]) - ) + log("Threshold running on %s:%s" % (main.config["Listener"]["Address"], main.config["Listener"]["Port"])) if main.config["RelayAPI"]["Enabled"]: relay = RelayFactory() if main.config["RelayAPI"]["UseSSL"] == True: @@ -82,10 +76,7 @@ if __name__ == "__main__": relay, interface=main.config["RelayAPI"]["Address"], ) - log( - "Threshold relay running on %s:%s" - % (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"]) - ) + log("Threshold relay running on %s:%s" % (main.config["RelayAPI"]["Address"], main.config["RelayAPI"]["Port"])) for net in main.network.keys(): main.network[net].start_bots() modules.counters.setupCounterLoop() diff --git a/utils/cleanup.py b/utils/cleanup.py index 51eaa05..83ed661 100644 --- a/utils/cleanup.py +++ b/utils/cleanup.py @@ -1,10 +1,8 @@ -import sys - -from twisted.internet import reactor - import main +from twisted.internet import reactor from utils.logging.debug import debug from utils.logging.log import * +import sys def handler(sig, frame): diff --git a/utils/dedup.py b/utils/dedup.py index 89e4bee..dc8d4c3 100644 --- a/utils/dedup.py +++ b/utils/dedup.py @@ -1,9 +1,7 @@ -from copy import deepcopy from datetime import datetime -from json import dumps - from csiphash import siphash24 - +from copy import deepcopy +from json import dumps import main from utils.logging.debug import debug @@ -12,24 +10,16 @@ def dedup(numName, b): c = deepcopy(b) if "ts" in c.keys(): del c["ts"] - c["approxtime"] = str(datetime.utcnow().timestamp())[ - : main.config["Tweaks"]["DedupPrecision"] - ] + 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 - ) + isDuplicate = any(castHash in main.lastEvents[x] for x in main.lastEvents.keys() if not x == numName) if isDuplicate: debug("Duplicate: %s" % (c)) return True if numName in main.lastEvents.keys(): main.lastEvents[numName].insert(0, castHash) - main.lastEvents[numName] = main.lastEvents[numName][ - 0 : main.config["Tweaks"]["MaxHash"] - ] + main.lastEvents[numName] = main.lastEvents[numName][0 : main.config["Tweaks"]["MaxHash"]] else: main.lastEvents[numName] = [castHash] return False diff --git a/utils/loaders/command_loader.py b/utils/loaders/command_loader.py index 19517ec..9c4095b 100644 --- a/utils/loaders/command_loader.py +++ b/utils/loaders/command_loader.py @@ -1,9 +1,10 @@ from os import listdir -import commands -from main import CommandMap from utils.logging.debug import debug from utils.logging.log import * +import commands + +from main import CommandMap def loadCommands(allowDup=False): @@ -14,15 +15,11 @@ def loadCommands(allowDup=False): try: module = __import__("commands.%s" % commandName) if not commandName in CommandMap: - CommandMap[commandName] = getattr( - getattr(module, commandName), className - ) + CommandMap[commandName] = getattr(getattr(module, commandName), className) debug("Registered command: %s" % commandName) else: if allowDup: - CommandMap[commandName] = getattr( - getattr(module, commandName), className - ) + CommandMap[commandName] = getattr(getattr(module, commandName), className) debug("Registered command: %s" % commandName) error("Duplicate command: %s" % (commandName)) diff --git a/utils/loaders/single_loader.py b/utils/loaders/single_loader.py index 64b0618..f5219ac 100644 --- a/utils/loaders/single_loader.py +++ b/utils/loaders/single_loader.py @@ -1,11 +1,12 @@ -import sys -from importlib import reload from os import listdir +from importlib import reload +import sys -import commands -from main import CommandMap from utils.logging.debug import debug from utils.logging.log import * +import commands + +from main import CommandMap def loadSingle(commandName): @@ -14,9 +15,7 @@ def loadSingle(commandName): try: if commandName in CommandMap.keys(): reload(sys.modules["commands." + commandName]) - CommandMap[commandName] = getattr( - sys.modules["commands." + commandName], className - ) + CommandMap[commandName] = getattr(sys.modules["commands." + commandName], className) debug("Reloaded command: %s" % commandName) return "RELOAD" module = __import__("commands.%s" % commandName) diff --git a/utils/logging/debug.py b/utils/logging/debug.py index 0c73174..80651f7 100644 --- a/utils/logging/debug.py +++ b/utils/logging/debug.py @@ -1,6 +1,5 @@ import main - # we need a seperate module to log.py, as log.py is imported by main.py, and we need to access main # to read the setting def debug(*data):