__main__.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import asyncio
  2. import re
  3. import importlib
  4. import uvloop
  5. from pyrogram import filters, idle
  6. from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
  7. from wbb import app, app2, BOT_NAME, BOT_USERNAME
  8. from wbb.utils import paginate_modules
  9. from wbb.modules.sudoers import bot_sys_stats
  10. from wbb.modules import ALL_MODULES
  11. loop = asyncio.get_event_loop()
  12. HELPABLE = {}
  13. async def start_bot():
  14. global COMMANDS_COUNT
  15. for module in ALL_MODULES:
  16. imported_module = importlib.import_module("wbb.modules." + module)
  17. if (
  18. hasattr(imported_module, "__MODULE__")
  19. and imported_module.__MODULE__
  20. ):
  21. imported_module.__MODULE__ = imported_module.__MODULE__
  22. if (
  23. hasattr(imported_module, "__HELP__")
  24. and imported_module.__HELP__
  25. ):
  26. HELPABLE[
  27. imported_module.__MODULE__.lower()
  28. ] = imported_module
  29. bot_modules = ""
  30. j = 1
  31. for i in ALL_MODULES:
  32. if j == 4:
  33. bot_modules += "|{:<15}|\n".format(i)
  34. j = 0
  35. else:
  36. bot_modules += "|{:<15}".format(i)
  37. j += 1
  38. print("+===============================================================+")
  39. print("| WBB - Modules |")
  40. print("+===============+===============+===============+===============+")
  41. print(bot_modules)
  42. print("+===============+===============+===============+===============+")
  43. print("Bot Started Successfully as {}!".format(BOT_NAME))
  44. await idle()
  45. @app.on_message(filters.command(["help", "start"]))
  46. async def help_command(_, message):
  47. if message.chat.type != "private":
  48. if len(message.command) >= 2 and message.command[1] == "help":
  49. text, keyboard = await help_parser(message)
  50. await message.reply(
  51. text, reply_markup=keyboard, disable_web_page_preview=True
  52. )
  53. return
  54. keyboard = InlineKeyboardMarkup(
  55. [
  56. [
  57. InlineKeyboardButton(
  58. text="Help ❓",
  59. url=f"t.me/{BOT_USERNAME}?start=help",
  60. ),
  61. InlineKeyboardButton(
  62. text="Repo 🛠",
  63. url="https://github.com/thehamkercat/WilliamButcherBot",
  64. )
  65. ],
  66. [
  67. InlineKeyboardButton(
  68. text="System Stats 💻",
  69. callback_data="stats_callback"
  70. ),
  71. InlineKeyboardButton(
  72. text="Support 👨",
  73. url="t.me/PatheticProgrammers"
  74. )
  75. ]
  76. ]
  77. )
  78. await message.reply("Pm Me For More Details.", reply_markup=keyboard)
  79. return
  80. keyboard = InlineKeyboardMarkup(
  81. [
  82. [
  83. InlineKeyboardButton(
  84. text="Commands ❓",
  85. callback_data="bot_commands"
  86. ),
  87. InlineKeyboardButton(
  88. text="Repo 🛠",
  89. url="https://github.com/thehamkercat/WilliamButcherBot"
  90. )
  91. ],
  92. [
  93. InlineKeyboardButton(
  94. text="System Stats 🖥",
  95. callback_data="stats_callback"
  96. ),
  97. InlineKeyboardButton(
  98. text="Support 👨",
  99. url="t.me/PatheticProgrammers"
  100. )
  101. ],
  102. [
  103. InlineKeyboardButton(
  104. text="Add Me To Your Group 🎉",
  105. url=f"http://t.me/{BOT_USERNAME}?startgroup=new"
  106. )
  107. ]
  108. ]
  109. )
  110. await message.reply(f"Hey there! My name is {BOT_NAME}. I can manage your group with lots of useful features, feel free to add me to your group.", reply_markup=keyboard)
  111. async def help_parser(name, keyboard=None):
  112. if not keyboard:
  113. keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
  114. return (
  115. """Hello {first_name}! My name is {bot_name}!
  116. I'm a group management bot with some usefule features.
  117. You can choose an option below, by clicking a button.
  118. Also you can ask anything in Support Group.
  119. General command are:
  120. - /start: Start the bot
  121. - /help: Give this message""".format(
  122. first_name=name,
  123. bot_name=BOT_NAME,
  124. ),
  125. keyboard,
  126. )
  127. @app.on_callback_query(filters.regex("bot_commands"))
  128. async def commands_callbacc(_, CallbackQuery):
  129. text, keyboard = await help_parser(CallbackQuery.from_user.mention)
  130. await app.send_message(
  131. CallbackQuery.message.chat.id,
  132. text=text,
  133. reply_markup=keyboard
  134. )
  135. await CallbackQuery.message.delete()
  136. @app.on_callback_query(filters.regex("stats_callback"))
  137. async def stats_callbacc(_, CallbackQuery):
  138. text = await bot_sys_stats()
  139. await app.answer_callback_query(CallbackQuery.id, text, show_alert=True)
  140. @app.on_callback_query(filters.regex(r"help_(.*?)"))
  141. async def help_button(client, query):
  142. mod_match = re.match(r"help_module\((.+?)\)", query.data)
  143. prev_match = re.match(r"help_prev\((.+?)\)", query.data)
  144. next_match = re.match(r"help_next\((.+?)\)", query.data)
  145. back_match = re.match(r"help_back", query.data)
  146. create_match = re.match(r"help_create", query.data)
  147. if mod_match:
  148. module = mod_match.group(1)
  149. text = (
  150. "{} **{}**:\n".format(
  151. "Here is the help for", HELPABLE[module].__MODULE__
  152. )
  153. + HELPABLE[module].__HELP__
  154. )
  155. await query.message.edit(
  156. text=text,
  157. reply_markup=InlineKeyboardMarkup(
  158. [[InlineKeyboardButton("back", callback_data="help_back")]]
  159. ),
  160. disable_web_page_preview=True,
  161. )
  162. elif prev_match:
  163. curr_page = int(prev_match.group(1))
  164. await query.message.edit(
  165. text="Hi {first_name}. I am {bot_name}".format(
  166. first_name=query.from_user.first_name,
  167. bot_name=BOT_NAME,
  168. ),
  169. reply_markup=InlineKeyboardMarkup(
  170. paginate_modules(curr_page - 1, HELPABLE, "help")
  171. ),
  172. disable_web_page_preview=True,
  173. )
  174. elif next_match:
  175. next_page = int(next_match.group(1))
  176. await query.message.edit(
  177. text="Hi {first_name}. I am {bot_name}".format(
  178. first_name=query.from_user.first_name,
  179. bot_name=BOT_NAME,
  180. ),
  181. reply_markup=InlineKeyboardMarkup(
  182. paginate_modules(next_page + 1, HELPABLE, "help")
  183. ),
  184. disable_web_page_preview=True,
  185. )
  186. elif back_match:
  187. await query.message.edit(
  188. text="Hi {first_name}. I am {bot_name}".format(
  189. first_name=query.from_user.first_name,
  190. bot_name=BOT_NAME,
  191. ),
  192. reply_markup=InlineKeyboardMarkup(
  193. paginate_modules(0, HELPABLE, "help")
  194. ),
  195. disable_web_page_preview=True,
  196. )
  197. elif create_match:
  198. text, keyboard = await help_parser(query)
  199. await query.message.edit(
  200. text=text, reply_markup=keyboard, disable_web_page_preview=True
  201. )
  202. return await client.answer_callback_query(query.id)
  203. if __name__ == "__main__":
  204. uvloop.install()
  205. loop.run_until_complete(start_bot())