inlinefuncs.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 wbb.utils.pastebin import paste
  17. from pykeyboard import InlineKeyboard
  18. from sys import version as pyver
  19. import sys
  20. from motor import version as mongover
  21. from pyrogram import __version__ as pyrover
  22. import aiohttp
  23. import json
  24. async def inline_help_func(__HELP__):
  25. buttons = InlineKeyboard(row_width=2)
  26. buttons.add(
  27. InlineKeyboardButton(
  28. 'Get More Help.',
  29. url=f"t.me/{BOT_USERNAME}?start=start"
  30. ),
  31. InlineKeyboardButton(
  32. "Go Inline!",
  33. switch_inline_query_current_chat=""
  34. )
  35. )
  36. answerss = [
  37. InlineQueryResultArticle(
  38. title="Inline Commands",
  39. description="Help Related To Inline Usage.",
  40. input_message_content=InputTextMessageContent(__HELP__),
  41. thumb_url="https://hamker.me/cy00x5x.png",
  42. reply_markup=buttons
  43. )
  44. ]
  45. answerss = await alive_function(answerss)
  46. return answerss
  47. async def alive_function(answers):
  48. buttons = InlineKeyboard(row_width=2)
  49. bot_state = 'Dead' if not await app.get_me() else 'Alive'
  50. ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
  51. buttons.add(
  52. InlineKeyboardButton(
  53. 'Stats',
  54. callback_data='stats_callback'
  55. ),
  56. InlineKeyboardButton(
  57. "Go Inline!",
  58. switch_inline_query_current_chat=""
  59. )
  60. )
  61. msg = f"""
  62. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  63. **MainBot:** `{bot_state}`
  64. **UserBot:** `{ubot_state}`
  65. **Python:** `{pyver.split()[0]}`
  66. **Pyrogram:** `{pyrover}`
  67. **MongoDB:** `{mongover}`
  68. **Platform:** `{sys.platform}`
  69. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  70. """
  71. answers.append(
  72. InlineQueryResultArticle(
  73. title='Alive',
  74. description="Check Bot's Stats",
  75. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  76. input_message_content=InputTextMessageContent(
  77. msg,
  78. disable_web_page_preview=True
  79. ),
  80. reply_markup=buttons,
  81. )
  82. )
  83. return answers
  84. async def translate_func(answers, lang, tex):
  85. i = Translator().translate(tex, dest=lang)
  86. msg = f"""
  87. __**Translated to {lang}**__
  88. **INPUT:**
  89. {tex}
  90. **OUTPUT:**
  91. {i.text}"""
  92. answers.append(
  93. InlineQueryResultArticle(
  94. title=f'Translated to {lang}',
  95. description=i.text,
  96. input_message_content=InputTextMessageContent(msg)
  97. )
  98. )
  99. return answers
  100. async def urban_func(answers, text):
  101. results = await arq.urbandict(text)
  102. for i in results:
  103. msg = f"""
  104. **Query:** {text}
  105. **Definition:** __{results[i].definition}__
  106. **Example:** __{results[i].example}__"""
  107. answers.append(
  108. InlineQueryResultArticle(
  109. title=results[i].word,
  110. description=results[i].definition,
  111. input_message_content=InputTextMessageContent(msg)
  112. ))
  113. return answers
  114. async def google_search_func(answers, text):
  115. gresults = await GoogleSearch().async_search(text)
  116. for i in gresults:
  117. try:
  118. msg = f"""
  119. [{i['titles']}]({i['links']})
  120. {i['descriptions']}"""
  121. answers.append(
  122. InlineQueryResultArticle(
  123. title=i['titles'],
  124. description=i['descriptions'],
  125. input_message_content=InputTextMessageContent(
  126. msg,
  127. disable_web_page_preview=True
  128. )
  129. ))
  130. except KeyError:
  131. pass
  132. return answers
  133. async def wall_func(answers, text):
  134. results = await arq.wall(text)
  135. for i in results:
  136. try:
  137. answers.append(
  138. InlineQueryResultPhoto(
  139. photo_url=results[i].url_image,
  140. thumb_url=results[i].url_thumb,
  141. caption=f"[Source]({results[i].url_image})"
  142. ))
  143. except KeyError:
  144. pass
  145. return answers
  146. async def saavn_func(answers, text):
  147. buttons_list = []
  148. results = await arq.saavn(text)
  149. for i in results:
  150. buttons = InlineKeyboard(row_width=1)
  151. buttons.add(
  152. InlineKeyboardButton(
  153. 'Download | Play',
  154. url=results[i].media_url
  155. )
  156. )
  157. buttons_list.append(buttons)
  158. duration = await time_convert(results[i].duration)
  159. caption = f"""
  160. **Title:** {results[i].song}
  161. **Album:** {results[i].album}
  162. **Duration:** {duration}
  163. **Release:** {results[i].year}
  164. **Singers:** {results[i].singers}"""
  165. description = f"{results[i].album} | {duration} " \
  166. + f"| {results[i].singers} ({results[i].year})"
  167. try:
  168. answers.append(
  169. InlineQueryResultArticle(
  170. title=results[i].song,
  171. input_message_content=InputTextMessageContent(
  172. caption,
  173. disable_web_page_preview=True
  174. ),
  175. description=description,
  176. thumb_url=results[i].image,
  177. reply_markup=buttons_list[i]
  178. ))
  179. except (KeyError, ValueError):
  180. pass
  181. return answers
  182. async def deezer_func(answers, text):
  183. buttons_list = []
  184. results = await arq.deezer(text, 5)
  185. for i in results:
  186. buttons = InlineKeyboard(row_width=1)
  187. buttons.add(
  188. InlineKeyboardButton(
  189. 'Download | Play',
  190. url=results[i].url
  191. )
  192. )
  193. buttons_list.append(buttons)
  194. duration = await time_convert(results[i].duration)
  195. caption = f"""
  196. **Title:** {results[i].title}
  197. **Artist:** {results[i].artist}
  198. **Duration:** {duration}
  199. **Source:** [Deezer]({results[i].source})"""
  200. description = f"{results[i].artist} | {duration}"
  201. try:
  202. answers.append(
  203. InlineQueryResultArticle(
  204. title=results[i].title,
  205. thumb_url=results[i].thumbnail,
  206. description=description,
  207. input_message_content=InputTextMessageContent(
  208. caption,
  209. disable_web_page_preview=True
  210. ),
  211. reply_markup=buttons_list[i]
  212. ))
  213. except (KeyError, ValueError):
  214. pass
  215. return answers
  216. async def webss(url):
  217. start_time = time()
  218. if "." not in url:
  219. return
  220. screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
  221. end_time = time()
  222. try:
  223. m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
  224. except TypeError:
  225. return
  226. await m.delete()
  227. a = []
  228. pic = InlineQueryResultPhoto(
  229. photo_url=screenshot['url'],
  230. caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
  231. )
  232. a.append(pic)
  233. return a
  234. # Used my api key here, don't fuck with it
  235. async def shortify(url):
  236. if "." not in url:
  237. return
  238. header = {
  239. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  240. 'Content-Type': 'application/json'
  241. }
  242. payload = {
  243. "long_url": f"{url}"
  244. }
  245. payload = json.dumps(payload)
  246. async with aiohttp.ClientSession() as session:
  247. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  248. data = await resp.json()
  249. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  250. a = []
  251. b = InlineQueryResultArticle(
  252. title="Link Shortened!",
  253. description=data['link'],
  254. input_message_content=InputTextMessageContent(
  255. msg, disable_web_page_preview=True)
  256. )
  257. a.append(b)
  258. return a
  259. async def torrent_func(answers, text):
  260. results = await arq.torrent(text)
  261. limit = 0
  262. for i in results:
  263. if limit > 48:
  264. break
  265. title = results[i].name
  266. size = results[i].size
  267. seeds = results[i].seeds
  268. leechs = results[i].leechs
  269. upload_date = results[i].uploaded + " Ago"
  270. magnet = results[i].magnet
  271. caption = f"""
  272. **Title:** __{title}__
  273. **Size:** __{size}__
  274. **Seeds:** __{seeds}__
  275. **Leechs:** __{leechs}__
  276. **Uploaded:** __{upload_date}__
  277. **Magnet:** __{magnet}__"""
  278. description = f"{size} | {upload_date} | Seeds: {seeds}"
  279. try:
  280. answers.append(
  281. InlineQueryResultArticle(
  282. title=title,
  283. description=description,
  284. input_message_content=InputTextMessageContent(
  285. caption,
  286. disable_web_page_preview=True
  287. )
  288. )
  289. )
  290. limit += 1
  291. except (KeyError, ValueError):
  292. pass
  293. return answers
  294. async def youtube_func(answers, text):
  295. buttons_list = []
  296. results = await arq.youtube(text)
  297. for i in results:
  298. buttons = InlineKeyboard(row_width=1)
  299. video_url = f"https://youtube.com{results[i].url_suffix}"
  300. buttons.add(
  301. InlineKeyboardButton(
  302. 'Watch',
  303. url=video_url
  304. )
  305. )
  306. buttons_list.append(buttons)
  307. caption = f"""
  308. **Title:** {results[i].title}
  309. **Views:** {results[i].views}
  310. **Channel:** {results[i].channel}
  311. **Duration:** {results[i].duration}
  312. **Uploaded:** {results[i].publish_time}
  313. **Description:** {results[i].long_desc}"""
  314. description = f"{results[i].views} | {results[i].channel} | " \
  315. + f"{results[i].duration} | {results[i].publish_time}"
  316. try:
  317. answers.append(
  318. InlineQueryResultArticle(
  319. title=results[i].title,
  320. thumb_url=results[i].thumbnails[0],
  321. description=description,
  322. input_message_content=InputTextMessageContent(
  323. caption,
  324. disable_web_page_preview=True
  325. ),
  326. reply_markup=buttons_list[i]
  327. ))
  328. except (KeyError, ValueError):
  329. pass
  330. return answers
  331. async def lyrics_func(answers, text):
  332. song = await arq.lyrics(text)
  333. lyrics = song.lyrics
  334. song = lyrics.splitlines()
  335. song_name = song[0]
  336. artist = song[1]
  337. if len(lyrics) > 4095:
  338. lyrics = await paste(lyrics)
  339. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  340. msg = f"__{lyrics}__"
  341. answers.append(
  342. InlineQueryResultArticle(
  343. title=song_name,
  344. description=artist,
  345. input_message_content=InputTextMessageContent(msg)
  346. ))
  347. return answers