from util import Util class Command: def __init__(self,sock): self.sock=sock self.util=Util(sock) def mesg(self,msg): self.util.mesg(msg) def exec_cmd(self,command,extra=[None]): if extra!=[None]: eval(f"self.{command}(self.prefix,self.cmd,self.pm,self.line,self.admin,extra)") else: eval(f"self.{command}(self.prefix,self.cmd,self.pm,self.line,self.admin)") def echo(self,prefix,cmd,pm,line,admin): """simple echo command""" self.util.mesg(cmd.split(" ",1)[1]) def help(self,prefix,cmd,pm,line,admin,extra): mesg=self.mesg prefixes=", ".join(extra[0]) enabled_commands=extra[1] admin_commands=", ".join(extra[2]) try: topic=extra[3] except IndexError: topic=None abs_topics={ "prefixes":"available prefixes are {prefixes} or my name" } if topic==None: mesg(f"available topics: "+", ".join(enabled_commands+list(abs_topics.keys()))) if admin: mesg(f"admin commands: {admin_commands}") else: try: mesg(f"{topic}: "+eval(f"self.{topic}.__doc__")) except TypeError: if topic in abs_topics: mesg(f"{topic}: "+abs_topics[topic]) else: mesg(f"no help available for \"{topic}\"...") except AttributeError: mesg(f"there's no such thing as \"{topic}\"!") except Exception as e: mesg(str(e.__class__)+" "+str(e))