def globals_init():
    try:
        global sql, sql2
        from importlib import import_module

        sql = import_module('Skem.sql.gban_sql')
        sql2 = import_module('Skem.sql.gmute_sql')
    except Exception as e:
        sql = None
        sql2 = None
        LOGS.warn(get_translation('globalsSqlLog'))
        raise e
Exemple #2
0
def load_module(shortname):
    if shortname.startswith("__"):
        pass
    elif shortname.endswith("_"):
        import DaisyX.utils

        path = Path(f"DaisyX/modules/{shortname}.py")
        name = "DaisyX.modules.{}".format(shortname)
        spec = importlib.util.spec_from_file_location(name, path)
        mod = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(mod)
        LOGS.info("Successfully imported " + shortname)
    else:
        import DaisyX.utils

        path = Path(f"DaisyX/modules/{shortname}.py")
        name = "DaisyX.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.Var = Var
        mod.xbot = xbot
        mod.command = command
        mod.logger = logging.getLogger(shortname)
        # support for uniborg
        sys.modules["uniborg.util"] = DaisyX.utils
        mod.Config = Config
        mod.borg = bot
        mod.edit_or_reply = edit_or_reply
        # support for paperplaneextended
        sys.modules["DaisyX.events"] = DaisyX.utils
        spec.loader.exec_module(mod)
        # for imports
        sys.modules["DaisyX.modules." + shortname] = mod
        LOGS.info("Successfully imported " + shortname)