__main__.py 5.8 KB

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