Пример #1
0
    def import_load_modules(self) -> bool:
        def tryImportModule(path, module) -> bool:
            try:
                self.__imported_module = import_module(path + module)
                return True
            except ModuleNotFoundError as mnfe:
                raise ModuleNotFoundError(mnfe)
            except Exception:
                log.error(
                    f"Unable to start module '{module}' due to an unhandled exception",
                    exc_info=True)
            return False

        all_modules, sys_modules, user_modules = self.__load_modules()
        try:
            for module in sorted(all_modules):
                ALL_MODULES.append(module)
            for module in sys_modules:
                if tryImportModule("userbot.modules.", module):
                    LOAD_MODULES[module] = True
                    self.__load_modules_count += 1
                else:
                    LOAD_MODULES[module] = False
            for module in user_modules:
                if not module in self.__not_load_modules:
                    if tryImportModule("userbot.modules_user.", module):
                        LOAD_MODULES[module] = True
                        self.__load_modules_count += 1
                    else:
                        LOAD_MODULES[module] = False
                USER_MODULES.append(module)
            return True
        except ModuleNotFoundError as mnfe:
            log.error(f"Unable to load module: {mnfe}", exc_info=True)
        return False
Пример #2
0
 def tryImportModule(path, module) -> bool:
     try:
         self.__imported_module = import_module(path + module)
         return True
     except Exception:
         log.error(f"Unable to start module '{module}' due to an unhandled exception", exc_info=True)
     return False
Пример #3
0
 def tryImportModule(path, module) -> bool:
     try:
         self.__imported_module = import_module(path + module)
         return True
     except KeyboardInterrupt:
         raise KeyboardInterrupt
     except (BaseException, Exception):
         log.error(f"Unable to start module '{module}' due "
                   "to an unhandled exception",
                   exc_info=True)
     return False
Пример #4
0
# Copyright 2020 nunopenim @github
# Copyright 2020 prototype74 @github
#
# Licensed under the PEL (Penim Enterprises License), v1.0
#
# You may not use this file or any of the content within it, unless in
# compliance with the PE License

from userbot import log
from os.path import basename

if basename(__file__).startswith("config") or \
   basename(__file__).startswith("sample_config"):
    log.error("Please do not just use this sample config as "
              "your main config. Create a new config.py in the same "
              "directory with a proper ConfigClass.")
    quit(1)


class ConfigClass(object):
    # Required configurations
    #
    # API KEY and HASH are 2 identification numbers to log in
    # into your Telegram API appliaction. If you don't have any yet,
    # create a new application at https://my.telegram.org
    # and put your API IDs to the corresponding configs below
    #
    # Note: Do NOT share your API KEY and HASH with anyone else!
    #
    API_KEY = ""  # Your API KEY
    API_HASH = ""  # Your API HASH
Пример #5
0
        modules = _Modules()
        if not modules.import_load_modules():
            quit(1)
        load_modules_count = modules.loaded_modules()
        sum_modules = len(ALL_MODULES)
        if not load_modules_count:
            log.warning("No module(s) loaded!")
        elif load_modules_count > 0:
            log.info(
                f"Modules ({load_modules_count}/{sum_modules}) loaded and ready"
            )
        log.info("Starting Telegram client")
        with tgclient:
            me = tgclient.loop.run_until_complete(tgclient.get_me())
            log.info("You're running %s v%s as %s (ID: %s)", PROJECT, VERSION,
                     me.first_name, me.id)
            tgclient.run_until_disconnected()
    except KeyboardInterrupt:
        log.info("Keyboard interruption. Terminating...")
    except PhoneNumberInvalidError:
        log.error("Invalid phone number!")
    except Exception as e:
        log.critical(f"Unable to start userbot: {e}", exc_info=True)

    try:
        if fhandler:
            fhandler.close()
        shutdown()  # shutdown logging
    except:
        pass