inline.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import sys
  2. from wbb import app, app2, SUDOERS, USERBOT_USERNAME, BOT_USERNAME
  3. from wbb.utils.errors import capture_err
  4. from pykeyboard import InlineKeyboard
  5. from sys import version as pyver
  6. from motor import version as mongover
  7. from pyrogram import __version__ as pyrover
  8. from pyrogram import filters
  9. from pyrogram.types import (
  10. InlineQueryResultArticle,
  11. InputTextMessageContent,
  12. InlineKeyboardButton
  13. )
  14. from googletrans import Translator
  15. __MODULE__ = "Inline"
  16. __HELP__ = """
  17. tr [LANGUAGE] [QUERY] Translate Text.
  18. alive - Check Bot's Stats."""
  19. """ Inspiration From https://github.com/pokurt/Nana-Remix/blob/master/nana/plugins/assistant/inline_mod/alive.py """
  20. async def alive_function(answers):
  21. buttons = InlineKeyboard(row_width=1)
  22. bot_state = 'Dead' if not await app.get_me() else 'Alive'
  23. ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
  24. buttons.add(InlineKeyboardButton('Stats', callback_data='stats_callback'))
  25. msg = f"""
  26. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  27. **MainBot:** `{bot_state}`
  28. **UserBot:** `{ubot_state}`
  29. **Python:** `{pyver.split()[0]}`
  30. **Pyrogram:** `{pyrover}`
  31. **MongoDB:** `{mongover}`
  32. **Platform:** `{sys.platform}`
  33. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  34. """
  35. answers.append(
  36. InlineQueryResultArticle(
  37. title='Alive',
  38. description="Check Bot's Stats",
  39. input_message_content=InputTextMessageContent(
  40. msg,
  41. disable_web_page_preview=True
  42. ),
  43. reply_markup=buttons,
  44. )
  45. )
  46. return answers
  47. async def translate_func(answers, lang, tex):
  48. i = Translator().translate(tex, dest=lang)
  49. msg = f"""
  50. __**Translated to {lang}**__
  51. **INPUT:**
  52. {tex}
  53. **OUTPUT:**
  54. {i.text}"""
  55. answers.append(
  56. InlineQueryResultArticle(
  57. title=f'Translated to {lang}',
  58. description=i.text,
  59. input_message_content=InputTextMessageContent(
  60. msg
  61. )
  62. )
  63. )
  64. return answers
  65. @app.on_inline_query()
  66. async def inline_query_handler(client, query):
  67. try:
  68. text = query.query.lower()
  69. answers = []
  70. if text == '':
  71. await client.answer_inline_query(
  72. query.id,
  73. results=answers,
  74. switch_pm_text='Commands',
  75. switch_pm_parameter='help',
  76. )
  77. return
  78. elif text == "alive":
  79. answerss = await alive_function(answers)
  80. await client.answer_inline_query(
  81. query.id,
  82. results=answerss,
  83. cache_time=10
  84. )
  85. elif text.split()[0] == "tr":
  86. lang = text.split()[1]
  87. tex = text.split(None, 2)[2]
  88. answerss = await translate_func(answers, lang, tex)
  89. await client.answer_inline_query(
  90. query.id,
  91. results=answerss,
  92. cache_time=10
  93. )
  94. except IndexError:
  95. return