__main__.py 6.4 KB

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