inlinefuncs.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. import sys
  17. from motor import version as mongover
  18. from pyrogram import __version__ as pyrover
  19. import aiohttp
  20. import json
  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. **Query:** {text}
  69. **Definition:** __{results[i].definition}__
  70. **Example:** __{results[i].example}__"""
  71. answers.append(
  72. InlineQueryResultArticle(
  73. title=results[i].word,
  74. description=results[i].definition,
  75. input_message_content=InputTextMessageContent(msg)
  76. ))
  77. return answers
  78. async def google_search_func(answers, text):
  79. gresults = await GoogleSearch().async_search(text)
  80. for i in gresults:
  81. try:
  82. msg = f"""
  83. [{i['titles']}]({i['links']})
  84. {i['descriptions']}"""
  85. answers.append(
  86. InlineQueryResultArticle(
  87. title=i['titles'],
  88. description=i['descriptions'],
  89. input_message_content=InputTextMessageContent(
  90. msg,
  91. disable_web_page_preview=True
  92. )
  93. ))
  94. except KeyError:
  95. pass
  96. return answers
  97. async def wall_func(answers, text):
  98. results = await arq.wall(text)
  99. for i in results:
  100. try:
  101. answers.append(
  102. InlineQueryResultPhoto(
  103. photo_url=results[i].url_image,
  104. thumb_url=results[i].url_thumb,
  105. caption=f"[Source]({results[i].url_image})"
  106. ))
  107. except KeyError:
  108. pass
  109. return answers
  110. async def saavn_func(answers, text):
  111. results = await arq.saavn(text)
  112. for i in results:
  113. caption = f"""
  114. **Title:** {results[i].song}
  115. **Album:** {results[i].album}
  116. **Duration:** {results[i].duration} Seconds
  117. **Release:** {results[i].year}
  118. **Singers:** {results[i].singers}
  119. **Link:** [Here]({results[i].media_url})"""
  120. try:
  121. answers.append(
  122. InlineQueryResultPhoto(
  123. photo_url=results[i].image,
  124. caption=caption,
  125. ))
  126. except KeyError:
  127. pass
  128. return answers
  129. async def deezer_func(answers, text):
  130. results = await arq.deezer(text, 5)
  131. for i in results:
  132. caption = f"""
  133. **Title:** {results[i].title}
  134. **Duration:** {results[i].duration} Seconds
  135. **Artist:** {results[i].artist}
  136. **Link:** [Here]({results[i].url})"""
  137. try:
  138. answers.append(
  139. InlineQueryResultPhoto(
  140. photo_url=results[i].thumbnail,
  141. caption=caption,
  142. ))
  143. except KeyError:
  144. pass
  145. return answers
  146. async def webss(url):
  147. start_time = time()
  148. if "." not in url:
  149. return
  150. screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
  151. end_time = time()
  152. m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
  153. await m.delete()
  154. a = []
  155. pic = InlineQueryResultPhoto(
  156. photo_url=screenshot['url'],
  157. caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
  158. )
  159. a.append(pic)
  160. return a
  161. # Used my api key here, don't fuck with it
  162. async def shortify(url):
  163. if "." not in url:
  164. return
  165. header = {
  166. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  167. 'Content-Type': 'application/json'
  168. }
  169. payload = {
  170. "long_url": f"{url}"
  171. }
  172. payload = json.dumps(payload)
  173. async with aiohttp.ClientSession() as session:
  174. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  175. data = await resp.json()
  176. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  177. a = []
  178. b = InlineQueryResultArticle(
  179. title="Link Shortened!",
  180. description=data['link'],
  181. input_message_content=InputTextMessageContent(msg, disable_web_page_preview=True)
  182. )
  183. a.append(b)
  184. return a