Renovate the module system and implement adding and resuming pool instances using the new relay/alias/network system
parent
4efea3f535
commit
8926cb76ec
@ -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)
|
|
@ -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,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:
|
@ -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