__main__.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import asyncio
  2. import uvloop
  3. import re
  4. import importlib
  5. from pyrogram import filters, idle
  6. from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
  7. from wbb import app, MOD_NOLOAD
  8. from wbb.utils import random_line, get_info, paginate_modules, cust_filter
  9. from wbb.utils import botinfo
  10. from wbb.modules import ALL_MODULES
  11. loop = asyncio.get_event_loop()
  12. HELPABLE = {}
  13. async def start_bot():
  14. await app.start()
  15. await get_info(app)
  16. from wbb.utils import botinfo
  17. for module in ALL_MODULES:
  18. imported_module = importlib.import_module("wbb.modules." + module)
  19. if (
  20. hasattr(imported_module, "__MODULE__")
  21. and imported_module.__MODULE__
  22. ):
  23. if imported_module.__MODULE__.lower() in MOD_NOLOAD:
  24. continue
  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(cust_filter.command("start"))
  50. async def start(client, message):
  51. if message.chat.type != "private":
  52. await message.reply_text((await random_line("wbb/utils/start.txt")))
  53. return
  54. await message.reply("Get Some /help")
  55. @app.on_message(cust_filter.command("help"))
  56. async def help_command(_, message):
  57. if message.chat.type != "private":
  58. if len(message.command) >= 2 and message.command[1] == "help":
  59. text, keyboard = await help_parser(message)
  60. await message.reply(
  61. text, reply_markup=keyboard, disable_web_page_preview=True
  62. )
  63. return
  64. keyboard = InlineKeyboardMarkup(
  65. [
  66. [
  67. InlineKeyboardButton(
  68. text="Help",
  69. url="t.me/" + botinfo.BOT_USERNAME + "?start=help",
  70. )
  71. ]
  72. ]
  73. )
  74. await message.reply("Contact me in PM.", reply_markup=keyboard)
  75. return
  76. text, keyboard = await help_parser(message)
  77. await message.reply(
  78. text,
  79. reply_markup=keyboard,
  80. disable_web_page_preview=True
  81. )
  82. async def help_parser(message, keyboard=None):
  83. if not keyboard:
  84. keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
  85. return (
  86. "Hi {first_name}, I am {bot_name}".format(
  87. first_name=message.from_user.first_name,
  88. bot_name=botinfo.BOT_NAME,
  89. ),
  90. keyboard,
  91. )
  92. @app.on_callback_query(filters.regex(r"help_(.*?)"))
  93. async def help_button(c, q):
  94. mod_match = re.match(r"help_module\((.+?)\)", q.data)
  95. prev_match = re.match(r"help_prev\((.+?)\)", q.data)
  96. next_match = re.match(r"help_next\((.+?)\)", q.data)
  97. back_match = re.match(r"help_back", q.data)
  98. create_match = re.match(r"help_create", q.data)
  99. if mod_match:
  100. module = mod_match.group(1)
  101. text = (
  102. "{} **{}**:\n".format(
  103. "Here is the help for", HELPABLE[module].__MODULE__
  104. )
  105. + HELPABLE[module].__HELP__
  106. )
  107. await q.message.edit(
  108. text=text,
  109. reply_markup=InlineKeyboardMarkup(
  110. [[InlineKeyboardButton("back", callback_data="help_back")]]
  111. ),
  112. disable_web_page_preview=True,
  113. )
  114. elif prev_match:
  115. curr_page = int(prev_match.group(1))
  116. await q.message.edit(
  117. text="Hi {first_name}. I am {bot_name}".format(
  118. first_name=q.from_user.first_name,
  119. bot_name=botinfo.BOT_NAME,
  120. ),
  121. reply_markup=InlineKeyboardMarkup(
  122. paginate_modules(curr_page - 1, HELPABLE, "help")
  123. ),
  124. disable_web_page_preview=True,
  125. )
  126. elif next_match:
  127. next_page = int(next_match.group(1))
  128. await q.message.edit(
  129. text="Hi {first_name}. I am {bot_name}".format(
  130. first_name=q.from_user.first_name,
  131. bot_name=botinfo.BOT_NAME,
  132. ),
  133. reply_markup=InlineKeyboardMarkup(
  134. paginate_modules(next_page + 1, HELPABLE, "help")
  135. ),
  136. disable_web_page_preview=True,
  137. )
  138. elif back_match:
  139. await q.message.edit(
  140. text="Hi {first_name}. I am {bot_name}".format(
  141. first_name=q.from_user.first_name,
  142. bot_name=botinfo.BOT_NAME,
  143. ),
  144. reply_markup=InlineKeyboardMarkup(
  145. paginate_modules(0, HELPABLE, "help")
  146. ),
  147. disable_web_page_preview=True,
  148. )
  149. elif create_match:
  150. text, keyboard = await help_parser(q)
  151. await q.message.edit(
  152. text=text, reply_markup=keyboard, disable_web_page_preview=True
  153. )
  154. return await c.answer_callback_query(q.id)
  155. if __name__ == "__main__":
  156. uvloop.install()
  157. loop.run_until_complete(start_bot())