__main__.py 7.7 KB

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