コード例 #1
0
def check_reboot():
    perf_reboot = getConfig("REBOOT", False)
    start_recovery = getConfig("START_RECOVERY", False)
    try:
        if perf_reboot or start_recovery:
            py_exec = (executable
                       if " " not in executable else '"' + executable + '"')
            if perf_reboot:  # preferred if True
                if getConfig("REBOOT_SAFEMODE"):
                    log.info("Rebooting into safe mode...")
                    tcmd = [py_exec, "-m", "userbot", "-safemode"]
                else:
                    log.info("Performing normal reboot...")
                    tcmd = [py_exec, "-m", "userbot"]
            elif start_recovery:
                commit_id = getConfig("UPDATE_COMMIT_ID")
                if commit_id:
                    log.info("Starting auto update in recovery...")
                    tcmd = [py_exec, "recovery.py", "-autoupdate", commit_id]
                else:
                    log.info("Rebooting into recovery...")
                    tcmd = [py_exec, "recovery.py"]
            shutdown_logging()
            execle(py_exec, *tcmd, environ)
    except KeyboardInterrupt:
        raise KeyboardInterrupt
    except (BaseException, Exception) as e:
        if start_recovery:
            log.critical(f"Failed to reboot HyperUBot into recovery: {e}",
                         exc_info=True)
        else:
            log.critical(f"Failed to reboot HyperUBot: {e}",
                         exc_info=True)
    return
コード例 #2
0
ファイル: __main__.py プロジェクト: zeuslord224/HyperUBot
    def import_load_modules(self):
        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

        all_modules, sys_modules, user_modules = self.__load_modules()
        try:
            for module in sorted(all_modules):
                update_all_modules(module)
            for module in sys_modules:
                if tryImportModule("userbot.modules.", module):
                    update_load_modules(module, True)
                    self.__load_modules_count += 1
                else:
                    update_load_modules(module, False)
            for module in user_modules:
                if not SAFEMODE:
                    if not module in self.__not_load_modules:
                        if tryImportModule("userbot.modules_user.", module):
                            update_load_modules(module, True)
                            self.__load_modules_count += 1
                        else:
                            update_load_modules(module, False)
                update_user_modules(module)
        except Exception as e:
            log.critical(f"Failed to load modules [CORE]: {e}", exc_info=True)
            quit(1)
        return
コード例 #3
0
def run_client():
    try:
        log.info("Starting Telegram client")
        with tgclient:
            me = tgclient.loop.run_until_complete(tgclient.get_me())
            log.info(f"You're running {PROJECT} v{VERSION} as "
                     f"{me.first_name} (ID: {me.id})")
            tgclient.run_until_disconnected()
    except KeyboardInterrupt:
        raise KeyboardInterrupt
    except (BaseException, Exception) as e:
        log.critical(f"Client has stopped: {e}", exc_info=True)
    return
コード例 #4
0
def start_modules():
    if SAFEMODE:
        log.info("Starting system modules only")
    else:
        log.info("Starting modules")
    modules = _Modules()
    try:
        modules.import_load_modules()
    except KeyboardInterrupt:
        raise KeyboardInterrupt
    except (BaseException, Exception) as e:
        log.critical(f"Failed to start modules: {e}", exc_info=True)
    load_modules_count = modules.loaded_modules()
    sum_modules = len(getAllModules())
    if not load_modules_count:
        log.warning("No modules started!")
    elif load_modules_count > 0:
        log.info(f"Modules ({load_modules_count}/{sum_modules}) "
                 "started and ready!")
    return
コード例 #5
0
    except (BaseException, Exception) as e:
        if start_recovery:
            log.critical(f"Failed to reboot HyperUBot into recovery: {e}",
                         exc_info=True)
        else:
            log.critical(f"Failed to reboot HyperUBot: {e}",
                         exc_info=True)
    return


def main():
    start_modules()
    log.info("HyperUBot is going online")
    run_client()
    log.info("HyperUBot is offline")
    check_reboot()
    return


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        log.info("Keyboard interruption. Exiting...")
    except (BaseException, Exception) as e:
        log.critical(f"HyperUBot has stopped: {e}", exc_info=True)
        quit(1)
    finally:
        shutdown_logging()
    quit()
コード例 #6
0
ファイル: __main__.py プロジェクト: zeuslord224/HyperUBot
        modules.import_load_modules()
        load_modules_count = modules.loaded_modules()
        sum_modules = len(getAllModules())
        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. Exiting...")
    except Exception as e:
        log.critical(f"Unable to start HyperUBot: {e}", exc_info=True)

    try:
        # reboot reasons
        perf_reboot = getConfig("REBOOT", False)
        start_recovery = getConfig("START_RECOVERY", False)
        if perf_reboot or start_recovery:
            PY_EXEC = executable if not " " in executable else '"' + executable + '"'
            if perf_reboot:  # preferred if True
                if getConfig("REBOOT_SAFEMODE"):
                    log.info("Rebooting into safe mode...")
                    tcmd = [PY_EXEC, "-m", "userbot", "-safemode"]
                else:
                    log.info("Performing normal reboot...")
                    tcmd = [PY_EXEC, "-m", "userbot"]
            elif start_recovery:
コード例 #7
0
ファイル: __main__.py プロジェクト: soulr344/HyperUBot
        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