__main__.py 5.7 KB

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