2021-09-16 17:35:06 +00:00
|
|
|
class Command:
|
2021-10-03 21:36:22 +00:00
|
|
|
def __init__(self,config):
|
2021-09-19 18:33:30 +00:00
|
|
|
self.config=config
|
2021-10-03 21:36:22 +00:00
|
|
|
self.commands=[]
|
2021-09-16 17:35:06 +00:00
|
|
|
def mesg(self,msg): self.util.mesg(msg)
|
2021-10-03 21:36:22 +00:00
|
|
|
def err_perm(self,level="admin"): self.mesg(f"Error: insufficient privileges, you lack {level} access")
|
|
|
|
def adm(func,*args, **kwargs):
|
|
|
|
global adm_cmds
|
|
|
|
try:
|
|
|
|
if func.__name__ not in adm_cmds and func.__name__!="_": adm_cmds.append(func.__name__)
|
|
|
|
except NameError:
|
|
|
|
adm_cmds=[]
|
|
|
|
if func.__name__ not in adm_cmds and func.__name__!="_": adm_cmds.append(func.__name__)
|
|
|
|
def _(self,*args, **kwargs):
|
|
|
|
if(func.__name__=="help"):
|
|
|
|
self.admin_commands=adm_cmds
|
|
|
|
#func.admin_commands=adm_cmds
|
|
|
|
if not self.admin:
|
|
|
|
self.err_perm()
|
|
|
|
else:
|
|
|
|
# return func(self)
|
|
|
|
return func(self,self.prefix,self.line,self.pm,self._line,self.admin,self.mesg)
|
|
|
|
return _
|
|
|
|
def cmd(func,*args, **kwargs):
|
|
|
|
global cmds
|
|
|
|
try:
|
|
|
|
if func.__name__ not in cmds and func.__name__!="_": cmds.append(func.__name__)
|
|
|
|
except NameError:
|
|
|
|
cmds=[]
|
|
|
|
if func.__name__ not in cmds and func.__name__!="_": cmds.append(func.__name__)
|
|
|
|
def _(self,*args, **kwargs):
|
|
|
|
if(func.__name__=="help"):
|
|
|
|
self.commands=cmds
|
|
|
|
#func.commands=cmds
|
|
|
|
if(func.__name__ not in self.config.cmd.disabled):
|
|
|
|
return func(self,self.prefix,self.line,self.pm,self._line,self.admin,self.mesg)
|
|
|
|
return _
|
|
|
|
def preq_cmd(self): #command prequisites / triggers
|
|
|
|
cmd=self.line
|
|
|
|
if cmd=="help" or cmd.startswith("help "):
|
|
|
|
command="help"
|
|
|
|
elif cmd.startswith("echo "):
|
|
|
|
command="echo"
|
|
|
|
elif cmd=="dbg" or cmd.startswith("dbg "):
|
|
|
|
command="dbg"
|
|
|
|
elif cmd=="dbg2" or cmd.startswith("dbg2 "):
|
|
|
|
command="dbg2"
|
|
|
|
else:return
|
|
|
|
if command not in self.config.cmd.disabled:
|
|
|
|
eval(f"self.{command}()")
|
|
|
|
@adm
|
|
|
|
def quit(self,prefix,cmd,pm,line,admin,mesg):
|
|
|
|
if admin and (cmd=="q" or cmd=="quit"):
|
|
|
|
self.util.quit()
|
|
|
|
elif is_adm and (cmd.startswith("q ") or cmd.startswith("quit ")):
|
|
|
|
self.util.quit(cmd.split(" ",1)[1])
|
|
|
|
|
|
|
|
@adm
|
|
|
|
def dbg2(self,prefix,cmd,pm,line,admin,mesg):
|
|
|
|
mesg(dir(self))
|
|
|
|
@adm
|
|
|
|
def dbg(self,prefix,cmd,pm,line,admin,mesg):
|
|
|
|
"""temporary debug command, subject to change A LOT""";
|
|
|
|
mesg(dir())
|
|
|
|
@cmd
|
|
|
|
def echo(self,prefix,cmd,pm,line,admin,mesg):
|
2021-09-16 17:35:06 +00:00
|
|
|
"""simple echo command"""
|
2021-10-03 21:36:22 +00:00
|
|
|
mesg(cmd.split(" ",1)[1])
|
|
|
|
@cmd
|
|
|
|
def help(self,prefix,cmd,pm,line,admin,mesg):
|
|
|
|
global adm_cmds
|
|
|
|
global cmds
|
|
|
|
disabled_commands=self.config.cmd.disabled
|
|
|
|
admin_commands,commands=[],[]
|
|
|
|
for i in ["exec","eval","reload"]:
|
|
|
|
if i not in adm_cmds:
|
|
|
|
adm_cmds.append(i)
|
|
|
|
for i in adm_cmds:
|
|
|
|
if i not in disabled_commands:
|
|
|
|
admin_commands.append(i)
|
|
|
|
for i in cmds:
|
|
|
|
if i not in admin_commands and i not in disabled_commands:
|
|
|
|
commands.append(i)
|
|
|
|
prefixes="\""+"\", \"".join(self.config.cmd.prefixes)+"\""
|
|
|
|
admin_commands=", ".join(admin_commands)
|
|
|
|
try: topic=cmd.split(" ",1)[1]
|
2021-09-16 17:35:06 +00:00
|
|
|
except IndexError: topic=None
|
2021-10-03 21:36:22 +00:00
|
|
|
try: self_nick=self.self_nick
|
2021-09-21 17:41:31 +00:00
|
|
|
except IndexError: self_nick=None
|
2021-10-03 21:36:22 +00:00
|
|
|
|
2021-09-16 17:35:06 +00:00
|
|
|
abs_topics={
|
2021-09-21 17:41:31 +00:00
|
|
|
"prefixes":f"available prefixes are {prefixes} or \"{self_nick}\""
|
2021-09-16 17:35:06 +00:00
|
|
|
}
|
|
|
|
if topic==None:
|
2021-10-03 21:36:22 +00:00
|
|
|
mesg(f"available topics: "+", ".join(list(abs_topics.keys())))
|
|
|
|
mesg(f"available commands: "+", ".join(commands))
|
2021-09-16 17:35:06 +00:00
|
|
|
if admin:
|
|
|
|
mesg(f"admin commands: {admin_commands}")
|
|
|
|
else:
|
|
|
|
try: mesg(f"{topic}: "+eval(f"self.{topic}.__doc__"))
|
2021-10-03 21:36:22 +00:00
|
|
|
except (TypeError,AttributeError) as e:
|
2021-09-21 17:41:31 +00:00
|
|
|
# mesg(str( e.__class__.__name__ ))
|
2021-09-16 17:35:06 +00:00
|
|
|
if topic in abs_topics:
|
|
|
|
mesg(f"{topic}: "+abs_topics[topic])
|
|
|
|
else:
|
|
|
|
mesg(f"no help available for \"{topic}\"...")
|
|
|
|
except Exception as e: mesg(str(e.__class__)+" "+str(e))
|