def load_module(shortname): if shortname.startswith("__"): pass elif shortname.endswith("_"): import importlib import sys from pathlib import Path import WhiteEyeUserBot.modules import WhiteEyeUserBot.utils path = Path(f"WhiteEyeUserBot/modules/{shortname}.py") name = "WhiteEyeUserBot.modules.{}".format(shortname) spec = importlib.util.spec_from_file_location(name, path) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) sedprint.info("Successfully (re)imported " + shortname) else: import importlib import sys from pathlib import Path import WhiteEyeUserBot.modules import WhiteEyeUserBot.utils path = Path(f"WhiteEyeUserBot/modules/{shortname}.py") name = "WhiteEyeUserBot.modules.{}".format(shortname) spec = importlib.util.spec_from_file_location(name, path) mod = importlib.util.module_from_spec(spec) mod.bot = bot mod.tgbot = bot.tgbot mod.Config = Config mod.command = command mod.logger = logging.getLogger(shortname) # support for uniborg sys.modules["uniborg.util"] = WhiteEyeUserBot.utils sys.modules["WhiteEyeUserBot.util"] = WhiteEyeUserBot.utils sys.modules["userbot.utils"] = WhiteEyeUserBot.utils sys.modules["userbot.plugins"] = WhiteEyeUserBot.modules sys.modules["plugins"] = WhiteEyeUserBot.modules sys.modules["userbot"] = WhiteEyeUserBot mod.admin_cmd = WhiteEye_on_cmd mod.sudo_cmd = sudo_cmd mod.WhiteEye_on_cmd = WhiteEye_on_cmd mod.CMD_HELP = CMD_HELP mod.Config = Config mod.ignore_grp = ignore_grp() mod.ignore_pm = ignore_pm() mod.ignore_bot = ignore_bot() mod.am_i_admin = am_i_admin() mod.ignore_fwd = ignore_fwd() mod.borg = bot mod.WhiteEye = bot # support for paperplaneextended sys.modules["WhiteEyeUserBot.events"] = WhiteEyeUserBot.utils sys.modules["WhiteEyeUserBot.functions.events"] = WhiteEyeUserBot.utils spec.loader.exec_module(mod) # for imports sys.modules["WhiteEyeUserBot.modules." + shortname] = mod sedprint.info("Successfully imported " + shortname)
def load_module_dclient(shortname, client): if shortname.startswith("__"): pass elif shortname.endswith("_"): import importlib import sys from pathlib import Path import WhiteEyeUserBot.modules import WhiteEyeUserBot.utils path = Path(f"WhiteEyeUserBot/modules/{shortname}.py") name = "WhiteEyeUserBot.modules.{}".format(shortname) spec = importlib.util.spec_from_file_location(name, path) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) else: import importlib import sys from pathlib import Path import WhiteEyeUserBot.modules import WhiteEyeUserBot.utils path = Path(f"WhiteEyeUserBot/modules/{shortname}.py") name = "WhiteEyeUserBot.modules.{}".format(shortname) spec = importlib.util.spec_from_file_location(name, path) mod = importlib.util.module_from_spec(spec) mod.bot = client mod.tgbot = bot.tgbot mod.Config = Config mod.Var = Config mod.command = command sedlu = str(shortname) + "- MClient -" mod.logger = logging.getLogger(sedlu) # support for uniborg sys.modules["uniborg.util"] = WhiteEyeUserBot.utils sys.modules["WhiteEyeUserBot.util"] = WhiteEyeUserBot.utils sys.modules["userbot.utils"] = WhiteEyeUserBot.utils sys.modules["userbot.plugins"] = WhiteEyeUserBot.modules sys.modules["plugins"] = WhiteEyeUserBot.modules sys.modules["userbot"] = WhiteEyeUserBot mod.admin_cmd = WhiteEye_on_cmd mod.sudo_cmd = sudo_cmd mod.WhiteEye_on_cmd = WhiteEye_on_cmd mod.Config = Config mod.ignore_grp = ignore_grp() mod.ignore_pm = ignore_pm() mod.ignore_bot = ignore_bot() mod.am_i_admin = am_i_admin() mod.ignore_fwd = ignore_fwd() mod.borg = client mod.WhiteEye = client mod.CMD_HELP = CMD_HELP sys.modules["WhiteEyeUserBot.functions.events"] = WhiteEyeUserBot.utils sys.modules["WhiteEyeUserBot.events"] = WhiteEyeUserBot.utils spec.loader.exec_module(mod) sys.modules["WhiteEyeUserBot.modules." + shortname] = mod