__main__.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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, Command
  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 hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__:
  20. if imported_module.__MODULE__.lower() in MOD_NOLOAD:
  21. continue
  22. imported_module.__MODULE__ = imported_module.__MODULE__
  23. if hasattr(imported_module, "__HELP__") and imported_module.__HELP__:
  24. HELPABLE[imported_module.__MODULE__.lower()] = imported_module
  25. bot_modules = ""
  26. j = 1
  27. for i in ALL_MODULES:
  28. if j == 4:
  29. bot_modules += "|{:<15}|\n".format(i)
  30. j = 0
  31. else:
  32. bot_modules += "|{:<15}".format(i)
  33. j += 1
  34. print("+===============================================================+")
  35. print("| WBB - Modules |")
  36. print("+===============+===============+===============+===============+")
  37. print(bot_modules)
  38. print("+===============+===============+===============+===============+")
  39. print("Bot Started Successfully as {}!".format(botinfo.BOT_NAME))
  40. await idle()
  41. @app.on_message(cust_filter.command("start"))
  42. async def start(client, message):
  43. if message.chat.type != "private":
  44. await message.reply_text((await random_line("wbb/utils/start.txt")))
  45. return
  46. await message.reply("Hi, try /help")
  47. @app.on_message(cust_filter.command("help"))
  48. async def help_command(_, message):
  49. if message.chat.type != "private":
  50. if len(message.command) >= 2 and message.command[1] == "help":
  51. text, keyboard = await help_parser(message)
  52. await message.reply(
  53. text, reply_markup=keyboard, disable_web_page_preview=True
  54. )
  55. return
  56. keyboard = InlineKeyboardMarkup(
  57. [
  58. [
  59. InlineKeyboardButton(
  60. text="Help",
  61. url="t.me/" + botinfo.BOT_USERNAME + "?start=help",
  62. )
  63. ]
  64. ]
  65. )
  66. await message.reply("Contact me in PM.", reply_markup=keyboard)
  67. return
  68. text, keyboard = await help_parser(message)
  69. await message.reply(
  70. text,
  71. reply_markup=keyboard,
  72. disable_web_page_preview=True
  73. )
  74. async def help_parser(message, keyboard=None):
  75. if not keyboard:
  76. keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
  77. return (
  78. "Hi {first_name}, I am {bot_name}".format(
  79. first_name=message.from_user.first_name,
  80. bot_name=botinfo.BOT_NAME,
  81. commands=", ".join(Command),
  82. ),
  83. keyboard,
  84. )
  85. @app.on_callback_query(filters.regex(r"help_(.*?)"))
  86. async def help_button(c, q):
  87. mod_match = re.match(r"help_module\((.+?)\)", q.data)
  88. prev_match = re.match(r"help_prev\((.+?)\)", q.data)
  89. next_match = re.match(r"help_next\((.+?)\)", q.data)
  90. back_match = re.match(r"help_back", q.data)
  91. create_match = re.match(r"help_create", q.data)
  92. if mod_match:
  93. module = mod_match.group(1)
  94. text = (
  95. "{} **{}**:\n".format(
  96. "Here is the help for", HELPABLE[module].__MODULE__
  97. )
  98. + HELPABLE[module].__HELP__
  99. )
  100. await q.message.edit(
  101. text=text,
  102. reply_markup=InlineKeyboardMarkup(
  103. [[InlineKeyboardButton("back", callback_data="help_back")]]
  104. ),
  105. disable_web_page_preview=True,
  106. )
  107. elif prev_match:
  108. curr_page = int(prev_match.group(1))
  109. await q.message.edit(
  110. text="Hi {first_name}. I am {bot_name}".format(
  111. first_name=q.from_user.first_name,
  112. bot_name=botinfo.BOT_NAME,
  113. commands=", ".join(Command),
  114. ),
  115. reply_markup=InlineKeyboardMarkup(
  116. paginate_modules(curr_page - 1, HELPABLE, "help")
  117. ),
  118. disable_web_page_preview=True,
  119. )
  120. elif next_match:
  121. next_page = int(next_match.group(1))
  122. await q.message.edit(
  123. text="Hi {first_name}. I am {bot_name}".format(
  124. first_name=q.from_user.first_name,
  125. bot_name=botinfo.BOT_NAME,
  126. commands=", ".join(Command),
  127. ),
  128. reply_markup=InlineKeyboardMarkup(
  129. paginate_modules(next_page + 1, HELPABLE, "help")
  130. ),
  131. disable_web_page_preview=True,
  132. )
  133. elif back_match:
  134. await q.message.edit(
  135. text="Hi {first_name}. I am {bot_name}".format(
  136. first_name=q.from_user.first_name,
  137. bot_name=botinfo.BOT_NAME,
  138. commands=", ".join(Command),
  139. ),
  140. reply_markup=InlineKeyboardMarkup(
  141. paginate_modules(0, HELPABLE, "help")
  142. ),
  143. disable_web_page_preview=True,
  144. )
  145. elif create_match:
  146. text, keyboard = await help_parser(q)
  147. await q.message.edit(
  148. text=text, reply_markup=keyboard, disable_web_page_preview=True
  149. )
  150. return await c.answer_callback_query(q.id)
  151. if __name__ == "__main__":
  152. uvloop.install()
  153. loop.run_until_complete(start_bot())