inline.py 2.9 KB

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