Renovate the module system and implement adding and resuming pool instances using the new relay/alias/network system
This commit is contained in:
parent
4efea3f535
commit
8926cb76ec
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
|
from yaml import dump
|
||||||
|
|
||||||
class Alias:
|
class Alias:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("alias", self.alias)
|
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 authed:
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
import modules.userinfo as userinfo
|
import modules.userinfo as userinfo
|
||||||
|
|
||||||
class Chans:
|
class Chans:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("chans", self.chans)
|
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 authed:
|
||||||
|
|
|
@ -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
|
import main
|
||||||
|
|
||||||
class Delete:
|
class Del:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("del", self.delete)
|
self.delete(*args)
|
||||||
|
|
||||||
def delete(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def delete(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||||
if authed:
|
if authed:
|
|
@ -1,8 +1,9 @@
|
||||||
import main
|
import main
|
||||||
|
from core.bot import deliverRelayCommands
|
||||||
|
|
||||||
class Disable:
|
class Disable:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("disable", self.disable)
|
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 authed:
|
||||||
|
@ -11,6 +12,11 @@ class Disable:
|
||||||
failure("Name does not exist: %s" % spl[1])
|
failure("Name does not exist: %s" % spl[1])
|
||||||
return
|
return
|
||||||
main.pool[spl[1]]["enabled"] = False
|
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")
|
main.saveConf("pool")
|
||||||
if spl[1] in main.ReactorPool.keys():
|
if spl[1] in main.ReactorPool.keys():
|
||||||
if spl[1] in main.FactoryPool.keys():
|
if spl[1] in main.FactoryPool.keys():
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
from subprocess import run, PIPE
|
from subprocess import run, PIPE
|
||||||
|
|
||||||
class Dist:
|
class Dist:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("dist", self.dist)
|
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 authed:
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import main
|
import main
|
||||||
import core.helper as helper
|
from core.helper import startBot
|
||||||
|
from core.bot import deliverRelayCommands
|
||||||
|
|
||||||
class Enable:
|
class Enable:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("enable", self.enable)
|
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 authed:
|
||||||
|
@ -12,9 +13,14 @@ class Enable:
|
||||||
failure("Name does not exist: %s" % spl[1])
|
failure("Name does not exist: %s" % spl[1])
|
||||||
return
|
return
|
||||||
main.pool[spl[1]]["enabled"] = True
|
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")
|
main.saveConf("pool")
|
||||||
if not spl[1] in main.IRCPool.keys():
|
if not spl[1] in main.IRCPool.keys():
|
||||||
helper.addBot(spl[1])
|
startBot(spl[1])
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
success("Successfully enabled bot %s" % spl[1])
|
success("Successfully enabled bot %s" % spl[1])
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Get:
|
class Get:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("get", self.get)
|
self.get(*args)
|
||||||
|
|
||||||
def get(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def get(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||||
if authed:
|
if authed:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Help:
|
class Help:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("help", self.help)
|
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:
|
if authed:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Join:
|
class Join:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("join", self.join)
|
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 authed:
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
import modules.keyword as keyword
|
import modules.keyword as keyword
|
||||||
|
|
||||||
class Key:
|
class Key:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("key", self.key)
|
self.key(*args)
|
||||||
|
|
||||||
def key(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def key(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||||
if authed:
|
if authed:
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
from yaml import dump
|
from yaml import dump
|
||||||
|
|
||||||
class List:
|
class List:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("list", self.list)
|
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 authed:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Load:
|
class Load:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("load", self.load)
|
self.list(*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 authed:
|
||||||
|
|
|
@ -2,15 +2,18 @@ import main
|
||||||
from utils.loaders.single_loader import loadSingle
|
from utils.loaders.single_loader import loadSingle
|
||||||
|
|
||||||
class Loadmod:
|
class Loadmod:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("loadmod", self.loadmod)
|
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 authed:
|
||||||
if length == 2:
|
if length == 2:
|
||||||
rtrn = loadSingle(spl[1], main.register)
|
rtrn = loadSingle(spl[1])
|
||||||
if rtrn == True:
|
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
|
return
|
||||||
else:
|
else:
|
||||||
failure("Error loading module %s: %s" % (spl[1], rtrn))
|
failure("Error loading module %s: %s" % (spl[1], rtrn))
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Logout:
|
class Logout:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("logout", self.logout)
|
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:
|
if authed:
|
||||||
|
|
|
@ -2,12 +2,11 @@ import main
|
||||||
from yaml import dump
|
from yaml import dump
|
||||||
|
|
||||||
class Mod:
|
class Mod:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("mod", self.mod)
|
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 authed:
|
||||||
toUnset = False
|
|
||||||
if length == 2:
|
if length == 2:
|
||||||
if not spl[1] in main.pool.keys():
|
if not spl[1] in main.pool.keys():
|
||||||
failure("Name does not exist: %s" % spl[1])
|
failure("Name does not exist: %s" % spl[1])
|
||||||
|
@ -33,51 +32,17 @@ class Mod:
|
||||||
failure("No such key: %s" % spl[2])
|
failure("No such key: %s" % spl[2])
|
||||||
return
|
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]]:
|
if spl[3] == main.pool[spl[1]][spl[2]]:
|
||||||
failure("Value already exists: %s" % spl[3])
|
failure("Value already exists: %s" % spl[3])
|
||||||
return
|
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":
|
if spl[2] == "enabled":
|
||||||
failure("Use the enable and disable commands to manage this")
|
failure("Use the enable and disable commands to manage this")
|
||||||
return
|
return
|
||||||
if spl[2] == "autojoin":
|
|
||||||
spl[3] = spl[3].split(",")
|
|
||||||
|
|
||||||
main.pool[spl[1]][spl[2]] = spl[3]
|
main.pool[spl[1]][spl[2]] = spl[3]
|
||||||
if spl[1] in main.IRCPool.keys():
|
|
||||||
main.IRCPool[spl[1]].refresh()
|
|
||||||
main.saveConf("pool")
|
main.saveConf("pool")
|
||||||
if toUnset:
|
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
|
||||||
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]))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,8 +5,8 @@ from io import StringIO
|
||||||
from yaml import dump
|
from yaml import dump
|
||||||
|
|
||||||
class Mon:
|
class Mon:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("mon", self.mon)
|
self.mon(*args)
|
||||||
|
|
||||||
def setup_arguments(self, ArgumentParser):
|
def setup_arguments(self, ArgumentParser):
|
||||||
self.parser = ArgumentParser(prog="mon", description="Manage monitors. Extremely flexible. All arguments are optional.")
|
self.parser = ArgumentParser(prog="mon", description="Manage monitors. Extremely flexible. All arguments are optional.")
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Msg:
|
class Msg:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("msg", self.msg)
|
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 authed:
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
from yaml import dump
|
from yaml import dump
|
||||||
|
|
||||||
class Network:
|
class Network:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("network", self.network)
|
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 authed:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Part:
|
class Part:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("part", self.part)
|
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 authed:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Password:
|
class Pass:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("pass", self.password)
|
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:
|
if authed:
|
|
@ -2,8 +2,8 @@ import main
|
||||||
from modules import provision
|
from modules import provision
|
||||||
|
|
||||||
class Provision:
|
class Provision:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("provision", self.provision)
|
self.provision(*args)
|
||||||
|
|
||||||
def provision(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
def provision(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||||
if authed:
|
if authed:
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
from yaml import dump
|
from yaml import dump
|
||||||
|
|
||||||
class Relay:
|
class Relay:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("relay", self.relay)
|
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 authed:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import main
|
import main
|
||||||
|
|
||||||
class Save:
|
class Save:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("save", self.save)
|
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 authed:
|
||||||
|
|
|
@ -4,8 +4,8 @@ import modules.userinfo as userinfo
|
||||||
from string import digits
|
from string import digits
|
||||||
|
|
||||||
class Stats:
|
class Stats:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("stats", self.stats)
|
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 authed:
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
import modules.userinfo as userinfo
|
import modules.userinfo as userinfo
|
||||||
|
|
||||||
class Users:
|
class Users:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("users", self.users)
|
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 authed:
|
||||||
|
|
|
@ -2,8 +2,8 @@ import main
|
||||||
import modules.userinfo as userinfo
|
import modules.userinfo as userinfo
|
||||||
|
|
||||||
class Who:
|
class Who:
|
||||||
def __init__(self, register):
|
def __init__(self, *args):
|
||||||
register("who", self.who)
|
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 authed:
|
||||||
|
|
|
@ -23,5 +23,6 @@
|
||||||
"alias": "alias <add|del|list> [<alias> <nickname> <altnick> <ident> <realname> <password>]",
|
"alias": "alias <add|del|list> [<alias> <nickname> <altnick> <ident> <realname> <password>]",
|
||||||
"relay": "relay <add|del|list> [<relay> <host> <port> <user> <password>]",
|
"relay": "relay <add|del|list> [<relay> <host> <port> <user> <password>]",
|
||||||
"network": "network <add|del|list> [<name> <address> <port> <ssl|plain> <sasl|ns|none>]",
|
"network": "network <add|del|list> [<name> <address> <port> <ssl|plain> <sasl|ns|none>]",
|
||||||
"provision": "provision <relay> <alias> [<network>]"
|
"provision": "provision <relay> <alias> [<network>]",
|
||||||
|
"cmd": "cmd <relay> <user> <entity> <text ...>"
|
||||||
}
|
}
|
||||||
|
|
46
core/bot.py
46
core/bot.py
|
@ -95,44 +95,27 @@ class IRCBot(IRCClient):
|
||||||
error("Network with all numbers: %s" % name)
|
error("Network with all numbers: %s" % name)
|
||||||
self.buffer = ""
|
self.buffer = ""
|
||||||
self.name = name
|
self.name = name
|
||||||
instance = main.pool[name]
|
inst = main.pool[name]
|
||||||
|
alias = main.alias[inst["alias"]]
|
||||||
|
relay = main.relay[inst["relay"]]
|
||||||
|
network = main.network[inst["network"]]
|
||||||
|
|
||||||
self.nickname = instance["nickname"]
|
self.nickname = alias["nick"]
|
||||||
self.realname = instance["realname"]
|
self.realname = alias["realname"]
|
||||||
self.username = instance["username"]
|
self.username = inst["alias"]+"/"+inst["network"]
|
||||||
self.userinfo = instance["userinfo"]
|
self.password = relay["password"]
|
||||||
self.fingerReply = instance["finger"]
|
self.userinfo = None
|
||||||
self.versionName = instance["version"]
|
self.fingerReply = None
|
||||||
|
self.versionName = None
|
||||||
self.versionNum = None
|
self.versionNum = None
|
||||||
self.versionEnv = None
|
self.versionEnv = None
|
||||||
self.sourceURL = instance["source"]
|
self.sourceURL = None
|
||||||
self.autojoin = instance["autojoin"]
|
|
||||||
|
|
||||||
self._who = {}
|
self._who = {}
|
||||||
self._getWho = {}
|
self._getWho = {}
|
||||||
|
|
||||||
self._names = {}
|
self._names = {}
|
||||||
|
|
||||||
self.authtype = instance["authtype"]
|
|
||||||
if self.authtype == "ns":
|
|
||||||
self.authpass = instance["password"]
|
|
||||||
self.authentity = instance["authentity"]
|
|
||||||
else:
|
|
||||||
self.password = instance["password"]
|
|
||||||
|
|
||||||
def refresh(self):
|
|
||||||
instance = main.pool[self.name]
|
|
||||||
if not instance["nickname"] == self.nickname:
|
|
||||||
self.nickname = instance["nickname"]
|
|
||||||
self.setNick(self.nickname)
|
|
||||||
|
|
||||||
self.userinfo = instance["userinfo"]
|
|
||||||
self.fingerReply = instance["finger"]
|
|
||||||
self.versionName = instance["version"]
|
|
||||||
self.versionNum = None
|
|
||||||
self.versionEnv = None
|
|
||||||
self.sourceURL = instance["source"]
|
|
||||||
|
|
||||||
def parsen(self, user):
|
def parsen(self, user):
|
||||||
step = user.split("!")
|
step = user.split("!")
|
||||||
nick = step[0]
|
nick = step[0]
|
||||||
|
@ -350,10 +333,6 @@ class IRCBot(IRCClient):
|
||||||
log("signed on: %s" % self.name)
|
log("signed on: %s" % self.name)
|
||||||
if main.config["Notifications"]["Connection"]:
|
if main.config["Notifications"]["Connection"]:
|
||||||
keyword.sendMaster("SIGNON: %s" % self.name)
|
keyword.sendMaster("SIGNON: %s" % self.name)
|
||||||
if self.authtype == "ns":
|
|
||||||
self.msg(self.authentity, "IDENTIFY %s" % self.nspass)
|
|
||||||
for i in self.autojoin:
|
|
||||||
self.join(i)
|
|
||||||
count.event(self.net, "signedon")
|
count.event(self.net, "signedon")
|
||||||
|
|
||||||
def joined(self, channel):
|
def joined(self, channel):
|
||||||
|
@ -454,7 +433,6 @@ class IRCBotFactory(ReconnectingClientFactory):
|
||||||
def __init__(self, name, relay=None, relayCommands=None, user=None, stage2=None):
|
def __init__(self, name, relay=None, relayCommands=None, user=None, stage2=None):
|
||||||
if not name == None:
|
if not name == None:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.instance = main.pool[name]
|
|
||||||
self.net = "".join([x for x in self.name if not x in digits])
|
self.net = "".join([x for x in self.name if not x in digits])
|
||||||
else:
|
else:
|
||||||
self.name = "Relay to "+relay
|
self.name = "Relay to "+relay
|
||||||
|
|
|
@ -1,39 +1,38 @@
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from core.bot import IRCBot, IRCBotFactory
|
from core.bot import IRCBot, IRCBotFactory
|
||||||
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
import main
|
import main
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
|
|
||||||
def addBot(name):
|
def startBot(name):
|
||||||
instance = main.pool[name]
|
inst = main.pool[name]
|
||||||
log("Started bot %s to %s:%s protocol %s nickname %s" % (name,
|
relay, alias, network = inst["relay"], inst["alias"], inst["network"]
|
||||||
instance["host"],
|
host = main.relay[relay]["host"]
|
||||||
instance["port"],
|
port = int(main.relay[relay]["port"])
|
||||||
instance["protocol"],
|
|
||||||
instance["nickname"]))
|
|
||||||
|
|
||||||
|
log("Started bot %s to %s network %s" % (name, relay, network))
|
||||||
|
|
||||||
if instance["protocol"] == "ssl":
|
keyFN = main.certPath+main.config["Key"]
|
||||||
keyFN = main.certPath+main.config["Key"]
|
certFN = main.certPath+main.config["Certificate"]
|
||||||
certFN = main.certPath+main.config["Certificate"]
|
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"),
|
||||||
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"),
|
certFN.encode("utf-8", "replace"))
|
||||||
certFN.encode("utf-8", "replace"))
|
if "bind" in main.relay[relay].keys():
|
||||||
if instance["bind"] == None:
|
bot = IRCBotFactory(name)
|
||||||
bot = IRCBotFactory(name)
|
rct = reactor.connectSSL(host,
|
||||||
rct = reactor.connectSSL(instance["host"],
|
port,
|
||||||
int(instance["port"]),
|
bot, contextFactory,
|
||||||
bot, contextFactory)
|
bindAddress=main.relay[relay]["bind"])
|
||||||
|
|
||||||
main.ReactorPool[name] = rct
|
main.ReactorPool[name] = rct
|
||||||
main.FactoryPool[name] = bot
|
main.FactoryPool[name] = bot
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
bot = IRCBotFactory(name)
|
||||||
|
rct = reactor.connectSSL(host,
|
||||||
|
port,
|
||||||
|
bot, contextFactory)
|
||||||
|
|
||||||
bot = IRCBotFactory(name)
|
main.ReactorPool[name] = rct
|
||||||
rct = reactor.connectSSL(instance["host"],
|
main.FactoryPool[name] = bot
|
||||||
int(instance["port"]),
|
return
|
||||||
bot, contextFactory,
|
|
||||||
bindAddress=instance["bind"])
|
|
||||||
|
|
||||||
main.ReactorPool[name] = rct
|
|
||||||
main.FactoryPool[name] = bot
|
|
||||||
return
|
|
||||||
|
|
|
@ -22,9 +22,8 @@ def parseCommand(addr, authed, data):
|
||||||
else:
|
else:
|
||||||
failure("No text was sent")
|
failure("No text was sent")
|
||||||
return
|
return
|
||||||
for i in main.CommandMap.keys():
|
if spl[0] in main.CommandMap.keys():
|
||||||
if spl[0] == i:
|
main.CommandMap[spl[0]](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
|
||||||
main.CommandMap[i](addr, authed, data, obj, spl, success, failure, info, incUsage, length)
|
return
|
||||||
return
|
|
||||||
incUsage(None)
|
incUsage(None)
|
||||||
return
|
return
|
||||||
|
|
13
main.py
13
main.py
|
@ -1,7 +1,6 @@
|
||||||
from json import load, dump, loads
|
from json import load, dump, loads
|
||||||
import redis
|
from redis import StrictRedis
|
||||||
from string import digits
|
from string import digits
|
||||||
from utils.loaders.command_loader import loadCommands
|
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
|
|
||||||
configPath = "conf/"
|
configPath = "conf/"
|
||||||
|
@ -43,13 +42,6 @@ def liveNets():
|
||||||
networks.add("".join([x for x in i if not x in digits]))
|
networks.add("".join([x for x in i if not x in digits]))
|
||||||
return networks
|
return networks
|
||||||
|
|
||||||
def register(command, function):
|
|
||||||
if not command in CommandMap:
|
|
||||||
CommandMap[command] = function
|
|
||||||
debug("Registered command: %s" % command)
|
|
||||||
else:
|
|
||||||
error("Duplicate command: %s" % (command))
|
|
||||||
|
|
||||||
def saveConf(var):
|
def saveConf(var):
|
||||||
with open(configPath+filemap[var][0], "w") as f:
|
with open(configPath+filemap[var][0], "w") as f:
|
||||||
dump(globals()[var], f, indent=4)
|
dump(globals()[var], f, indent=4)
|
||||||
|
@ -66,7 +58,6 @@ def initConf():
|
||||||
def initMain():
|
def initMain():
|
||||||
global r
|
global r
|
||||||
initConf()
|
initConf()
|
||||||
loadCommands(register)
|
r = StrictRedis(unix_socket_path=config["RedisSocket"], db=0)
|
||||||
r = redis.StrictRedis(unix_socket_path=config["RedisSocket"], db=0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import main
|
import main
|
||||||
from core.bot import deliverRelayCommands
|
from core.bot import deliverRelayCommands
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
|
from core.helper import startBot
|
||||||
|
|
||||||
def provisionUserData(relay, alias, nick, altnick, ident, realname, password):
|
def provisionUserData(relay, alias, nick, altnick, ident, realname, password):
|
||||||
commands = {}
|
commands = {}
|
||||||
|
@ -81,7 +82,10 @@ def provisionRelayForNetwork(relay, alias, network):
|
||||||
else:
|
else:
|
||||||
main.pool[network+i] = {"relay": relay,
|
main.pool[network+i] = {"relay": relay,
|
||||||
"alias": alias,
|
"alias": alias,
|
||||||
"network": network}
|
"network": network,
|
||||||
|
"enabled": main.config["ConnectOnCreate"]}
|
||||||
main.saveConf("pool")
|
main.saveConf("pool")
|
||||||
|
if main.config["ConnectOnCreate"]:
|
||||||
|
startBot(network+i)
|
||||||
storedNetwork = True
|
storedNetwork = True
|
||||||
return network+i
|
return network+i
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
||||||
|
|
||||||
#from twisted.python import log
|
#from twisted.python import log
|
||||||
#from sys import stdout
|
#from sys import stdout
|
||||||
#log.startLogging(stdout)
|
#log.startLogging(stdout)
|
||||||
|
@ -11,10 +10,12 @@ import main
|
||||||
main.initMain()
|
main.initMain()
|
||||||
|
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
import modules.userinfo as userinfo
|
from utils.loaders.command_loader import loadCommands
|
||||||
import core.helper as helper
|
from core.helper import startBot
|
||||||
from core.server import Server, ServerFactory
|
from core.server import Server, ServerFactory
|
||||||
|
|
||||||
|
loadCommands()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
listener = ServerFactory()
|
listener = ServerFactory()
|
||||||
if main.config["Listener"]["UseSSL"] == True:
|
if main.config["Listener"]["UseSSL"] == True:
|
||||||
|
@ -27,6 +28,6 @@ if __name__ == "__main__":
|
||||||
if not "enabled" in main.pool[i]:
|
if not "enabled" in main.pool[i]:
|
||||||
continue
|
continue
|
||||||
if main.pool[i]["enabled"] == True:
|
if main.pool[i]["enabled"] == True:
|
||||||
helper.addBot(i)
|
startBot(i)
|
||||||
|
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
import commands
|
import commands
|
||||||
|
|
||||||
def loadCommands(func):
|
from main import CommandMap
|
||||||
|
|
||||||
|
def loadCommands():
|
||||||
for filename in listdir('commands'):
|
for filename in listdir('commands'):
|
||||||
if filename.endswith('.py') and filename != "__init__.py":
|
if filename.endswith('.py') and filename != "__init__.py":
|
||||||
commandName = filename[0:-3]
|
commandName = filename[0:-3]
|
||||||
className = commandName.capitalize()
|
className = commandName.capitalize()
|
||||||
try:
|
try:
|
||||||
__import__('commands.%s' % commandName)
|
module = __import__('commands.%s' % commandName)
|
||||||
eval('commands.%s.%s(func)' % (commandName, className))
|
if not commandName in CommandMap:
|
||||||
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
||||||
|
debug("Registered command: %s" % commandName)
|
||||||
|
else:
|
||||||
|
error("Duplicate command: %s" % (commandName))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
error("Exception while loading command %s:\n%s" % (commandName, err))
|
error("Exception while loading command %s:\n%s" % (commandName, err))
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
from os import listdir
|
from os import listdir
|
||||||
import main
|
from importlib import reload
|
||||||
|
from sys import modules
|
||||||
|
|
||||||
from utils.logging.log import *
|
from utils.logging.log import *
|
||||||
import commands
|
import commands
|
||||||
|
|
||||||
def loadSingle(command, func):
|
from main import CommandMap
|
||||||
if command+".py" in listdir("commands"):
|
|
||||||
|
def loadSingle(commandName):
|
||||||
|
if commandName+".py" in listdir("commands"):
|
||||||
|
className = commandName.capitalize()
|
||||||
try:
|
try:
|
||||||
if command in main.CommandMap.keys():
|
if commandName in CommandMap.keys():
|
||||||
return "Cannot reload modules"
|
reload(modules["commands."+commandName])
|
||||||
else:
|
CommandMap[commandName] = getattr(modules["commands."+commandName], className)
|
||||||
className = command.capitalize()
|
debug("Reloaded command: %s" % commandName)
|
||||||
__import__("commands.%s" % command)
|
return "RELOAD"
|
||||||
eval("commands.%s.%s(func)" % (command, className))
|
module = __import__('commands.%s' % commandName)
|
||||||
return True
|
CommandMap[commandName] = getattr(getattr(module, commandName), className)
|
||||||
|
debug("Registered command: %s" % commandName)
|
||||||
|
return True
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
return err
|
return err
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in New Issue