def __list_all_modules(): from os.path import dirname, basename, isfile import glob # This generates a list of modules in this folder for the * in __main__ to work. mod_paths = glob.glob(dirname(__file__) + "/*.py") all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith(".py") and not f.endswith('__init__.py') ] if USERBOT_LOAD or USERBOT_NOLOAD: to_load = USERBOT_LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load): log.error("Invalid Module name for userbot!") quit(1) else: to_load = all_modules if USERBOT_NOLOAD: log.info("Userbot No load: {}".format(USERBOT_NOLOAD)) return [item for item in to_load if item not in USERBOT_NOLOAD] return to_load return all_modules
def __list_all_modules(): from os.path import dirname, basename, isfile import glob # This generates a list of modules # in this folder for the * in __main__ to work. mod_paths = glob.glob(dirname(__file__) + '/*.py') all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith('.py') and not f.endswith('__init__.py') ] if ASSISTANT_LOAD or ASSISTANT_NOLOAD: to_load = ASSISTANT_LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load ): log.error('Invalid Module name for Assistant bot!') quit(1) else: to_load = all_modules if ASSISTANT_NOLOAD: log.info(f'Not loaded: {ASSISTANT_NOLOAD}') return [item for item in to_load if item not in ASSISTANT_NOLOAD] return to_load return all_modules
async def update_checker(): try: repo = Repo() except NoSuchPathError as error: log.warning(f'Check update failed!\nDirectory {error} is not found!') return except InvalidGitRepositoryError as error: log.warning( 'Check update failed!\nDirectory {} Not a git repository'.format( error, ), ) return except GitCommandError as error: log.warning(f'Check update failed!\n{error}') return brname = repo.active_branch.name if brname not in OFFICIAL_BRANCH: return try: repo.create_remote('upstream', REPOSITORY) except BaseException: pass upstream = repo.remote('upstream') upstream.fetch(brname) changelog = await gen_chlog(repo, f'HEAD..upstream/{brname}') if not changelog: log.info(f'Nana is up-to-date with branch {brname}') return log.warning(f'New UPDATE available for [{brname}]!') text = tld('updater_available_text').format(brname) text += f'**CHANGELOG:**\n`{changelog}`' button = InlineKeyboard(row_width=1) button.add( InlineKeyboardButton( tld('update_now_btn'), callback_data='update_now', ), ) await setbot.send_message( Owner, text, reply_markup=button, parse_mode='markdown', )
async def update_checker(): try: repo = Repo() except NoSuchPathError as error: log.warning(f"Check update failed!\nDirectory {error} is not found!") return except InvalidGitRepositoryError as error: log.warning( f"Check update failed!\nDirectory {error} does not seems to be a git repository" ) return except GitCommandError as error: log.warning(f"Check update failed!\n{error}") return brname = repo.active_branch.name if brname not in OFFICIAL_BRANCH: return try: repo.create_remote("upstream", REPOSITORY) except BaseException: pass upstream = repo.remote("upstream") upstream.fetch(brname) changelog = await gen_chlog(repo, f"HEAD..upstream/{brname}") if not changelog: log.info(f"Nana is up-to-date with branch {brname}") return log.warning(f"New UPDATE available for [{brname}]!") text = tld("updater_available_text").format(brname) text += f"**CHANGELOG:**\n`{changelog}`" button = InlineKeyboardMarkup([[ InlineKeyboardButton(tld("update_now_btn"), callback_data="update_now") ]]) await setbot.send_message(Owner, text, reply_markup=button, parse_mode="markdown")
async def start_bot(): # sys.excepthook = except_hook # print("----- Checking user and bot... -----") print("Checking userbot...") await reinitial() print("Check done, please wait...") # print("----------- Check done! ------------") # Assistant bot # Nana userbot await app.start() for modul in ALL_MODULES: imported_module = importlib.import_module("nana.modules." + modul) if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__: imported_module.__MODULE__ = imported_module.__MODULE__ log.info("-----------------------") log.info("Userbot modules: " + str(ALL_MODULES)) print("Module was loaded: " + ", ".join(ALL_MODULES)) log.info("-----------------------") log.warning("──「 Bot run successfully! 」──") if TEST_DEVELOP: log.warning("Test is passed!") else: await app.idle()
mod_paths = glob.glob(dirname(__file__) + "/*.py") all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith(".py") and not f.endswith('__init__.py') ] if USERBOT_LOAD or USERBOT_NOLOAD: to_load = USERBOT_LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load): log.error("Invalid Module name for userbot!") quit(1) else: to_load = all_modules if USERBOT_NOLOAD: log.info("Userbot No load: {}".format(USERBOT_NOLOAD)) return [item for item in to_load if item not in USERBOT_NOLOAD] return to_load return all_modules ALL_MODULES = sorted(__list_all_modules()) log.info("Userbot module loaded: %s", str(ALL_MODULES)) __all__ = ALL_MODULES + ["ALL_MODULES"]
async def start_bot(): # sys.excepthook = except_hook print("----- Checking user and bot... -----") await reinitial() print("----------- Check done! ------------") # Assistant bot await setbot.start() for setting in ALL_SETTINGS: imported_module = importlib.import_module("nana.assistant." + setting) # Nana userbot await app.start() for modul in ALL_MODULES: imported_module = importlib.import_module("nana.modules." + modul) if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__: imported_module.__MODULE__ = imported_module.__MODULE__ if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__: if not imported_module.__MODULE__.lower() in HELP_COMMANDS: HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module else: raise Exception("Can't have two modules with the same name! Please change one") if hasattr(imported_module, "__HELP__") and imported_module.__HELP__: HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module log.info("-----------------------") log.info("Userbot modules: " + str(ALL_MODULES)) log.info("-----------------------") log.info("Assistant modules: " + str(ALL_SETTINGS)) log.info("-----------------------") log.info("Bot run successfully!") if TEST_DEVELOP: log.warning("Test is passed!") else: await setbot.idle()
mod_paths = glob.glob(dirname(__file__) + "/*.py") all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith(".py") and not f.endswith('__init__.py') ] if ASSISTANT_LOAD or ASSISTANT_NOLOAD: to_load = ASSISTANT_LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load): log.error("Invalid Module name for Assistant bot!") quit(1) else: to_load = all_modules if ASSISTANT_NOLOAD: log.info("Not loaded: {}".format(ASSISTANT_NOLOAD)) return [item for item in to_load if item not in ASSISTANT_NOLOAD] return to_load return all_modules ALL_SETTINGS = sorted(__list_all_modules()) log.info("Assistant bot module loaded: %s", str(ALL_SETTINGS)) __all__ = ALL_SETTINGS + ["ALL_SETTINGS"]
mod_paths = glob.glob(dirname(__file__) + '/*.py') all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith('.py') and not f.endswith('__init__.py') ] if USERBOT_LOAD or USERBOT_NOLOAD: to_load = USERBOT_LOAD if to_load: if not all( any(mod == module_name for module_name in all_modules) for mod in to_load): log.error('Invalid Module name for userbot!') quit(1) else: to_load = all_modules if USERBOT_NOLOAD: log.info(f'Userbot No load: {USERBOT_NOLOAD}') return [item for item in to_load if item not in USERBOT_NOLOAD] return to_load return all_modules ALL_MODULES = sorted(__list_all_modules()) log.info('Userbot module loaded: %s', str(ALL_MODULES)) __all__ = ALL_MODULES + ['ALL_MODULES']