inlinefuncs.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. from wbb import (
  2. arq, app, app2, USERBOT_USERNAME,
  3. BOT_USERNAME, LOG_GROUP_ID
  4. )
  5. from pyrogram.types import (
  6. InlineQueryResultArticle,
  7. InputTextMessageContent,
  8. InlineKeyboardButton,
  9. InlineQueryResultPhoto
  10. )
  11. from googletrans import Translator
  12. from search_engine_parser import GoogleSearch
  13. from time import time
  14. from wbb.utils.fetch import fetch
  15. from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
  16. from pykeyboard import InlineKeyboard
  17. from sys import version as pyver
  18. import sys
  19. from motor import version as mongover
  20. from pyrogram import __version__ as pyrover
  21. import aiohttp
  22. import json
  23. async def inline_help_func(__HELP__):
  24. buttons = InlineKeyboard(row_width=2)
  25. buttons.add(
  26. InlineKeyboardButton(
  27. 'Get More Help.',
  28. url=f"t.me/{BOT_USERNAME}?start=start"
  29. ),
  30. InlineKeyboardButton(
  31. "Go Inline!",
  32. switch_inline_query_current_chat=""
  33. )
  34. )
  35. answerss = [
  36. InlineQueryResultArticle(
  37. title="Inline Commands",
  38. description="Help Related To Inline Usage.",
  39. input_message_content=InputTextMessageContent(__HELP__),
  40. reply_markup=buttons
  41. )
  42. ]
  43. answerss = await alive_function(answerss)
  44. return answerss
  45. async def alive_function(answers):
  46. buttons = InlineKeyboard(row_width=2)
  47. bot_state = 'Dead' if not await app.get_me() else 'Alive'
  48. ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
  49. buttons.add(
  50. InlineKeyboardButton(
  51. 'Stats',
  52. callback_data='stats_callback'
  53. ),
  54. InlineKeyboardButton(
  55. "Go Inline!",
  56. switch_inline_query_current_chat=""
  57. )
  58. )
  59. msg = f"""
  60. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  61. **MainBot:** `{bot_state}`
  62. **UserBot:** `{ubot_state}`
  63. **Python:** `{pyver.split()[0]}`
  64. **Pyrogram:** `{pyrover}`
  65. **MongoDB:** `{mongover}`
  66. **Platform:** `{sys.platform}`
  67. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  68. """
  69. answers.append(
  70. InlineQueryResultArticle(
  71. title='Alive',
  72. description="Check Bot's Stats",
  73. input_message_content=InputTextMessageContent(
  74. msg,
  75. disable_web_page_preview=True
  76. ),
  77. reply_markup=buttons,
  78. )
  79. )
  80. return answers
  81. async def translate_func(answers, lang, tex):
  82. i = Translator().translate(tex, dest=lang)
  83. msg = f"""
  84. __**Translated to {lang}**__
  85. **INPUT:**
  86. {tex}
  87. **OUTPUT:**
  88. {i.text}"""
  89. answers.append(
  90. InlineQueryResultArticle(
  91. title=f'Translated to {lang}',
  92. description=i.text,
  93. input_message_content=InputTextMessageContent(msg)
  94. )
  95. )
  96. return answers
  97. async def urban_func(answers, text):
  98. results = await arq.urbandict(text)
  99. for i in results:
  100. msg = f"""
  101. **Query:** {text}
  102. **Definition:** __{results[i].definition}__
  103. **Example:** __{results[i].example}__"""
  104. answers.append(
  105. InlineQueryResultArticle(
  106. title=results[i].word,
  107. description=results[i].definition,
  108. input_message_content=InputTextMessageContent(msg)
  109. ))
  110. return answers
  111. async def google_search_func(answers, text):
  112. gresults = await GoogleSearch().async_search(text)
  113. for i in gresults:
  114. try:
  115. msg = f"""
  116. [{i['titles']}]({i['links']})
  117. {i['descriptions']}"""
  118. answers.append(
  119. InlineQueryResultArticle(
  120. title=i['titles'],
  121. description=i['descriptions'],
  122. input_message_content=InputTextMessageContent(
  123. msg,
  124. disable_web_page_preview=True
  125. )
  126. ))
  127. except KeyError:
  128. pass
  129. return answers
  130. async def wall_func(answers, text):
  131. results = await arq.wall(text)
  132. for i in results:
  133. try:
  134. answers.append(
  135. InlineQueryResultPhoto(
  136. photo_url=results[i].url_image,
  137. thumb_url=results[i].url_thumb,
  138. caption=f"[Source]({results[i].url_image})"
  139. ))
  140. except KeyError:
  141. pass
  142. return answers
  143. async def saavn_func(answers, text):
  144. buttons_list = []
  145. results = await arq.saavn(text)
  146. for i in results:
  147. buttons = InlineKeyboard(row_width=1)
  148. buttons.add(
  149. InlineKeyboardButton(
  150. 'Download | Play',
  151. url=results[i].media_url
  152. )
  153. )
  154. buttons_list.append(buttons)
  155. duration = await time_convert(results[i].duration)
  156. caption = f"""
  157. **Title:** {results[i].song}
  158. **Album:** {results[i].album}
  159. **Duration:** {duration}
  160. **Release:** {results[i].year}
  161. **Singers:** {results[i].singers}"""
  162. description = f"{results[i].album} | {duration} " \
  163. + f"| {results[i].singers} ({results[i].year})"
  164. try:
  165. answers.append(
  166. InlineQueryResultArticle(
  167. title=results[i].song,
  168. input_message_content=InputTextMessageContent(
  169. caption,
  170. disable_web_page_preview=True
  171. ),
  172. description=description,
  173. thumb_url=results[i].image,
  174. reply_markup=buttons_list[i]
  175. ))
  176. except KeyError:
  177. pass
  178. return answers
  179. async def deezer_func(answers, text):
  180. buttons_list = []
  181. results = await arq.deezer(text, 5)
  182. for i in results:
  183. buttons = InlineKeyboard(row_width=1)
  184. buttons.add(
  185. InlineKeyboardButton(
  186. 'Download | Play',
  187. url=results[i].url
  188. )
  189. )
  190. buttons_list.append(buttons)
  191. duration = await time_convert(results[i].duration)
  192. caption = f"""
  193. **Title:** {results[i].title}
  194. **Artist:** {results[i].artist}
  195. **Duration:** {duration}
  196. **Source:** [Deezer]({results[i].source})"""
  197. description = f"{results[i].artist} | {duration}"
  198. try:
  199. answers.append(
  200. InlineQueryResultArticle(
  201. title=results[i].title,
  202. thumb_url=results[i].thumbnail,
  203. description=description,
  204. input_message_content=InputTextMessageContent(
  205. caption,
  206. disable_web_page_preview=True
  207. ),
  208. reply_markup=buttons_list[i]
  209. ))
  210. except KeyError:
  211. pass
  212. return answers
  213. async def webss(url):
  214. start_time = time()
  215. if "." not in url:
  216. return
  217. screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
  218. end_time = time()
  219. m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
  220. await m.delete()
  221. a = []
  222. pic = InlineQueryResultPhoto(
  223. photo_url=screenshot['url'],
  224. caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
  225. )
  226. a.append(pic)
  227. return a
  228. # Used my api key here, don't fuck with it
  229. async def shortify(url):
  230. if "." not in url:
  231. return
  232. header = {
  233. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  234. 'Content-Type': 'application/json'
  235. }
  236. payload = {
  237. "long_url": f"{url}"
  238. }
  239. payload = json.dumps(payload)
  240. async with aiohttp.ClientSession() as session:
  241. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  242. data = await resp.json()
  243. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  244. a = []
  245. b = InlineQueryResultArticle(
  246. title="Link Shortened!",
  247. description=data['link'],
  248. input_message_content=InputTextMessageContent(msg, disable_web_page_preview=True)
  249. )
  250. a.append(b)
  251. return a