|
| 1 | +from pyrogram import idle, Client |
| 2 | + |
| 3 | +from pyrogrambot import app, filters |
| 4 | +from pyrogrambot.utils.misc import count_modules |
| 5 | + |
| 6 | +from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup |
| 7 | + |
| 8 | +import importlib |
| 9 | +import re |
| 10 | + |
| 11 | +#Bot info |
| 12 | + |
| 13 | +async def get_info(app): |
| 14 | + global BOT_ID, BOT_NAME, BOT_USERNAME, BOT_DC_ID |
| 15 | + getme = await app.get_me() |
| 16 | + BOT_ID = getme.id |
| 17 | + |
| 18 | + if getme.last_name: |
| 19 | + BOT_NAME = getme.first_name + " " + getme.last_name |
| 20 | + else: |
| 21 | + BOT_NAME = getme.first_name |
| 22 | + BOT_USERNAME = getme.username |
| 23 | + BOT_DC_ID = getme.dc_id |
| 24 | + |
| 25 | +#Help [Taken From WBB] |
| 26 | + |
| 27 | +HELPABLE = {} |
| 28 | + |
| 29 | + |
| 30 | +async def start_bot(): |
| 31 | + await app.start() |
| 32 | + await get_info(app) |
| 33 | + |
| 34 | + for module in ALL_MODULES: |
| 35 | + imported_module = importlib.import_module("PyrogramBot.modules." + module) |
| 36 | + if ( |
| 37 | + hasattr(imported_module, "__MODULE__") |
| 38 | + and imported_module.__MODULE__ |
| 39 | + ): |
| 40 | + imported_module.__MODULE__ = imported_module.__MODULE__ |
| 41 | + if ( |
| 42 | + hasattr(imported_module, "__HELP__") |
| 43 | + and imported_module.__HELP__ |
| 44 | + ): |
| 45 | + HELPABLE[ |
| 46 | + imported_module.__MODULE__.lower() |
| 47 | + ] = imported_module |
| 48 | + |
| 49 | + bot_modules = "" |
| 50 | + j = 1 |
| 51 | + for i in ALL_MODULES: |
| 52 | + if j == 4: |
| 53 | + bot_modules += "|{:<15}|\n".format(i) |
| 54 | + j = 0 |
| 55 | + else: |
| 56 | + bot_modules += "|{:<15}".format(i) |
| 57 | + j += 1 |
| 58 | + print(">>------------|•|-----------<<") |
| 59 | + print(f">>------|• {BOT_NAME} •|-----<<") |
| 60 | + print(">>------------|•|-----------<<") |
| 61 | + print(bot_modules) |
| 62 | + print("Bot is Up, Game ON!!") |
| 63 | + await idle() |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +@app.on_message(filters.command("help")) |
| 69 | +async def help_command(_, message): |
| 70 | + if message.chat.type != "private": |
| 71 | + if len(message.command) >= 2 and message.command[1] == "help": |
| 72 | + text, keyboard = await help_parser(message) |
| 73 | + await message.reply( |
| 74 | + text, reply_markup=keyboard, disable_web_page_preview=True |
| 75 | + ) |
| 76 | + return |
| 77 | + keyboard = InlineKeyboardMarkup( |
| 78 | + [ |
| 79 | + [ |
| 80 | + InlineKeyboardButton( |
| 81 | + text="Help", |
| 82 | + url=f"t.me/{BOT_USERNAME}?start=help", |
| 83 | + ) |
| 84 | + ] |
| 85 | + ] |
| 86 | + ) |
| 87 | + await message.reply("Contact me in PM.", reply_markup=keyboard) |
| 88 | + return |
| 89 | + text, keyboard = await help_parser(message) |
| 90 | + await message.reply_text(text, reply_markup=keyboard) |
| 91 | + |
| 92 | + |
| 93 | +async def help_parser(message, keyboard=None): |
| 94 | + if not keyboard: |
| 95 | + keyboard = InlineKeyboardMarkup(count_modules(0, HELPABLE, "help")) |
| 96 | + return ( |
| 97 | + "Hi {first_name}, I am a bot".format( |
| 98 | + first_name=message.from_user.first_name, |
| 99 | + ), |
| 100 | + keyboard, |
| 101 | + ) |
| 102 | + |
| 103 | + |
| 104 | +@app.on_callback_query(filters.regex(r"help_(.*?)")) |
| 105 | +async def help_button(client, query): |
| 106 | + mod_match = re.match(r"help_module\((.+?)\)", query.data) |
| 107 | + prev_match = re.match(r"help_prev\((.+?)\)", query.data) |
| 108 | + next_match = re.match(r"help_next\((.+?)\)", query.data) |
| 109 | + back_match = re.match(r"help_back", query.data) |
| 110 | + create_match = re.match(r"help_create", query.data) |
| 111 | + |
| 112 | + if mod_match: |
| 113 | + module = mod_match.group(1) |
| 114 | + text = ( |
| 115 | + "{} **{}**:\n".format( |
| 116 | + "Here is the help for", HELPABLE[module].__MODULE__ |
| 117 | + ) |
| 118 | + + HELPABLE[module].__HELP__ |
| 119 | + ) |
| 120 | + |
| 121 | + await query.message.edit( |
| 122 | + text=text, |
| 123 | + reply_markup=InlineKeyboardMarkup( |
| 124 | + [[InlineKeyboardButton("back", callback_data="help_back")]] |
| 125 | + ), |
| 126 | + disable_web_page_preview=True, |
| 127 | + ) |
| 128 | + |
| 129 | + elif prev_match: |
| 130 | + curr_page = int(prev_match.group(1)) |
| 131 | + await query.message.edit( |
| 132 | + text="Hi {first_name}. I am bot".format( |
| 133 | + first_name=query.from_user.first_name, |
| 134 | + ), |
| 135 | + reply_markup=InlineKeyboardMarkup( |
| 136 | + count_modules(curr_page - 1, HELPABLE, "help") |
| 137 | + ), |
| 138 | + disable_web_page_preview=True, |
| 139 | + ) |
| 140 | + |
| 141 | + elif next_match: |
| 142 | + next_page = int(next_match.group(1)) |
| 143 | + await query.message.edit( |
| 144 | + text="Hi {first_name}. I am a bot".format( |
| 145 | + first_name=query.from_user.first_name, |
| 146 | + ), |
| 147 | + reply_markup=InlineKeyboardMarkup( |
| 148 | + count_modules(next_page + 1, HELPABLE, "help") |
| 149 | + ), |
| 150 | + disable_web_page_preview=True, |
| 151 | + ) |
| 152 | + |
| 153 | + elif back_match: |
| 154 | + await query.message.edit( |
| 155 | + text="Hi {first_name}. I am a bot".format( |
| 156 | + first_name=query.from_user.first_name, |
| 157 | + ), |
| 158 | + reply_markup=InlineKeyboardMarkup( |
| 159 | + count_modules(0, HELPABLE, "help") |
| 160 | + ), |
| 161 | + disable_web_page_preview=True, |
| 162 | + ) |
| 163 | + |
| 164 | + elif create_match: |
| 165 | + text, keyboard = await help_parser(query) |
| 166 | + await query.message.edit( |
| 167 | + text=text, reply_markup=keyboard, disable_web_page_preview=True |
| 168 | + ) |
| 169 | + |
| 170 | + return await client.answer_callback_query(query.id) |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | +if __name__ == "__main__": |
| 175 | + app.start() |
| 176 | + idle() |
0 commit comments