| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- import asyncio
- import re
- import importlib
- import time
- import uvloop
- from pyrogram import filters, idle
- from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
- from wbb import app, MOD_NOLOAD
- from wbb.utils import get_info, paginate_modules
- from wbb.utils import botinfo, formatter
- from wbb.modules.sudoers import bot_sys_stats
- from wbb.modules import ALL_MODULES
- from wbb import bot_start_time
- loop = asyncio.get_event_loop()
- HELPABLE = {}
- async def start_bot():
- await app.start()
- await get_info(app)
- for module in ALL_MODULES:
- imported_module = importlib.import_module("wbb.modules." + module)
- if (
- hasattr(imported_module, "__MODULE__")
- and imported_module.__MODULE__
- ):
- if imported_module.__MODULE__.lower() in MOD_NOLOAD:
- continue
- imported_module.__MODULE__ = imported_module.__MODULE__
- if (
- hasattr(imported_module, "__HELP__")
- and imported_module.__HELP__
- ):
- HELPABLE[
- imported_module.__MODULE__.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 - Modules |")
- print("+===============+===============+===============+===============+")
- print(bot_modules)
- print("+===============+===============+===============+===============+")
- print("Bot Started Successfully as {}!".format(botinfo.BOT_NAME))
- await idle()
- @app.on_message(filters.command("start"))
- async def start(_, message):
- bot_uptime = int(time.time() - bot_start_time)
- await message.reply_text(
- f"Already Online Since {formatter.get_readable_time((bot_uptime))},"
- " Maybe Try /help")
- @app.on_message(filters.command("help"))
- async def help_command(_, message):
- if message.chat.type != "private":
- if len(message.command) >= 2 and message.command[1] == "help":
- text, keyboard = await help_parser(message)
- await message.reply(
- text, reply_markup=keyboard, disable_web_page_preview=True
- )
- return
- keyboard = InlineKeyboardMarkup(
- [
- [
- InlineKeyboardButton(
- text="Help",
- url=f"t.me/{botinfo.BOT_USERNAME}?start=help",
- ),
- InlineKeyboardButton(
- text="Repo",
- url="https://github.com/thehamkercat/WilliamButcherBot",
- )
- ],
- [
- InlineKeyboardButton(
- text="System Stats",
- callback_data="stats_callback"
- ),
- InlineKeyboardButton(
- text="Support",
- url="t.me/PatheticProgrammers"
- )
- ]
- ]
- )
- await message.reply("Pm Me For More Details.", reply_markup=keyboard)
- return
- text, keyboard = await help_parser(message)
- await message.reply_photo(
- caption=text,
- photo="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
- reply_markup=keyboard
- )
- async def help_parser(message, keyboard=None):
- if not keyboard:
- keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
- return (
- "Hi {first_name}, I am {bot_name}, A well written telegram group manager bot, Invite me to your chat.".format(
- first_name=message.from_user.first_name,
- bot_name=botinfo.BOT_NAME,
- ),
- keyboard,
- )
- @app.on_callback_query(filters.regex("stats_callback"))
- async def end_callbacc(_, CallbackQuery):
- text = await bot_sys_stats()
- await app.answer_callback_query(CallbackQuery.id, text, show_alert=True)
- @app.on_callback_query(filters.regex(r"help_(.*?)"))
- async def help_button(client, query):
- mod_match = re.match(r"help_module\((.+?)\)", query.data)
- prev_match = re.match(r"help_prev\((.+?)\)", query.data)
- next_match = re.match(r"help_next\((.+?)\)", query.data)
- back_match = re.match(r"help_back", query.data)
- create_match = re.match(r"help_create", query.data)
- if mod_match:
- module = mod_match.group(1)
- text = (
- "{} **{}**:\n".format(
- "Here is the help for", HELPABLE[module].__MODULE__
- )
- + HELPABLE[module].__HELP__
- )
- await query.message.edit(
- text=text,
- reply_markup=InlineKeyboardMarkup(
- [[InlineKeyboardButton("back", callback_data="help_back")]]
- ),
- disable_web_page_preview=True,
- )
- elif prev_match:
- curr_page = int(prev_match.group(1))
- await query.message.edit(
- text="Hi {first_name}. I am {bot_name}".format(
- first_name=query.from_user.first_name,
- bot_name=botinfo.BOT_NAME,
- ),
- reply_markup=InlineKeyboardMarkup(
- paginate_modules(curr_page - 1, HELPABLE, "help")
- ),
- disable_web_page_preview=True,
- )
- elif next_match:
- next_page = int(next_match.group(1))
- await query.message.edit(
- text="Hi {first_name}. I am {bot_name}".format(
- first_name=query.from_user.first_name,
- bot_name=botinfo.BOT_NAME,
- ),
- reply_markup=InlineKeyboardMarkup(
- paginate_modules(next_page + 1, HELPABLE, "help")
- ),
- disable_web_page_preview=True,
- )
- elif back_match:
- await query.message.edit(
- text="Hi {first_name}. I am {bot_name}".format(
- first_name=query.from_user.first_name,
- bot_name=botinfo.BOT_NAME,
- ),
- reply_markup=InlineKeyboardMarkup(
- paginate_modules(0, HELPABLE, "help")
- ),
- disable_web_page_preview=True,
- )
- elif create_match:
- text, keyboard = await help_parser(query)
- await query.message.edit(
- text=text, reply_markup=keyboard, disable_web_page_preview=True
- )
- return await client.answer_callback_query(query.id)
- if __name__ == "__main__":
- uvloop.install()
- loop.run_until_complete(start_bot())
|