__main__.py 7.5 KB

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