__main__.py 5.7 KB

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