Reformat project

This commit is contained in:
2022-07-21 13:39:59 +01:00
parent 4669096fcb
commit da678617d8
57 changed files with 523 additions and 218 deletions

View File

@@ -6,7 +6,9 @@ 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():

View File

@@ -1,5 +1,6 @@
import main
from yaml import dump
import main
from modules import alias
@@ -7,7 +8,9 @@ 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))

View File

@@ -6,7 +6,9 @@ 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():
@@ -15,7 +17,10 @@ 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:

View File

@@ -6,7 +6,9 @@ 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 = []
@@ -20,7 +22,8 @@ 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")
@@ -33,7 +36,10 @@ 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:

View File

@@ -5,7 +5,9 @@ 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 = []
@@ -13,7 +15,9 @@ 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:
@@ -27,7 +31,9 @@ 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:

View File

@@ -6,7 +6,9 @@ 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():
@@ -14,9 +16,15 @@ 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:
@@ -27,9 +35,15 @@ 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:

View File

@@ -1,12 +1,15 @@
import main
from yaml import dump
import main
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))

View File

@@ -6,7 +6,9 @@ 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")

View File

@@ -6,7 +6,9 @@ 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():

View File

@@ -6,7 +6,9 @@ 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():
@@ -19,7 +21,10 @@ 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")

View File

@@ -6,7 +6,9 @@ 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():

View File

@@ -1,12 +1,15 @@
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)

View File

@@ -1,12 +1,15 @@
import main
from yaml import dump
import main
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":
@@ -19,10 +22,16 @@ 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():
@@ -32,10 +41,16 @@ 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:
@@ -47,10 +62,15 @@ 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():
@@ -59,10 +79,15 @@ 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":
@@ -74,7 +99,12 @@ 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:

View File

@@ -6,7 +6,9 @@ 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():

View File

@@ -5,7 +5,9 @@ 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:

View File

@@ -5,7 +5,9 @@ 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():

View File

@@ -6,7 +6,9 @@ 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():

View File

@@ -5,7 +5,9 @@ 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():

View File

@@ -5,7 +5,9 @@ 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():

View File

@@ -6,7 +6,9 @@ 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])

View File

@@ -5,7 +5,9 @@ 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")

View File

@@ -1,13 +1,16 @@
import main
from yaml import dump
import main
class ModCommand:
# This could be greatly improved, but not really important right now
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():
@@ -21,7 +24,9 @@ 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:

View File

@@ -5,7 +5,9 @@ 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():
@@ -20,7 +22,10 @@ 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")

View File

@@ -1,14 +1,18 @@
import main
from yaml import dump
from modules.network import Network
from string import digits
from yaml import dump
import main
from modules.network import Network
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":
@@ -28,7 +32,9 @@ 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

View File

@@ -5,7 +5,9 @@ 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():

View File

@@ -5,7 +5,9 @@ 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

View File

@@ -5,14 +5,19 @@ 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:
@@ -22,7 +27,10 @@ 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:

View File

@@ -5,7 +5,9 @@ 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 = []

View File

@@ -6,7 +6,9 @@ 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():

View File

@@ -1,18 +1,24 @@
import main
from yaml import dump
import main
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:
@@ -35,7 +41,10 @@ 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:
@@ -52,7 +61,9 @@ 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:

View File

@@ -5,7 +5,9 @@ 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():

View File

@@ -1,14 +1,17 @@
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 = []

View File

@@ -5,7 +5,9 @@ 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():

View File

@@ -1,13 +1,17 @@
import main
from yaml import dump
from uuid import uuid4
from yaml import dump
import main
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":

View File

@@ -6,7 +6,9 @@ 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")

View File

@@ -6,7 +6,9 @@ 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])