def __list_all_modules(): # 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") and not f.endswith("__main__.py") ] if MOD_LOAD or MOD_NOLOAD: to_load = MOD_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!") sys.exit() else: to_load = all_modules if MOD_NOLOAD: log.info("No load: %s", MOD_NOLOAD) return [item for item in to_load if item not in MOD_NOLOAD] return to_load return all_modules
async def admin_cache_func(_, cmu: ChatMemberUpdated): if cmu.old_chat_member and cmu.old_chat_member.promoted_by: admins_in_chat[cmu.chat.id] = { "last_updated_at": time(), "data": [ member.user.id async for member in app.iter_chat_members( cmu.chat.id, filter="administrators") ], } log.info(f"Updated admin cache for {cmu.chat.id} [{cmu.chat.title}]")
async def rss_worker(): log.info("RSS Worker started") while True: feeds = await get_rss_feeds() if not feeds: await sleep(RSS_DELAY) continue loop = get_event_loop() for _feed in feeds: chat = _feed["chat_id"] try: url = _feed["url"] last_title = _feed.get("last_title") parsed = await loop.run_in_executor(None, parse, url) feed = Feed(parsed) if feed.title == last_title: continue await app.send_message( chat, feed.parsed(), disable_web_page_preview=True ) await update_rss_feed(chat, feed.title) except (ChannelInvalid, ChannelPrivate, InputUserDeactivated): await remove_rss_feed(chat) log.info(f"Removed RSS Feed from {chat} (Invalid Chat)") except Exception as e: log.info(f"RSS in {chat}: {str(e)}") pass await sleep(RSS_DELAY)
all_modules = [ basename(f)[:-3] for f in mod_paths if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py") and not f.endswith("__main__.py") ] if MOD_LOAD or MOD_NOLOAD: to_load = MOD_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!") sys.exit() else: to_load = all_modules if MOD_NOLOAD: log.info("No load: %s", MOD_NOLOAD) return [item for item in to_load if item not in MOD_NOLOAD] return to_load return all_modules importlib.import_module("wbb.modules.__main__") ALL_MODULES = sorted(__list_all_modules()) log.info("Modules loaded: %s", str(ALL_MODULES)) __all__ = ALL_MODULES + ["ALL_MODULES"]
async def start_bot(): global HELPABLE for module in ALL_MODULES: imported_module = importlib.import_module("wbb.modules." + module) if (hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__): imported_module.__MODULE__ = imported_module.__MODULE__ if (hasattr(imported_module, "__HELP__") and imported_module.__HELP__): HELPABLE[imported_module.__MODULE__.replace( " ", "_").lower()] = imported_module bot_modules = "" j = 1 for i in ALL_MODULES: if j == 4: bot_modules += "|{:<15}|\n".format(i) j = 0 else: bot_modules += "|{:<15}".format(i) j += 1 print("+===============================================================+") print("| WBB |") print("+===============+===============+===============+===============+") print(bot_modules) print("+===============+===============+===============+===============+") log.info(f"BOT STARTED AS {BOT_NAME}!") log.info(f"USERBOT STARTED AS {USERBOT_NAME}!") restart_data = await clean_restart_stage() try: log.info("Sending online status") if restart_data: await app.edit_message_text( restart_data["chat_id"], restart_data["message_id"], "**Restarted Successfully**", ) else: await app.send_message(LOG_GROUP_ID, "Bot started!") except Exception: pass await idle() await aiohttpsession.close() log.info("Stopping clients") await app.stop() log.info("Cancelling asyncio tasks") for task in asyncio.all_tasks(): task.cancel() log.info("Dead!")
<code>upload [URL or File Path]</code> → Upload a file from local or URL<br> <code>parse_preview [REPLY TO A MESSAGE]</code> → Parse a web_page(link) preview<br> <code>id</code> → Same as /id but for Ubot<br> <code>paste</code> → Paste shit on batbin.<br> <code>help</code> → Get link to this page.<br> <code>kang</code> → Kang stickers.<br> <code>dice</code> → Roll a dice.<br> """ log.info("Pasting userbot commands on telegraph") __HELP__ = f"""**Commands:** {telegraph.create_page( "Userbot Commands", html_content=TEXT, )['url']}""" log.info("Done pasting userbot commands on telegraph") @app2.on_message( filters.command("help", prefixes=USERBOT_PREFIX) & filters.user(USERBOT_ID) ) async def get_help(_, message: Message): await eor( message,