From 68ee237c14e133a1fb38cf1c205a0f575adb81ec Mon Sep 17 00:00:00 2001 From: jan6 Date: Sun, 19 Sep 2021 19:56:17 +0300 Subject: [PATCH] hot reload! --- command.py => commands.py | 9 +++++++++ config.py | 2 +- stuff.py | 11 +++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) rename command.py => commands.py (82%) diff --git a/command.py b/commands.py similarity index 82% rename from command.py rename to commands.py index f46a82f..70e5b60 100644 --- a/command.py +++ b/commands.py @@ -4,6 +4,7 @@ class Command: self.sock=sock self.util=Util(sock) def mesg(self,msg): self.util.mesg(msg) + def err_perm(self,level="admin"): mesg("Error: insufficient privileges, you lack {level} access") 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)") @@ -35,3 +36,11 @@ class Command: 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)) + def reload(self,prefix,cmd,pm,line,admin): + mesg=self.mesg + if admin: + mesg("reloading...") + self.util.reload() + mesg("reloaded!") + else: + err_perm() diff --git a/config.py b/config.py index 9be53d3..847d62e 100644 --- a/config.py +++ b/config.py @@ -24,4 +24,4 @@ class config: class cmd: prefixes=["6","'"] enabled_commands=["help","echo"] - admin_commands=["eval","quit"] + admin_commands=["eval","quit","reload"] diff --git a/stuff.py b/stuff.py index 34dc327..9835e56 100755 --- a/stuff.py +++ b/stuff.py @@ -1,8 +1,10 @@ import irctokens -from config import config +from config import config as Config from util import Util -from command import Command +from commands import Command +import sys, importlib def stuff(bot,sock): + config=Config chan=config.server.channel util=Util(sock) command=Command(sock) @@ -93,6 +95,11 @@ def stuff(bot,sock): quit() elif is_adm and (cmd.startswith("q ") or cmd.startswith("quit")): quit(cmd.split(" ",1)[1]) + elif is_adm and cmd.startswith("reload"): +# command.exec_cmd("reload") + command=importlib.reload(sys.modules["commands"]).Command(sock) + config=importlib.reload(sys.modules["config"]).config + mesg("reloaded") elif cmd.startswith("eval "): if(is_adm): try: