inline.py 3.8 KB

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