Renovate the module system and implement adding and resuming pool instances using the new relay/alias/network system
This commit is contained in:
111
commands/add.py
111
commands/add.py
@@ -1,111 +0,0 @@
|
||||
import main
|
||||
import core.helper as helper
|
||||
|
||||
class Add:
|
||||
def __init__(self, register):
|
||||
register("add", self.add)
|
||||
|
||||
def add(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length > 6:
|
||||
failure("Too many arguments")
|
||||
return
|
||||
|
||||
if length > 1:
|
||||
name = spl[1]
|
||||
if name.isdigit():
|
||||
failure("Network name is all numbers. This will break things.")
|
||||
return
|
||||
else:
|
||||
incUsage("add")
|
||||
return
|
||||
if length > 2:
|
||||
host = spl[2]
|
||||
if length > 3:
|
||||
port = spl[3]
|
||||
if length > 4:
|
||||
protocol = spl[4]
|
||||
if length > 5:
|
||||
nickname = spl[5]
|
||||
|
||||
toFail = False
|
||||
if length < 6:
|
||||
if main.config["Default"]["nickname"] == None:
|
||||
failure("Choose a nickname, or configure one in defaults")
|
||||
toFail = True
|
||||
else:
|
||||
nickname = main.config["Default"]["nickname"]
|
||||
|
||||
if length < 5:
|
||||
if main.config["Default"]["protocol"] == None:
|
||||
failure("Choose a protocol, or configure one in defaults")
|
||||
toFail = True
|
||||
else:
|
||||
protocol = main.config["Default"]["protocol"]
|
||||
|
||||
if length < 4:
|
||||
if main.config["Default"]["port"] == None:
|
||||
failure("Choose a port, or configure one in defaults")
|
||||
toFail = True
|
||||
else:
|
||||
port = main.config["Default"]["port"]
|
||||
|
||||
if length < 3:
|
||||
if main.config["Default"]["host"] == None:
|
||||
failure("Choose a host, or configure one in defaults")
|
||||
toFail = True
|
||||
else:
|
||||
host = main.config["Default"]["host"]
|
||||
if toFail:
|
||||
failure("Stopping due to previous error(s)")
|
||||
return
|
||||
|
||||
if length < 2:
|
||||
incUsage("add")
|
||||
return
|
||||
|
||||
if name in main.pool.keys():
|
||||
failure("Name already exists: %s" % name)
|
||||
return
|
||||
|
||||
protocol = protocol.lower()
|
||||
|
||||
if not protocol in ["ssl", "plain"]:
|
||||
failure("Protocol must be ssl or plain, not %s" % protocol)
|
||||
return
|
||||
|
||||
if not port.isdigit():
|
||||
failure("Port must be an integer, not %s" % port)
|
||||
return
|
||||
|
||||
main.pool[name] = { "host": host,
|
||||
"port": port,
|
||||
"protocol": protocol,
|
||||
"bind": main.config["Default"]["bind"],
|
||||
"timeout": main.config["Default"]["timeout"],
|
||||
"maxdelay": main.config["Default"]["maxdelay"],
|
||||
"initialdelay": main.config["Default"]["initialdelay"],
|
||||
"factor": main.config["Default"]["factor"],
|
||||
"jitter": main.config["Default"]["jitter"],
|
||||
"nickname": nickname,
|
||||
"username": main.config["Default"]["username"],
|
||||
"realname": main.config["Default"]["realname"],
|
||||
"userinfo": main.config["Default"]["userinfo"],
|
||||
"finger": main.config["Default"]["finger"],
|
||||
"version": main.config["Default"]["version"],
|
||||
"source": main.config["Default"]["source"],
|
||||
"autojoin": main.config["Default"]["autojoin"],
|
||||
"authtype": main.config["Default"]["authtype"],
|
||||
"password": main.config["Default"]["password"],
|
||||
"authentity": main.config["Default"]["authentity"],
|
||||
"key": main.config["Default"]["key"],
|
||||
"certificate": main.config["Default"]["certificate"],
|
||||
"enabled": main.config["ConnectOnCreate"],
|
||||
}
|
||||
if main.config["ConnectOnCreate"] == True:
|
||||
helper.addBot(name)
|
||||
success("Successfully created bot")
|
||||
main.saveConf("pool")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
from yaml import dump
|
||||
|
||||
class Alias:
|
||||
def __init__(self, register):
|
||||
register("alias", self.alias)
|
||||
def __init__(self, *args):
|
||||
self.alias(*args)
|
||||
|
||||
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
import modules.userinfo as userinfo
|
||||
|
||||
class Chans:
|
||||
def __init__(self, register):
|
||||
register("chans", self.chans)
|
||||
def __init__(self, *args):
|
||||
self.chans(*args)
|
||||
|
||||
def chans(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
24
commands/cmd.py
Normal file
24
commands/cmd.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import main
|
||||
from core.bot import deliverRelayCommands
|
||||
|
||||
class Cmd:
|
||||
def __init__(self, *args):
|
||||
self.cmd(*args)
|
||||
|
||||
def cmd(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length > 4:
|
||||
if not spl[1] in main.relay.keys():
|
||||
failure("No such relay: %s" % spl[1])
|
||||
return
|
||||
|
||||
commands = {spl[3]: [" ".join(spl[4:])]}
|
||||
print(" ".join(spl[4:]))
|
||||
success("Sending commands to relay %s as user %s" % (spl[1], spl[2]))
|
||||
deliverRelayCommands(spl[1], commands, user=spl[2])
|
||||
return
|
||||
else:
|
||||
incUsage("cmd")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Delete:
|
||||
def __init__(self, register):
|
||||
register("del", self.delete)
|
||||
class Del:
|
||||
def __init__(self, *args):
|
||||
self.delete(*args)
|
||||
|
||||
def delete(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
@@ -1,8 +1,9 @@
|
||||
import main
|
||||
from core.bot import deliverRelayCommands
|
||||
|
||||
class Disable:
|
||||
def __init__(self, register):
|
||||
register("disable", self.disable)
|
||||
def __init__(self, *args):
|
||||
self.disable(*args)
|
||||
|
||||
def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
@@ -11,6 +12,11 @@ class Disable:
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
return
|
||||
main.pool[spl[1]]["enabled"] = False
|
||||
user = main.pool[spl[1]]["alias"]
|
||||
network = main.pool[spl[1]]["network"]
|
||||
relay = main.pool[spl[1]]["relay"]
|
||||
commands = {"status": ["Disconnect"]}
|
||||
deliverRelayCommands(relay, commands, user=user+"/"+network)
|
||||
main.saveConf("pool")
|
||||
if spl[1] in main.ReactorPool.keys():
|
||||
if spl[1] in main.FactoryPool.keys():
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
from subprocess import run, PIPE
|
||||
|
||||
class Dist:
|
||||
def __init__(self, register):
|
||||
register("dist", self.dist)
|
||||
def __init__(self, *args):
|
||||
self.dist(*args)
|
||||
|
||||
def dist(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import main
|
||||
import core.helper as helper
|
||||
from core.helper import startBot
|
||||
from core.bot import deliverRelayCommands
|
||||
|
||||
class Enable:
|
||||
def __init__(self, register):
|
||||
register("enable", self.enable)
|
||||
def __init__(self, *args):
|
||||
self.enable(*args)
|
||||
|
||||
def enable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
@@ -12,9 +13,14 @@ class Enable:
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
return
|
||||
main.pool[spl[1]]["enabled"] = True
|
||||
user = main.pool[spl[1]]["alias"]
|
||||
network = main.pool[spl[1]]["network"]
|
||||
relay = main.pool[spl[1]]["relay"]
|
||||
commands = {"status": ["Connect"]}
|
||||
deliverRelayCommands(relay, commands, user=user+"/"+network)
|
||||
main.saveConf("pool")
|
||||
if not spl[1] in main.IRCPool.keys():
|
||||
helper.addBot(spl[1])
|
||||
startBot(spl[1])
|
||||
else:
|
||||
pass
|
||||
success("Successfully enabled bot %s" % spl[1])
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Get:
|
||||
def __init__(self, register):
|
||||
register("get", self.get)
|
||||
def __init__(self, *args):
|
||||
self.get(*args)
|
||||
|
||||
def get(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Help:
|
||||
def __init__(self, register):
|
||||
register("help", self.help)
|
||||
def __init__(self, *args):
|
||||
self.help(*args)
|
||||
|
||||
def help(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Join:
|
||||
def __init__(self, register):
|
||||
register("join", self.join)
|
||||
def __init__(self, *args):
|
||||
self.join(*args)
|
||||
|
||||
def join(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
import modules.keyword as keyword
|
||||
|
||||
class Key:
|
||||
def __init__(self, register):
|
||||
register("key", self.key)
|
||||
def __init__(self, *args):
|
||||
self.key(*args)
|
||||
|
||||
def key(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
from yaml import dump
|
||||
|
||||
class List:
|
||||
def __init__(self, register):
|
||||
register("list", self.list)
|
||||
def __init__(self, *args):
|
||||
self.list(*args)
|
||||
|
||||
def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Load:
|
||||
def __init__(self, register):
|
||||
register("load", self.load)
|
||||
def __init__(self, *args):
|
||||
self.list(*args)
|
||||
|
||||
def load(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,15 +2,18 @@ import main
|
||||
from utils.loaders.single_loader import loadSingle
|
||||
|
||||
class Loadmod:
|
||||
def __init__(self, register):
|
||||
register("loadmod", self.loadmod)
|
||||
def __init__(self, *args):
|
||||
self.loadmod(*args)
|
||||
|
||||
def loadmod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 2:
|
||||
rtrn = loadSingle(spl[1], main.register)
|
||||
rtrn = loadSingle(spl[1])
|
||||
if rtrn == True:
|
||||
success("Loaded module %s" % spl[1])
|
||||
success("Loaded module: %s" % spl[1])
|
||||
return
|
||||
elif rtrn == "RELOAD":
|
||||
success("Reloaded module: %s" % spl[1])
|
||||
return
|
||||
else:
|
||||
failure("Error loading module %s: %s" % (spl[1], rtrn))
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Logout:
|
||||
def __init__(self, register):
|
||||
register("logout", self.logout)
|
||||
def __init__(self, *args):
|
||||
self.logout(*args)
|
||||
|
||||
def logout(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,12 +2,11 @@ import main
|
||||
from yaml import dump
|
||||
|
||||
class Mod:
|
||||
def __init__(self, register):
|
||||
register("mod", self.mod)
|
||||
def __init__(self, *args):
|
||||
self.mod(*args)
|
||||
|
||||
def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
toUnset = False
|
||||
if length == 2:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
@@ -33,51 +32,17 @@ class Mod:
|
||||
failure("No such key: %s" % spl[2])
|
||||
return
|
||||
|
||||
if spl[2] == "protocol":
|
||||
if not spl[3] in ["ssl", "plain"]:
|
||||
failure("Protocol must be ssl or plain, not %s" % spl[3])
|
||||
return
|
||||
if spl[3] == main.pool[spl[1]][spl[2]]:
|
||||
failure("Value already exists: %s" % spl[3])
|
||||
return
|
||||
|
||||
if spl[3].lower() in ["none", "nil"]:
|
||||
spl[3] = None
|
||||
toUnset = True
|
||||
|
||||
if spl[2] in ["port", "timeout", "maxdelay"]:
|
||||
try:
|
||||
spl[3] = int(spl[3])
|
||||
except:
|
||||
failure("Value must be an integer, not %s" % spl[3])
|
||||
return
|
||||
|
||||
if spl[2] in ["initialdelay", "factor", "jitter"]:
|
||||
try:
|
||||
spl[3] = float(spl[3])
|
||||
except:
|
||||
failure("Value must be a floating point integer, not %s" % spl[3])
|
||||
return
|
||||
|
||||
if spl[2] == "authtype":
|
||||
if not toUnset:
|
||||
if not spl[3] in ["sp", "ns"]:
|
||||
failure("Authtype must be sp or ns, not %s" % spl[3])
|
||||
return
|
||||
if spl[2] == "enabled":
|
||||
failure("Use the enable and disable commands to manage this")
|
||||
return
|
||||
if spl[2] == "autojoin":
|
||||
spl[3] = spl[3].split(",")
|
||||
|
||||
main.pool[spl[1]][spl[2]] = spl[3]
|
||||
if spl[1] in main.IRCPool.keys():
|
||||
main.IRCPool[spl[1]].refresh()
|
||||
main.saveConf("pool")
|
||||
if toUnset:
|
||||
success("Successfully unset key %s on %s" % (spl[2], spl[1]))
|
||||
else:
|
||||
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
|
||||
|
||||
else:
|
||||
|
||||
@@ -5,8 +5,8 @@ from io import StringIO
|
||||
from yaml import dump
|
||||
|
||||
class Mon:
|
||||
def __init__(self, register):
|
||||
register("mon", self.mon)
|
||||
def __init__(self, *args):
|
||||
self.mon(*args)
|
||||
|
||||
def setup_arguments(self, ArgumentParser):
|
||||
self.parser = ArgumentParser(prog="mon", description="Manage monitors. Extremely flexible. All arguments are optional.")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Msg:
|
||||
def __init__(self, register):
|
||||
register("msg", self.msg)
|
||||
def __init__(self, *args):
|
||||
self.msg(*args)
|
||||
|
||||
def msg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
from yaml import dump
|
||||
|
||||
class Network:
|
||||
def __init__(self, register):
|
||||
register("network", self.network)
|
||||
def __init__(self, *args):
|
||||
self.network(*args)
|
||||
|
||||
def network(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Part:
|
||||
def __init__(self, register):
|
||||
register("part", self.part)
|
||||
def __init__(self, *args):
|
||||
self.part(*args)
|
||||
|
||||
def part(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Password:
|
||||
def __init__(self, register):
|
||||
register("pass", self.password)
|
||||
class Pass:
|
||||
def __init__(self, *args):
|
||||
self.password(*args)
|
||||
|
||||
def password(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
from modules import provision
|
||||
|
||||
class Provision:
|
||||
def __init__(self, register):
|
||||
register("provision", self.provision)
|
||||
def __init__(self, *args):
|
||||
self.provision(*args)
|
||||
|
||||
def provision(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
from yaml import dump
|
||||
|
||||
class Relay:
|
||||
def __init__(self, register):
|
||||
register("relay", self.relay)
|
||||
def __init__(self, *args):
|
||||
self.relay(*args)
|
||||
|
||||
def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import main
|
||||
|
||||
class Save:
|
||||
def __init__(self, register):
|
||||
register("save", self.save)
|
||||
def __init__(self, *args):
|
||||
self.save(*args)
|
||||
|
||||
def save(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -4,8 +4,8 @@ import modules.userinfo as userinfo
|
||||
from string import digits
|
||||
|
||||
class Stats:
|
||||
def __init__(self, register):
|
||||
register("stats", self.stats)
|
||||
def __init__(self, *args):
|
||||
self.stats(*args)
|
||||
|
||||
def stats(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
import modules.userinfo as userinfo
|
||||
|
||||
class Users:
|
||||
def __init__(self, register):
|
||||
register("users", self.users)
|
||||
def __init__(self, *args):
|
||||
self.users(*args)
|
||||
|
||||
def users(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
@@ -2,8 +2,8 @@ import main
|
||||
import modules.userinfo as userinfo
|
||||
|
||||
class Who:
|
||||
def __init__(self, register):
|
||||
register("who", self.who)
|
||||
def __init__(self, *args):
|
||||
self.who(*args)
|
||||
|
||||
def who(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
|
||||
Reference in New Issue
Block a user