inlinefuncs.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. from wbb import (
  2. arq, app, app2, USERBOT_USERNAME,
  3. BOT_USERNAME, LOG_GROUP_ID )
  4. from pyrogram.types import (
  5. InlineQueryResultArticle,
  6. InputTextMessageContent,
  7. InlineKeyboardButton,
  8. InlineQueryResultPhoto
  9. )
  10. from googletrans import Translator
  11. from search_engine_parser import GoogleSearch
  12. from time import time
  13. from wbb.utils.fetch import fetch
  14. from pykeyboard import InlineKeyboard
  15. from sys import version as pyver
  16. from motor import version as mongover
  17. from pyrogram import __version__ as pyrover
  18. import aiohttp
  19. import json
  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(msg)
  60. )
  61. )
  62. return answers
  63. async def urban_func(answers, text):
  64. results = await arq.urbandict(text)
  65. for i in results:
  66. msg = f"""
  67. **Query:** {text}
  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. async def google_search_func(answers, text):
  78. gresults = await GoogleSearch().async_search(text)
  79. for i in gresults:
  80. try:
  81. msg = f"""
  82. [{i['titles']}]({i['links']})
  83. {i['descriptions']}"""
  84. answers.append(
  85. InlineQueryResultArticle(
  86. title=i['titles'],
  87. description=i['descriptions'],
  88. input_message_content=InputTextMessageContent(
  89. msg,
  90. disable_web_page_preview=True
  91. )
  92. ))
  93. except KeyError:
  94. pass
  95. return answers
  96. async def webss(url):
  97. start_time = time()
  98. if "." not in url:
  99. return
  100. screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
  101. end_time = time()
  102. m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
  103. await m.delete()
  104. a = []
  105. pic = InlineQueryResultPhoto(
  106. photo_url=screenshot['url'],
  107. caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
  108. )
  109. a.append(pic)
  110. return a
  111. # Used my api key here, don't fuck with it
  112. async def shortify(url):
  113. if "." not in url:
  114. return
  115. header = {
  116. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  117. 'Content-Type': 'application/json'
  118. }
  119. payload = {
  120. "long_url": f"{url}"
  121. }
  122. payload = json.dumps(payload)
  123. async with aiohttp.ClientSession() as session:
  124. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  125. data = await resp.json()
  126. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  127. a = []
  128. b = InlineQueryResultArticle(
  129. title="Link Shortened!",
  130. description=data['link'],
  131. input_message_content=InputTextMessageContent(msg, disable_web_page_preview=True)
  132. )
  133. a.append(b)
  134. return a