inlinefuncs.py 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. """
  2. MIT License
  3. Copyright (c) 2021 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. import asyncio
  21. import json
  22. import os
  23. import sys
  24. from random import randint
  25. from sys import version as pyver
  26. from time import ctime, time
  27. import aiofiles
  28. from motor import version as mongover
  29. from pykeyboard import InlineKeyboard
  30. from pyrogram import __version__ as pyrover
  31. from pyrogram import filters
  32. from pyrogram.raw.functions import Ping
  33. from pyrogram.types import (InlineKeyboardButton, InlineQueryResultArticle,
  34. InlineQueryResultPhoto, InputTextMessageContent)
  35. from search_engine_parser import GoogleSearch
  36. from wbb import (BOT_USERNAME, MESSAGE_DUMP_CHAT, SUDOERS, USERBOT_ID,
  37. USERBOT_NAME, USERBOT_USERNAME, app, app2, arq, aiohttpsession)
  38. from wbb.core.types import InlineQueryResultCachedDocument, InlineQueryResultAudio
  39. from wbb.modules.info import get_chat_info, get_user_info
  40. from wbb.modules.music import download_youtube_audio
  41. from wbb.modules.paste import isPreviewUp
  42. from wbb.utils.fetch import fetch
  43. from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
  44. from wbb.utils.functions import make_carbon, test_speedtest
  45. from wbb.utils.pastebin import paste
  46. keywords_list = [
  47. "alive",
  48. "ping",
  49. "tr",
  50. "ud",
  51. "google",
  52. "bitly",
  53. "wall",
  54. "yt",
  55. "torrent",
  56. "lyrics",
  57. "wiki",
  58. "speedtest",
  59. "music",
  60. "saavn",
  61. "deezer",
  62. "gh_repo",
  63. "gh_user",
  64. "search",
  65. "paste",
  66. "nsfw_scan",
  67. "ytmusic",
  68. "carbon",
  69. "info",
  70. "chat_info",
  71. "tmdb",
  72. "pypi",
  73. ]
  74. async def inline_help_func(__HELP__):
  75. buttons = InlineKeyboard(row_width=4)
  76. buttons.add(
  77. *[
  78. (InlineKeyboardButton(text=i, switch_inline_query_current_chat=i))
  79. for i in keywords_list
  80. ]
  81. )
  82. answerss = [
  83. InlineQueryResultArticle(
  84. title="Inline Commands",
  85. description="Help Related To Inline Usage.",
  86. input_message_content=InputTextMessageContent(
  87. "Click A Button To Get Started."
  88. ),
  89. thumb_url="https://hamker.me/cy00x5x.png",
  90. reply_markup=buttons,
  91. ),
  92. InlineQueryResultArticle(
  93. title="Github Repo",
  94. description="Get Github Respository Of Bot.",
  95. input_message_content=InputTextMessageContent(
  96. "https://github.com/thehamkercat/WilliamButcherBot"
  97. ),
  98. thumb_url="https://hamker.me/gjc9fo3.png",
  99. ),
  100. ]
  101. answerss = await alive_function(answerss)
  102. return answerss
  103. async def alive_function(answers):
  104. buttons = InlineKeyboard(row_width=2)
  105. bot_state = "Dead" if not await app.get_me() else "Alive"
  106. ubot_state = "Dead" if not await app2.get_me() else "Alive"
  107. buttons.add(
  108. InlineKeyboardButton("Stats", callback_data="stats_callback"),
  109. InlineKeyboardButton(
  110. "Go Inline!", switch_inline_query_current_chat=""
  111. ),
  112. )
  113. msg = f"""
  114. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  115. **MainBot:** `{bot_state}`
  116. **UserBot:** `{ubot_state}`
  117. **Python:** `{pyver.split()[0]}`
  118. **Pyrogram:** `{pyrover}`
  119. **MongoDB:** `{mongover}`
  120. **Platform:** `{sys.platform}`
  121. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  122. """
  123. answers.append(
  124. InlineQueryResultArticle(
  125. title="Alive",
  126. description="Check Bot's Stats",
  127. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  128. input_message_content=InputTextMessageContent(
  129. msg, disable_web_page_preview=True
  130. ),
  131. reply_markup=buttons,
  132. )
  133. )
  134. return answers
  135. async def translate_func(answers, lang, tex):
  136. result = await arq.translate(tex, lang)
  137. if not result.ok:
  138. answers.append(
  139. InlineQueryResultArticle(
  140. title="Error",
  141. description=result.result,
  142. input_message_content=InputTextMessageContent(result.result),
  143. )
  144. )
  145. return answers
  146. result = result.result
  147. msg = f"""
  148. __**Translated from {result.src} to {result.dest}**__
  149. **INPUT:**
  150. {tex}
  151. **OUTPUT:**
  152. {result.translatedText}"""
  153. answers.extend(
  154. [
  155. InlineQueryResultArticle(
  156. title=f"Translated from {result.src} to {result.dest}.",
  157. description=result.translatedText,
  158. input_message_content=InputTextMessageContent(msg),
  159. ),
  160. InlineQueryResultArticle(
  161. title=result.translatedText,
  162. input_message_content=InputTextMessageContent(
  163. result.translatedText
  164. ),
  165. ),
  166. ]
  167. )
  168. return answers
  169. async def urban_func(answers, text):
  170. results = await arq.urbandict(text)
  171. if not results.ok:
  172. answers.append(
  173. InlineQueryResultArticle(
  174. title="Error",
  175. description=results.result,
  176. input_message_content=InputTextMessageContent(results.result),
  177. )
  178. )
  179. return answers
  180. results = results.result[0:48]
  181. for i in results:
  182. msg = f"""
  183. **Query:** {text}
  184. **Definition:** __{i.definition}__
  185. **Example:** __{i.example}__"""
  186. answers.append(
  187. InlineQueryResultArticle(
  188. title=i.word,
  189. description=i.definition,
  190. input_message_content=InputTextMessageContent(msg),
  191. )
  192. )
  193. return answers
  194. async def google_search_func(answers, text):
  195. gresults = await GoogleSearch().async_search(text)
  196. limit = 0
  197. for i in gresults:
  198. if limit > 48:
  199. break
  200. limit += 1
  201. try:
  202. msg = f"""
  203. [{i['titles']}]({i['links']})
  204. {i['descriptions']}"""
  205. answers.append(
  206. InlineQueryResultArticle(
  207. title=i["titles"],
  208. description=i["descriptions"],
  209. input_message_content=InputTextMessageContent(
  210. msg, disable_web_page_preview=True
  211. ),
  212. )
  213. )
  214. except KeyError:
  215. pass
  216. return answers
  217. async def wall_func(answers, text):
  218. results = await arq.wall(text)
  219. if not results.ok:
  220. answers.append(
  221. InlineQueryResultArticle(
  222. title="Error",
  223. description=results.result,
  224. input_message_content=InputTextMessageContent(results.result),
  225. )
  226. )
  227. return answers
  228. results = results.result[0:48]
  229. for i in results:
  230. answers.append(
  231. InlineQueryResultPhoto(
  232. photo_url=i.url_image,
  233. thumb_url=i.url_thumb,
  234. caption=f"[Source]({i.url_image})",
  235. )
  236. )
  237. return answers
  238. async def saavn_func(answers, text):
  239. buttons_list = []
  240. results = await arq.saavn(text)
  241. if not results.ok:
  242. answers.append(
  243. InlineQueryResultArticle(
  244. title="Error",
  245. description=results.result,
  246. input_message_content=InputTextMessageContent(results.result),
  247. )
  248. )
  249. return answers
  250. results = results.result
  251. for count, i in enumerate(results):
  252. buttons = InlineKeyboard(row_width=1)
  253. buttons.add(InlineKeyboardButton("Download | Play", url=i.media_url))
  254. buttons_list.append(buttons)
  255. duration = await time_convert(i.duration)
  256. caption = f"""
  257. **Title:** {i.song}
  258. **Album:** {i.album}
  259. **Duration:** {duration}
  260. **Release:** {i.year}
  261. **Singers:** {i.singers}"""
  262. description = f"{i.album} | {duration} " + f"| {i.singers} ({i.year})"
  263. answers.append(
  264. InlineQueryResultArticle(
  265. title=i.song,
  266. input_message_content=InputTextMessageContent(
  267. caption, disable_web_page_preview=True
  268. ),
  269. description=description,
  270. thumb_url=i.image,
  271. reply_markup=buttons_list[count],
  272. )
  273. )
  274. return answers
  275. async def deezer_func(answers, text):
  276. buttons_list = []
  277. results = await arq.deezer(text, 5)
  278. if not results.ok:
  279. answers.append(
  280. InlineQueryResultArticle(
  281. title="Error",
  282. description=results.result,
  283. input_message_content=InputTextMessageContent(results.result),
  284. )
  285. )
  286. return answers
  287. results = results.result
  288. for count, i in enumerate(results):
  289. buttons = InlineKeyboard(row_width=1)
  290. buttons.add(InlineKeyboardButton("Download | Play", url=i.url))
  291. buttons_list.append(buttons)
  292. duration = await time_convert(i.duration)
  293. caption = f"""
  294. **Title:** {i.title}
  295. **Artist:** {i.artist}
  296. **Duration:** {duration}
  297. **Source:** [Deezer]({i.source})"""
  298. description = f"{i.artist} | {duration}"
  299. answers.append(
  300. InlineQueryResultArticle(
  301. title=i.title,
  302. thumb_url=i.thumbnail,
  303. description=description,
  304. input_message_content=InputTextMessageContent(
  305. caption, disable_web_page_preview=True
  306. ),
  307. reply_markup=buttons_list[count],
  308. )
  309. )
  310. return answers
  311. # Used my api key here, don't fuck with it
  312. async def shortify(url):
  313. if "." not in url:
  314. return
  315. header = {
  316. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  317. "Content-Type": "application/json",
  318. }
  319. payload = {"long_url": f"{url}"}
  320. payload = json.dumps(payload)
  321. async with aiohttpsession.post(
  322. "https://api-ssl.bitly.com/v4/shorten",
  323. headers=header,
  324. data=payload,
  325. ) as resp:
  326. data = await resp.json()
  327. msg = data["link"]
  328. a = []
  329. b = InlineQueryResultArticle(
  330. title="Link Shortened!",
  331. description=data["link"],
  332. input_message_content=InputTextMessageContent(
  333. msg, disable_web_page_preview=True
  334. ),
  335. )
  336. a.append(b)
  337. return a
  338. async def torrent_func(answers, text):
  339. results = await arq.torrent(text)
  340. if not results.ok:
  341. answers.append(
  342. InlineQueryResultArticle(
  343. title="Error",
  344. description=results.result,
  345. input_message_content=InputTextMessageContent(results.result),
  346. )
  347. )
  348. return answers
  349. results = results.result[0:48]
  350. for i in results:
  351. title = i.name
  352. size = i.size
  353. seeds = i.seeds
  354. leechs = i.leechs
  355. upload_date = i.uploaded
  356. magnet = i.magnet
  357. caption = f"""
  358. **Title:** __{title}__
  359. **Size:** __{size}__
  360. **Seeds:** __{seeds}__
  361. **Leechs:** __{leechs}__
  362. **Uploaded:** __{upload_date}__
  363. **Magnet:** `{magnet}`"""
  364. description = f"{size} | {upload_date} | Seeds: {seeds}"
  365. answers.append(
  366. InlineQueryResultArticle(
  367. title=title,
  368. description=description,
  369. input_message_content=InputTextMessageContent(
  370. caption, disable_web_page_preview=True
  371. ),
  372. )
  373. )
  374. pass
  375. return answers
  376. async def youtube_func(answers, text):
  377. results = await arq.youtube(text)
  378. if not results.ok:
  379. answers.append(
  380. InlineQueryResultArticle(
  381. title="Error",
  382. description=results.result,
  383. input_message_content=InputTextMessageContent(results.result),
  384. )
  385. )
  386. return answers
  387. results = results.result[0:48]
  388. for i in results:
  389. buttons = InlineKeyboard(row_width=1)
  390. video_url = f"https://youtube.com{i.url_suffix}"
  391. buttons.add(InlineKeyboardButton("Watch", url=video_url))
  392. caption = f"""
  393. **Title:** {i.title}
  394. **Views:** {i.views}
  395. **Channel:** {i.channel}
  396. **Duration:** {i.duration}
  397. **Uploaded:** {i.publish_time}
  398. **Description:** {i.long_desc}"""
  399. description = (
  400. f"{i.views} | {i.channel} | {i.duration} | {i.publish_time}"
  401. )
  402. answers.append(
  403. InlineQueryResultArticle(
  404. title=i.title,
  405. thumb_url=i.thumbnails[0],
  406. description=description,
  407. input_message_content=InputTextMessageContent(
  408. caption, disable_web_page_preview=True
  409. ),
  410. reply_markup=buttons,
  411. )
  412. )
  413. return answers
  414. async def lyrics_func(answers, text):
  415. song = await arq.lyrics(text)
  416. if not song.ok:
  417. answers.append(
  418. InlineQueryResultArticle(
  419. title="Error",
  420. description=song.result,
  421. input_message_content=InputTextMessageContent(song.result),
  422. )
  423. )
  424. return answers
  425. lyrics = song.result
  426. song = lyrics.splitlines()
  427. song_name = song[0]
  428. artist = song[1]
  429. if len(lyrics) > 4095:
  430. lyrics = await paste(lyrics)
  431. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  432. msg = f"__{lyrics}__"
  433. answers.append(
  434. InlineQueryResultArticle(
  435. title=song_name,
  436. description=artist,
  437. input_message_content=InputTextMessageContent(msg),
  438. )
  439. )
  440. return answers
  441. async def github_user_func(answers, text):
  442. URL = f"https://api.github.com/users/{text}"
  443. result = await fetch(URL)
  444. buttons = InlineKeyboard(row_width=1)
  445. buttons.add(
  446. InlineKeyboardButton(
  447. text="Open On Github", url=f"https://github.com/{text}"
  448. )
  449. )
  450. caption = f"""
  451. **Info Of {result['name']}**
  452. **Username:** `{text}`
  453. **Bio:** `{result['bio']}`
  454. **Profile Link:** [Here]({result['html_url']})
  455. **Company:** `{result['company']}`
  456. **Created On:** `{result['created_at']}`
  457. **Repositories:** `{result['public_repos']}`
  458. **Blog:** `{result['blog']}`
  459. **Location:** `{result['location']}`
  460. **Followers:** `{result['followers']}`
  461. **Following:** `{result['following']}`"""
  462. answers.append(
  463. InlineQueryResultPhoto(
  464. photo_url=result["avatar_url"],
  465. caption=caption,
  466. reply_markup=buttons,
  467. )
  468. )
  469. return answers
  470. async def github_repo_func(answers, text):
  471. text = text.replace("https://github.com/", "")
  472. text = text.replace("http://github.com/", "")
  473. if text[-1] == "/":
  474. text = text[0:-1]
  475. URL = f"https://api.github.com/repos/{text}"
  476. URL2 = f"https://api.github.com/repos/{text}/contributors"
  477. results = await asyncio.gather(fetch(URL), fetch(URL2))
  478. r = results[0]
  479. r1 = results[1]
  480. commits = 0
  481. for developer in r1:
  482. commits += developer["contributions"]
  483. buttons = InlineKeyboard(row_width=1)
  484. buttons.add(
  485. InlineKeyboardButton(
  486. "Open On Github", url=f"https://github.com/{text}"
  487. )
  488. )
  489. caption = f"""
  490. **Info Of {r['full_name']}**
  491. **Stars:** `{r['stargazers_count']}`
  492. **Watchers:** `{r['watchers_count']}`
  493. **Forks:** `{r['forks_count']}`
  494. **Commits:** `{commits}`
  495. **Is Fork:** `{r['fork']}`
  496. **Language:** `{r['language']}`
  497. **Contributors:** `{len(r1)}`
  498. **License:** `{r['license']['name'] if r['license'] else None}`
  499. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  500. **Created On:** `{r['created_at']}`
  501. **Homepage:** {r['homepage']}
  502. **Description:** __{r['description']}__"""
  503. answers.append(
  504. InlineQueryResultArticle(
  505. title="Found Repo",
  506. description=text,
  507. reply_markup=buttons,
  508. input_message_content=InputTextMessageContent(
  509. caption, disable_web_page_preview=True
  510. ),
  511. )
  512. )
  513. return answers
  514. async def tg_search_func(answers, text, user_id):
  515. if user_id not in SUDOERS:
  516. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  517. answers.append(
  518. InlineQueryResultArticle(
  519. title="ERROR",
  520. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  521. input_message_content=InputTextMessageContent(msg),
  522. )
  523. )
  524. return answers
  525. if str(text)[-1] != ":":
  526. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  527. answers.append(
  528. InlineQueryResultArticle(
  529. title="ERROR",
  530. description="Put A ':' After The Text To Search",
  531. input_message_content=InputTextMessageContent(msg),
  532. )
  533. )
  534. return answers
  535. text = text[0:-1]
  536. async for message in app2.search_global(text, limit=49):
  537. buttons = InlineKeyboard(row_width=2)
  538. buttons.add(
  539. InlineKeyboardButton(
  540. text="Origin",
  541. url=message.link if message.link else "https://t.me/telegram",
  542. ),
  543. InlineKeyboardButton(
  544. text="Search again", switch_inline_query_current_chat="search"
  545. ),
  546. )
  547. name = (
  548. message.from_user.first_name
  549. if message.from_user.first_name
  550. else "NO NAME"
  551. )
  552. caption = f"""
  553. **Query:** {text}
  554. **Name:** {str(name)} [`{message.from_user.id}`]
  555. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  556. **Date:** {ctime(message.date)}
  557. **Text:** >>
  558. {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
  559. """
  560. result = InlineQueryResultArticle(
  561. title=name,
  562. description=message.text if message.text else "[NO_TEXT]",
  563. reply_markup=buttons,
  564. input_message_content=InputTextMessageContent(
  565. caption, disable_web_page_preview=True
  566. ),
  567. )
  568. answers.append(result)
  569. return answers
  570. async def music_inline_func(answers, query):
  571. chat_id = -1001445180719
  572. group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
  573. try:
  574. messages = [
  575. m
  576. async for m in app2.search_messages(
  577. chat_id, query, filter="audio", limit=199
  578. )
  579. ]
  580. except Exception as e:
  581. print(e)
  582. msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
  583. answers.append(
  584. InlineQueryResultArticle(
  585. title="ERROR",
  586. description="Click Here To Know More.",
  587. input_message_content=InputTextMessageContent(
  588. msg, disable_web_page_preview=True
  589. ),
  590. )
  591. )
  592. return answers
  593. messages_ids_and_duration = []
  594. for f_ in messages:
  595. messages_ids_and_duration.append(
  596. {
  597. "message_id": f_.message_id,
  598. "duration": f_.audio.duration if f_.audio.duration else 0,
  599. }
  600. )
  601. messages = list(
  602. {v["duration"]: v for v in messages_ids_and_duration}.values()
  603. )
  604. messages_ids = []
  605. for ff_ in messages:
  606. messages_ids.append(ff_["message_id"])
  607. messages = await app.get_messages(chat_id, messages_ids[0:48])
  608. for message_ in messages:
  609. answers.append(
  610. InlineQueryResultCachedDocument(
  611. file_id=message_.audio.file_id, title=message_.audio.title
  612. )
  613. )
  614. return answers
  615. async def wiki_func(answers, text):
  616. data = await arq.wiki(text)
  617. if not data.ok:
  618. answers.append(
  619. InlineQueryResultArticle(
  620. title="Error",
  621. description=data.result,
  622. input_message_content=InputTextMessageContent(data.result),
  623. )
  624. )
  625. return answers
  626. data = data.result
  627. msg = f"""
  628. **QUERY:**
  629. {data.title}
  630. **ANSWER:**
  631. __{data.answer}__"""
  632. answers.append(
  633. InlineQueryResultArticle(
  634. title=data.title,
  635. description=data.answer,
  636. input_message_content=InputTextMessageContent(msg),
  637. )
  638. )
  639. return answers
  640. async def speedtest_init(query):
  641. answers = []
  642. user_id = query.from_user.id
  643. if user_id not in SUDOERS:
  644. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  645. answers.append(
  646. InlineQueryResultArticle(
  647. title="ERROR",
  648. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  649. input_message_content=InputTextMessageContent(msg),
  650. )
  651. )
  652. return answers
  653. msg = "**Click The Button Below To Perform A Speedtest**"
  654. button = InlineKeyboard(row_width=1)
  655. button.add(
  656. InlineKeyboardButton(text="Test", callback_data="test_speedtest")
  657. )
  658. answers.append(
  659. InlineQueryResultArticle(
  660. title="Click Here",
  661. input_message_content=InputTextMessageContent(msg),
  662. reply_markup=button,
  663. )
  664. )
  665. return answers
  666. """ callback query for the function above """
  667. @app.on_callback_query(filters.regex("test_speedtest"))
  668. async def test_speedtest_cq(_, cq):
  669. if cq.from_user.id not in SUDOERS:
  670. await cq.answer("This Isn't For You!")
  671. return
  672. inline_message_id = cq.inline_message_id
  673. await app.edit_inline_text(inline_message_id, "**Testing**")
  674. loop = asyncio.get_running_loop()
  675. download, upload, info = await loop.run_in_executor(None, test_speedtest)
  676. msg = f"""
  677. **Download:** `{download}`
  678. **Upload:** `{upload}`
  679. **Latency:** `{info['latency']} ms`
  680. **Country:** `{info['country']} [{info['cc']}]`
  681. **Latitude:** `{info['lat']}`
  682. **Longitude:** `{info['lon']}`
  683. """
  684. await app.edit_inline_text(inline_message_id, msg)
  685. async def pastebin_func(answers, link):
  686. link = link.split("/")
  687. if link[3] == "c":
  688. chat, message_id = int("-100" + link[4]), int(link[5])
  689. else:
  690. chat, message_id = link[3], link[4]
  691. m = await app.get_messages(chat, message_ids=int(message_id))
  692. if not m.text and not m.document:
  693. m = await app2.get_messages(chat, message_ids=int(message_id))
  694. if m.text:
  695. content = m.text
  696. else:
  697. if m.document.file_size > 1048576:
  698. answers.append(
  699. InlineQueryResultArticle(
  700. title="DOCUMENT TOO BIG",
  701. description="Maximum supported size is 1MB",
  702. input_message_content=InputTextMessageContent(
  703. "DOCUMENT TOO BIG"
  704. ),
  705. )
  706. )
  707. return answers
  708. doc = await m.download()
  709. async with aiofiles.open(doc, mode="r") as f:
  710. content = await f.read()
  711. os.remove(doc)
  712. link = await paste(content)
  713. preview = link + "/preview.png"
  714. if not await isPreviewUp(preview):
  715. return []
  716. await app.send_photo(MESSAGE_DUMP_CHAT, preview) # To Pre-cache the media
  717. buttons = InlineKeyboard(row_width=1)
  718. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  719. answers.append(
  720. InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons)
  721. )
  722. return answers
  723. async def pmpermit_func(answers, user_id, victim):
  724. if user_id != USERBOT_ID:
  725. return
  726. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  727. buttons = InlineKeyboard(row_width=2)
  728. buttons.add(
  729. InlineKeyboardButton(
  730. text="To Scam You", callback_data="pmpermit to_scam_you a"
  731. ),
  732. InlineKeyboardButton(
  733. text="For promotion", callback_data="pmpermit to_scam_you a"
  734. ),
  735. InlineKeyboardButton(
  736. text="Approve me", callback_data="pmpermit approve_me a"
  737. ),
  738. InlineKeyboardButton(
  739. text="Approve", callback_data=f"pmpermit approve {victim}"
  740. ),
  741. )
  742. answers.append(
  743. InlineQueryResultArticle(
  744. title="do_not_click_here",
  745. reply_markup=buttons,
  746. input_message_content=InputTextMessageContent(caption),
  747. )
  748. )
  749. return answers
  750. async def ping_func(answers):
  751. t1 = time()
  752. ping = Ping(ping_id=randint(696969, 6969696))
  753. await app.send(ping)
  754. t2 = time()
  755. ping = f"{str(round((t2 - t1), 6) * 100)} ms"
  756. answers.append(
  757. InlineQueryResultArticle(
  758. title=ping,
  759. input_message_content=InputTextMessageContent(f"__**{ping}**__"),
  760. )
  761. )
  762. return answers
  763. async def nsfw_scan_func(answers, url: str):
  764. t1 = time()
  765. data = await arq.nsfw_scan(url)
  766. if not data.ok:
  767. answers.append(
  768. InlineQueryResultArticle(
  769. title="Error",
  770. description=data.result,
  771. input_message_content=InputTextMessageContent(data.result),
  772. )
  773. )
  774. return answers
  775. t2 = time()
  776. tt = round(t2 - t1, 4)
  777. data = data.result
  778. content = f"""
  779. **Scanned [Image]({url}) In {tt} Seconds.**
  780. **Drawings:** `{data.drawings} %`
  781. **Neutral:** `{data.neutral} %`
  782. **Hentai:** `{data.hentai} %`
  783. **Porn:** `{data.porn} %`
  784. **Sexy:** `{data.sexy} %`
  785. """
  786. answers.append(
  787. InlineQueryResultArticle(
  788. title="Scanned",
  789. description=f"Took {tt} Seconds.",
  790. input_message_content=InputTextMessageContent(content),
  791. )
  792. )
  793. return answers
  794. async def yt_music_func(answers, url):
  795. if "http" not in url:
  796. url = (await arq.youtube(url)).result[0]
  797. url = f"https://youtube.com{url.url_suffix}"
  798. loop = asyncio.get_running_loop()
  799. music = await loop.run_in_executor(None, download_youtube_audio, url)
  800. if not music:
  801. msg = "**ERROR**\n__MUSIC TOO LONG__"
  802. answers.append(
  803. InlineQueryResultArticle(
  804. title="ERROR",
  805. description="MUSIC TOO LONG",
  806. input_message_content=InputTextMessageContent(msg),
  807. )
  808. )
  809. return answers
  810. (
  811. title,
  812. performer,
  813. duration,
  814. audio,
  815. thumbnail,
  816. ) = music
  817. m = await app.send_audio(
  818. MESSAGE_DUMP_CHAT,
  819. audio,
  820. title=title,
  821. duration=duration,
  822. performer=performer,
  823. thumb=thumbnail,
  824. )
  825. os.remove(audio)
  826. os.remove(thumbnail)
  827. answers.append(
  828. InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_id)
  829. )
  830. return answers
  831. async def carbon_inline_func(answers, link):
  832. link = link.split("/")
  833. if link[3] == "c":
  834. chat, message_id = int("-100" + link[4]), int(link[5])
  835. else:
  836. chat, message_id = link[3], link[4]
  837. m = await app.get_messages(chat, message_ids=int(message_id))
  838. if not m.text and not m.document:
  839. m = await app2.get_messages(chat, message_ids=int(message_id))
  840. if m.text:
  841. content = m.text
  842. else:
  843. if m.document.file_size > 1048576:
  844. answers.append(
  845. InlineQueryResultArticle(
  846. title="DOCUMENT TOO BIG",
  847. description="Maximum supported size is 1MB",
  848. input_message_content=InputTextMessageContent(
  849. "DOCUMENT TOO BIG"
  850. ),
  851. )
  852. )
  853. return answers
  854. doc = await m.download()
  855. async with aiofiles.open(doc, mode="r") as f:
  856. content = await f.read()
  857. os.remove(doc)
  858. image = await make_carbon(content)
  859. link = await paste(content)
  860. # To Pre-cache the media
  861. carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
  862. os.remove(image)
  863. buttons = InlineKeyboard(row_width=1)
  864. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  865. answers.append(
  866. InlineQueryResultCachedDocument(
  867. file_id=carbon.document.file_id,
  868. title="Carbon",
  869. reply_markup=buttons,
  870. )
  871. )
  872. return answers
  873. async def user_info_inline_func(answers, user):
  874. caption, photo_id = await get_user_info(user)
  875. answers.append(
  876. InlineQueryResultArticle(
  877. title="Found User.",
  878. input_message_content=InputTextMessageContent(
  879. caption, disable_web_page_preview=True
  880. ),
  881. )
  882. )
  883. return answers
  884. async def chat_info_inline_func(answers, chat):
  885. caption, photo_id = await get_chat_info(chat)
  886. answers.append(
  887. InlineQueryResultArticle(
  888. title="Found Chat.",
  889. input_message_content=InputTextMessageContent(
  890. caption, disable_web_page_preview=True
  891. ),
  892. )
  893. )
  894. return answers
  895. async def tmdb_func(answers, query):
  896. response = await arq.tmdb(query)
  897. if not response.ok:
  898. answers.append(
  899. InlineQueryResultArticle(
  900. title="Error",
  901. description=response.result,
  902. input_message_content=InputTextMessageContent(response.result),
  903. )
  904. )
  905. return answers
  906. results = response.result[0:48]
  907. for result in results:
  908. if not result.poster and not result.backdrop:
  909. continue
  910. if not result.genre:
  911. genre = None
  912. else:
  913. genre = " | ".join(result.genre)
  914. description = result.overview[0:900] if result.overview else "None"
  915. caption = f"""
  916. **{result.title}**
  917. **Type:** {result.type}
  918. **Rating:** {result.rating}
  919. **Genre:** {genre}
  920. **Release Date:** {result.releaseDate}
  921. **Description:** __{description}__
  922. """
  923. buttons = InlineKeyboard(row_width=1)
  924. buttons.add(
  925. InlineKeyboardButton(
  926. "Search Again", switch_inline_query_current_chat="tmdb"
  927. )
  928. )
  929. answers.append(
  930. InlineQueryResultPhoto(
  931. photo_url=result.backdrop
  932. if result.backdrop
  933. else result.poster,
  934. caption=caption,
  935. title=result.title,
  936. description=f"{genre} • {result.releaseDate} • {result.rating} • {description}",
  937. reply_markup=buttons,
  938. )
  939. )
  940. return answers
  941. async def pypiSearchFunc(answers: list, query: str) -> list:
  942. result = await arq.pypi(query)
  943. if not result.ok:
  944. answers.append(
  945. InlineQueryResultArticle(
  946. title="No Such Package",
  947. description=result.result,
  948. input_message_content=InputTextMessageContent(result.result),
  949. )
  950. )
  951. return answers
  952. result = result.result
  953. pURLS = [
  954. f"**{key}**: {value}" for key, value in result.projectURLS.items()
  955. ]
  956. pURLS = ("\n" + "\n".join(pURLS)) if pURLS else None
  957. caption = f"""
  958. **Name:** {result.name}
  959. **Version:** {result.version}
  960. **License:** {result.license}
  961. **Description:** {result.description}
  962. **Size:** {result.size}
  963. **Last Update:** {result.uploadTime}
  964. **Author:** {result.author}
  965. **Author's Email:** {result.authorEmail}
  966. **Requirements:** {(f'`{" | ".join(result.requirements)}`') if result.requirements else None}
  967. **Minimum Python Version:** {result.minPyVersion}
  968. **Homepage:** {result.homepage}
  969. **Bug Tracker:** {result.bugTrackURL}
  970. **Docs Url:** {result.docsURL}
  971. **Pypi Url:** {result.pypiURL}
  972. **Releases:** {result.releaseURL}
  973. **Project Urls:** ->{pURLS}
  974. """
  975. button = InlineKeyboard(row_width=2)
  976. button.add(
  977. InlineKeyboardButton(text="Open Page", url=result.pypiURL),
  978. InlineKeyboardButton(
  979. text="Search Again", switch_inline_query_current_chat="pypi"
  980. ),
  981. )
  982. answers.append(
  983. InlineQueryResultArticle(
  984. title=f"{result.name} | {result.version}",
  985. description=result.description,
  986. input_message_content=InputTextMessageContent(
  987. caption, disable_web_page_preview=True
  988. ),
  989. reply_markup=button,
  990. )
  991. )
  992. return answers
  993. async def randomAudioFunc(answers: list, query: str) -> list:
  994. url = f"https://www.zedge.net/api-zedge-web/browse/search?query={query}&contentType=ringtones"
  995. async with aiohttpsession.get(url) as resp:
  996. data = await resp.json()
  997. items = data['items']
  998. answers = [
  999. InlineQueryResultAudio(
  1000. audio_url=audio['audioUrl'],
  1001. thumb_url="https://tweety.drk1.workers.dev/0:/image_2021-05-22_20-56-47.png",
  1002. title=audio['title'],
  1003. mime_type="audio/mp3"
  1004. ) for audio in items
  1005. ]
  1006. return answers