__main__.py 5.6 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
  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. bot_uptime = int(time.time() - bot_start_time)
  52. if message.chat.type != "private":
  53. await message.reply_text(f'Already Online Since {bot_uptime}')
  54. return
  55. await message.reply("Get Some /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(
  79. text,
  80. reply_markup=keyboard,
  81. disable_web_page_preview=True
  82. )
  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(c, q):
  95. mod_match = re.match(r"help_module\((.+?)\)", q.data)
  96. prev_match = re.match(r"help_prev\((.+?)\)", q.data)
  97. next_match = re.match(r"help_next\((.+?)\)", q.data)
  98. back_match = re.match(r"help_back", q.data)
  99. create_match = re.match(r"help_create", q.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 q.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 q.message.edit(
  118. text="Hi {first_name}. I am {bot_name}".format(
  119. first_name=q.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 q.message.edit(
  130. text="Hi {first_name}. I am {bot_name}".format(
  131. first_name=q.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 q.message.edit(
  141. text="Hi {first_name}. I am {bot_name}".format(
  142. first_name=q.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(q)
  152. await q.message.edit(
  153. text=text, reply_markup=keyboard, disable_web_page_preview=True
  154. )
  155. return await c.answer_callback_query(q.id)
  156. if __name__ == "__main__":
  157. uvloop.install()
  158. loop.run_until_complete(start_bot())