__main__.py 7.6 KB

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