__main__.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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
  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. await main_bot()
  17. for modul in ALL_MODULES:
  18. imported_module = importlib.import_module("wbb.modules." + modul)
  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 run successfully as {}!".format(botinfo.BOT_NAME))
  40. await idle()
  41. async def main_bot():
  42. from wbb.utils import botinfo
  43. @app.on_message(cust_filter.command("start"))
  44. async def start(client, message):
  45. if message.chat.type != "private":
  46. await message.reply("Message me Privately *winks*")
  47. return
  48. await message.reply("Hi, try /help")
  49. @app.on_message(cust_filter.command("help"))
  50. async def help_command(_, message):
  51. if message.chat.type != "private":
  52. if len(message.command) >= 2 and message.command[1] == "help":
  53. text, keyboard = await help_parser(message)
  54. await message.reply(
  55. text, reply_markup=keyboard, disable_web_page_preview=True
  56. )
  57. return
  58. keyboard = InlineKeyboardMarkup(
  59. [
  60. [
  61. InlineKeyboardButton(
  62. text="Help",
  63. url="t.me/" + botinfo.BOT_USERNAME + "?start=help",
  64. )
  65. ]
  66. ]
  67. )
  68. await message.reply("Contact me at PM.", reply_markup=keyboard)
  69. return
  70. text, keyboard = await help_parser(message)
  71. await message.reply(text, reply_markup=keyboard, disable_web_page_preview=True)
  72. async def help_parser(message, keyboard=None):
  73. if not keyboard:
  74. keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
  75. return (
  76. "Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
  77. first_name=message.from_user.first_name,
  78. bot_name=botinfo.BOT_NAME,
  79. commands=", ".join(Command),
  80. ),
  81. keyboard,
  82. )
  83. @app.on_callback_query(filters.regex(r"help_(.*?)"))
  84. async def help_button(c, q):
  85. mod_match = re.match(r"help_module\((.+?)\)", q.data)
  86. prev_match = re.match(r"help_prev\((.+?)\)", q.data)
  87. next_match = re.match(r"help_next\((.+?)\)", q.data)
  88. back_match = re.match(r"help_back", q.data)
  89. create_match = re.match(r"help_create", q.data)
  90. if mod_match:
  91. module = mod_match.group(1)
  92. text = (
  93. "{} **{}**:\n".format(
  94. "Here is the help for", HELPABLE[module].__MODULE__
  95. )
  96. + HELPABLE[module].__HELP__
  97. )
  98. await q.message.edit(
  99. text=text,
  100. reply_markup=InlineKeyboardMarkup(
  101. [[InlineKeyboardButton("back", callback_data="help_back")]]
  102. ),
  103. disable_web_page_preview=True,
  104. )
  105. elif prev_match:
  106. curr_page = int(prev_match.group(1))
  107. await q.message.edit(
  108. text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
  109. first_name=q.from_user.first_name,
  110. bot_name=botinfo.BOT_NAME,
  111. commands=", ".join(Command),
  112. ),
  113. reply_markup=InlineKeyboardMarkup(
  114. paginate_modules(curr_page - 1, HELPABLE, "help")
  115. ),
  116. disable_web_page_preview=True,
  117. )
  118. elif next_match:
  119. next_page = int(next_match.group(1))
  120. await q.message.edit(
  121. text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
  122. first_name=q.from_user.first_name,
  123. bot_name=botinfo.BOT_NAME,
  124. commands=", ".join(Command),
  125. ),
  126. reply_markup=InlineKeyboardMarkup(
  127. paginate_modules(next_page + 1, HELPABLE, "help")
  128. ),
  129. disable_web_page_preview=True,
  130. )
  131. elif back_match:
  132. await q.message.edit(
  133. text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
  134. first_name=q.from_user.first_name,
  135. bot_name=botinfo.BOT_NAME,
  136. commands=", ".join(Command),
  137. ),
  138. reply_markup=InlineKeyboardMarkup(
  139. paginate_modules(0, HELPABLE, "help")
  140. ),
  141. disable_web_page_preview=True,
  142. )
  143. elif create_match:
  144. text, keyboard = await help_parser(q)
  145. await q.message.edit(
  146. text=text, reply_markup=keyboard, disable_web_page_preview=True
  147. )
  148. return await c.answer_callback_query(q.id)
  149. if __name__ == "__main__":
  150. uvloop.install()
  151. loop.run_until_complete(start_bot())