inlinefuncs.py 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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. import aiohttp
  29. from motor import version as mongover
  30. from pykeyboard import InlineKeyboard
  31. from pyrogram import __version__ as pyrover
  32. from pyrogram import filters
  33. from pyrogram.raw.functions import Ping
  34. from pyrogram.types import (InlineKeyboardButton, InlineQueryResultArticle,
  35. InlineQueryResultPhoto, InputTextMessageContent)
  36. from search_engine_parser import GoogleSearch
  37. from wbb import (BOT_USERNAME, MESSAGE_DUMP_CHAT, SUDOERS, USERBOT_ID,
  38. USERBOT_NAME, USERBOT_USERNAME, app, app2, arq)
  39. from wbb.core.types import InlineQueryResultCachedDocument
  40. from wbb.modules.info import get_chat_info, get_user_info
  41. from wbb.modules.music import download_youtube_audio
  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 (get_http_status_code, make_carbon,
  45. test_speedtest)
  46. from wbb.utils.pastebin import paste
  47. keywords_list = [
  48. "alive",
  49. "ping",
  50. "tr",
  51. "ud",
  52. "google",
  53. "bitly",
  54. "wall",
  55. "yt",
  56. "torrent",
  57. "lyrics",
  58. "wiki",
  59. "speedtest",
  60. "music",
  61. "saavn",
  62. "deezer",
  63. "gh_repo",
  64. "gh_user",
  65. "search",
  66. "paste",
  67. "nsfw_scan",
  68. "ytmusic",
  69. "carbon",
  70. "info",
  71. "chat_info",
  72. "tmdb",
  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 aiohttp.ClientSession() as session:
  322. async with session.post(
  323. "https://api-ssl.bitly.com/v4/shorten",
  324. headers=header,
  325. data=payload,
  326. ) as resp:
  327. data = await resp.json()
  328. msg = data["link"]
  329. a = []
  330. b = InlineQueryResultArticle(
  331. title="Link Shortened!",
  332. description=data["link"],
  333. input_message_content=InputTextMessageContent(
  334. msg, disable_web_page_preview=True
  335. ),
  336. )
  337. a.append(b)
  338. return a
  339. async def torrent_func(answers, text):
  340. results = await arq.torrent(text)
  341. if not results.ok:
  342. answers.append(
  343. InlineQueryResultArticle(
  344. title="Error",
  345. description=results.result,
  346. input_message_content=InputTextMessageContent(results.result),
  347. )
  348. )
  349. return answers
  350. results = results.result[0:48]
  351. for i in results:
  352. title = i.name
  353. size = i.size
  354. seeds = i.seeds
  355. leechs = i.leechs
  356. upload_date = i.uploaded
  357. magnet = i.magnet
  358. caption = f"""
  359. **Title:** __{title}__
  360. **Size:** __{size}__
  361. **Seeds:** __{seeds}__
  362. **Leechs:** __{leechs}__
  363. **Uploaded:** __{upload_date}__
  364. **Magnet:** `{magnet}`"""
  365. description = f"{size} | {upload_date} | Seeds: {seeds}"
  366. answers.append(
  367. InlineQueryResultArticle(
  368. title=title,
  369. description=description,
  370. input_message_content=InputTextMessageContent(
  371. caption, disable_web_page_preview=True
  372. ),
  373. )
  374. )
  375. pass
  376. return answers
  377. async def youtube_func(answers, text):
  378. results = await arq.youtube(text)
  379. if not results.ok:
  380. answers.append(
  381. InlineQueryResultArticle(
  382. title="Error",
  383. description=results.result,
  384. input_message_content=InputTextMessageContent(results.result),
  385. )
  386. )
  387. return answers
  388. results = results.result[0:48]
  389. for i in results:
  390. buttons = InlineKeyboard(row_width=1)
  391. video_url = f"https://youtube.com{i.url_suffix}"
  392. buttons.add(InlineKeyboardButton("Watch", url=video_url))
  393. caption = f"""
  394. **Title:** {i.title}
  395. **Views:** {i.views}
  396. **Channel:** {i.channel}
  397. **Duration:** {i.duration}
  398. **Uploaded:** {i.publish_time}
  399. **Description:** {i.long_desc}"""
  400. description = (
  401. f"{i.views} | {i.channel} | {i.duration} | {i.publish_time}"
  402. )
  403. answers.append(
  404. InlineQueryResultArticle(
  405. title=i.title,
  406. thumb_url=i.thumbnails[0],
  407. description=description,
  408. input_message_content=InputTextMessageContent(
  409. caption, disable_web_page_preview=True
  410. ),
  411. reply_markup=buttons,
  412. )
  413. )
  414. return answers
  415. async def lyrics_func(answers, text):
  416. song = await arq.lyrics(text)
  417. if not song.ok:
  418. answers.append(
  419. InlineQueryResultArticle(
  420. title="Error",
  421. description=song.result,
  422. input_message_content=InputTextMessageContent(song.result),
  423. )
  424. )
  425. return answers
  426. lyrics = song.result
  427. song = lyrics.splitlines()
  428. song_name = song[0]
  429. artist = song[1]
  430. if len(lyrics) > 4095:
  431. lyrics = await paste(lyrics)
  432. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  433. msg = f"__{lyrics}__"
  434. answers.append(
  435. InlineQueryResultArticle(
  436. title=song_name,
  437. description=artist,
  438. input_message_content=InputTextMessageContent(msg),
  439. )
  440. )
  441. return answers
  442. async def github_user_func(answers, text):
  443. URL = f"https://api.github.com/users/{text}"
  444. result = await fetch(URL)
  445. buttons = InlineKeyboard(row_width=1)
  446. buttons.add(
  447. InlineKeyboardButton(
  448. text="Open On Github", url=f"https://github.com/{text}"
  449. )
  450. )
  451. caption = f"""
  452. **Info Of {result['name']}**
  453. **Username:** `{text}`
  454. **Bio:** `{result['bio']}`
  455. **Profile Link:** [Here]({result['html_url']})
  456. **Company:** `{result['company']}`
  457. **Created On:** `{result['created_at']}`
  458. **Repositories:** `{result['public_repos']}`
  459. **Blog:** `{result['blog']}`
  460. **Location:** `{result['location']}`
  461. **Followers:** `{result['followers']}`
  462. **Following:** `{result['following']}`"""
  463. answers.append(
  464. InlineQueryResultPhoto(
  465. photo_url=result["avatar_url"],
  466. caption=caption,
  467. reply_markup=buttons,
  468. )
  469. )
  470. return answers
  471. async def github_repo_func(answers, text):
  472. text = text.replace("https://github.com/", "")
  473. text = text.replace("http://github.com/", "")
  474. if text[-1] == "/":
  475. text = text[0:-1]
  476. URL = f"https://api.github.com/repos/{text}"
  477. URL2 = f"https://api.github.com/repos/{text}/contributors"
  478. results = await asyncio.gather(fetch(URL), fetch(URL2))
  479. r = results[0]
  480. r1 = results[1]
  481. commits = 0
  482. for developer in r1:
  483. commits += developer["contributions"]
  484. buttons = InlineKeyboard(row_width=1)
  485. buttons.add(
  486. InlineKeyboardButton(
  487. "Open On Github", url=f"https://github.com/{text}"
  488. )
  489. )
  490. caption = f"""
  491. **Info Of {r['full_name']}**
  492. **Stars:** `{r['stargazers_count']}`
  493. **Watchers:** `{r['watchers_count']}`
  494. **Forks:** `{r['forks_count']}`
  495. **Commits:** `{commits}`
  496. **Is Fork:** `{r['fork']}`
  497. **Language:** `{r['language']}`
  498. **Contributors:** `{len(r1)}`
  499. **License:** `{r['license']['name'] if r['license'] else None}`
  500. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  501. **Created On:** `{r['created_at']}`
  502. **Homepage:** {r['homepage']}
  503. **Description:** __{r['description']}__"""
  504. answers.append(
  505. InlineQueryResultArticle(
  506. title="Found Repo",
  507. description=text,
  508. reply_markup=buttons,
  509. input_message_content=InputTextMessageContent(
  510. caption, disable_web_page_preview=True
  511. ),
  512. )
  513. )
  514. return answers
  515. async def tg_search_func(answers, text, user_id):
  516. if user_id not in SUDOERS:
  517. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  518. answers.append(
  519. InlineQueryResultArticle(
  520. title="ERROR",
  521. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  522. input_message_content=InputTextMessageContent(msg),
  523. )
  524. )
  525. return answers
  526. if str(text)[-1] != ":":
  527. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  528. answers.append(
  529. InlineQueryResultArticle(
  530. title="ERROR",
  531. description="Put A ':' After The Text To Search",
  532. input_message_content=InputTextMessageContent(msg),
  533. )
  534. )
  535. return answers
  536. text = text[0:-1]
  537. async for message in app2.search_global(text, limit=49):
  538. buttons = InlineKeyboard(row_width=2)
  539. buttons.add(
  540. InlineKeyboardButton(
  541. text="Origin",
  542. url=message.link if message.link else "https://t.me/telegram",
  543. ),
  544. InlineKeyboardButton(
  545. text="Search again", switch_inline_query_current_chat="search"
  546. ),
  547. )
  548. name = (
  549. message.from_user.first_name
  550. if message.from_user.first_name
  551. else "NO NAME"
  552. )
  553. caption = f"""
  554. **Query:** {text}
  555. **Name:** {str(name)} [`{message.from_user.id}`]
  556. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  557. **Date:** {ctime(message.date)}
  558. **Text:** >>
  559. {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
  560. """
  561. result = InlineQueryResultArticle(
  562. title=name,
  563. description=message.text if message.text else "[NO_TEXT]",
  564. reply_markup=buttons,
  565. input_message_content=InputTextMessageContent(
  566. caption, disable_web_page_preview=True
  567. ),
  568. )
  569. answers.append(result)
  570. return answers
  571. async def music_inline_func(answers, query):
  572. chat_id = -1001445180719
  573. group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
  574. try:
  575. messages = [
  576. m
  577. async for m in app2.search_messages(
  578. chat_id, query, filter="audio", limit=199
  579. )
  580. ]
  581. except Exception as e:
  582. print(e)
  583. msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
  584. answers.append(
  585. InlineQueryResultArticle(
  586. title="ERROR",
  587. description="Click Here To Know More.",
  588. input_message_content=InputTextMessageContent(
  589. msg, disable_web_page_preview=True
  590. ),
  591. )
  592. )
  593. return answers
  594. messages_ids_and_duration = []
  595. for f_ in messages:
  596. messages_ids_and_duration.append(
  597. {
  598. "message_id": f_.message_id,
  599. "duration": f_.audio.duration if f_.audio.duration else 0,
  600. }
  601. )
  602. messages = list(
  603. {v["duration"]: v for v in messages_ids_and_duration}.values()
  604. )
  605. messages_ids = []
  606. for ff_ in messages:
  607. messages_ids.append(ff_["message_id"])
  608. messages = await app.get_messages(chat_id, messages_ids[0:48])
  609. for message_ in messages:
  610. answers.append(
  611. InlineQueryResultCachedDocument(
  612. file_id=message_.audio.file_id, title=message_.audio.title
  613. )
  614. )
  615. return answers
  616. async def wiki_func(answers, text):
  617. data = await arq.wiki(text)
  618. if not data.ok:
  619. answers.append(
  620. InlineQueryResultArticle(
  621. title="Error",
  622. description=data.result,
  623. input_message_content=InputTextMessageContent(data.result),
  624. )
  625. )
  626. return answers
  627. data = data.result
  628. msg = f"""
  629. **QUERY:**
  630. {data.title}
  631. **ANSWER:**
  632. __{data.answer}__"""
  633. answers.append(
  634. InlineQueryResultArticle(
  635. title=data.title,
  636. description=data.answer,
  637. input_message_content=InputTextMessageContent(msg),
  638. )
  639. )
  640. return answers
  641. async def speedtest_init(query):
  642. answers = []
  643. user_id = query.from_user.id
  644. if user_id not in SUDOERS:
  645. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  646. answers.append(
  647. InlineQueryResultArticle(
  648. title="ERROR",
  649. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  650. input_message_content=InputTextMessageContent(msg),
  651. )
  652. )
  653. return answers
  654. msg = "**Click The Button Below To Perform A Speedtest**"
  655. button = InlineKeyboard(row_width=1)
  656. button.add(
  657. InlineKeyboardButton(text="Test", callback_data="test_speedtest")
  658. )
  659. answers.append(
  660. InlineQueryResultArticle(
  661. title="Click Here",
  662. input_message_content=InputTextMessageContent(msg),
  663. reply_markup=button,
  664. )
  665. )
  666. return answers
  667. """ callback query for the function above """
  668. @app.on_callback_query(filters.regex("test_speedtest"))
  669. async def test_speedtest_cq(_, cq):
  670. if cq.from_user.id not in SUDOERS:
  671. await cq.answer("This Isn't For You!")
  672. return
  673. inline_message_id = cq.inline_message_id
  674. await app.edit_inline_text(inline_message_id, "**Testing**")
  675. download, upload, info = await 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. status_code = await get_http_status_code(preview)
  715. i = 0
  716. while status_code != 200:
  717. if i == 5:
  718. break
  719. status_code = await get_http_status_code(preview)
  720. await asyncio.sleep(0.2)
  721. i += 1
  722. await app.send_photo(MESSAGE_DUMP_CHAT, preview) # To Pre-cache the media
  723. buttons = InlineKeyboard(row_width=1)
  724. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  725. answers.append(
  726. InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons)
  727. )
  728. return answers
  729. async def pmpermit_func(answers, user_id, victim):
  730. if user_id != USERBOT_ID:
  731. return
  732. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  733. buttons = InlineKeyboard(row_width=2)
  734. buttons.add(
  735. InlineKeyboardButton(
  736. text="To Scam You", callback_data="pmpermit to_scam_you a"
  737. ),
  738. InlineKeyboardButton(
  739. text="For promotion", callback_data="pmpermit to_scam_you a"
  740. ),
  741. InlineKeyboardButton(
  742. text="Approve me", callback_data="pmpermit approve_me a"
  743. ),
  744. InlineKeyboardButton(
  745. text="Approve", callback_data=f"pmpermit approve {victim}"
  746. ),
  747. )
  748. answers.append(
  749. InlineQueryResultArticle(
  750. title="do_not_click_here",
  751. reply_markup=buttons,
  752. input_message_content=InputTextMessageContent(caption),
  753. )
  754. )
  755. return answers
  756. async def ping_func(answers):
  757. t1 = time()
  758. ping = Ping(ping_id=randint(696969, 6969696))
  759. await app.send(ping)
  760. t2 = time()
  761. ping = f"{str(round((t2 - t1), 6) * 100)} ms"
  762. answers.append(
  763. InlineQueryResultArticle(
  764. title=ping,
  765. input_message_content=InputTextMessageContent(f"__**{ping}**__"),
  766. )
  767. )
  768. return answers
  769. async def nsfw_scan_func(answers, url: str):
  770. t1 = time()
  771. data = await arq.nsfw_scan(url)
  772. if not data.ok:
  773. answers.append(
  774. InlineQueryResultArticle(
  775. title="Error",
  776. description=data.result,
  777. input_message_content=InputTextMessageContent(data.result),
  778. )
  779. )
  780. return answers
  781. t2 = time()
  782. tt = round(t2 - t1, 4)
  783. data = data.result
  784. content = f"""
  785. **Scanned [Image]({url}) In {tt} Seconds.**
  786. **Drawings:** `{data.drawings} %`
  787. **Neutral:** `{data.neutral} %`
  788. **Hentai:** `{data.hentai} %`
  789. **Porn:** `{data.porn} %`
  790. **Sexy:** `{data.sexy} %`
  791. """
  792. answers.append(
  793. InlineQueryResultArticle(
  794. title="Scanned",
  795. description=f"Took {tt} Seconds.",
  796. input_message_content=InputTextMessageContent(content),
  797. )
  798. )
  799. return answers
  800. async def yt_music_func(answers, url, user_id):
  801. if user_id not in SUDOERS:
  802. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  803. answers.append(
  804. InlineQueryResultArticle(
  805. title="ERROR",
  806. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  807. input_message_content=InputTextMessageContent(msg),
  808. )
  809. )
  810. return answers
  811. if "http" not in url:
  812. url = (await arq.youtube(url)).result[0]
  813. url = f"https://youtube.com{url.url_suffix}"
  814. (
  815. title,
  816. performer,
  817. duration,
  818. audio,
  819. thumbnail,
  820. ) = await download_youtube_audio(url)
  821. m = await app.send_audio(
  822. MESSAGE_DUMP_CHAT,
  823. audio,
  824. title=title,
  825. duration=duration,
  826. performer=performer,
  827. thumb=thumbnail,
  828. )
  829. os.remove(audio)
  830. os.remove(thumbnail)
  831. answers.append(
  832. InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_id)
  833. )
  834. return answers
  835. async def carbon_inline_func(answers, link):
  836. link = link.split("/")
  837. if link[3] == "c":
  838. chat, message_id = int("-100" + link[4]), int(link[5])
  839. else:
  840. chat, message_id = link[3], link[4]
  841. m = await app.get_messages(chat, message_ids=int(message_id))
  842. if not m.text and not m.document:
  843. m = await app2.get_messages(chat, message_ids=int(message_id))
  844. if m.text:
  845. content = m.text
  846. else:
  847. if m.document.file_size > 1048576:
  848. answers.append(
  849. InlineQueryResultArticle(
  850. title="DOCUMENT TOO BIG",
  851. description="Maximum supported size is 1MB",
  852. input_message_content=InputTextMessageContent(
  853. "DOCUMENT TOO BIG"
  854. ),
  855. )
  856. )
  857. return answers
  858. doc = await m.download()
  859. async with aiofiles.open(doc, mode="r") as f:
  860. content = await f.read()
  861. os.remove(doc)
  862. image = await make_carbon(content)
  863. link = await paste(content)
  864. # To Pre-cache the media
  865. carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
  866. os.remove(image)
  867. buttons = InlineKeyboard(row_width=1)
  868. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  869. answers.append(
  870. InlineQueryResultCachedDocument(
  871. file_id=carbon.document.file_id,
  872. title="Carbon",
  873. reply_markup=buttons,
  874. )
  875. )
  876. return answers
  877. async def user_info_inline_func(answers, user):
  878. caption, photo_id = await get_user_info(user)
  879. answers.append(
  880. InlineQueryResultArticle(
  881. title="Found User.",
  882. input_message_content=InputTextMessageContent(
  883. caption, disable_web_page_preview=True
  884. ),
  885. )
  886. )
  887. return answers
  888. async def chat_info_inline_func(answers, chat):
  889. caption, photo_id = await get_chat_info(chat)
  890. answers.append(
  891. InlineQueryResultArticle(
  892. title="Found Chat.",
  893. input_message_content=InputTextMessageContent(
  894. caption, disable_web_page_preview=True
  895. ),
  896. )
  897. )
  898. return answers
  899. async def tmdb_func(answers, query):
  900. response = await arq.tmdb(query)
  901. if not response.ok:
  902. answers.append(
  903. InlineQueryResultArticle(
  904. title="Error",
  905. description=response.result,
  906. input_message_content=InputTextMessageContent(response.result),
  907. )
  908. )
  909. return answers
  910. results = response.result[0:48]
  911. for result in results:
  912. if not result.poster and not result.backdrop:
  913. continue
  914. if not result.genre:
  915. genre = None
  916. else:
  917. genre = " | ".join(result.genre)
  918. description = result.overview[0:900] if result.overview else "None"
  919. caption = f"""
  920. **{result.title}**
  921. **Type:** {result.type}
  922. **Rating:** {result.rating}
  923. **Genre:** {genre}
  924. **Release Date:** {result.releaseDate}
  925. **Description:** __{description}__
  926. """
  927. buttons = InlineKeyboard(row_width=1)
  928. buttons.add(
  929. InlineKeyboardButton(
  930. "Search Again", switch_inline_query_current_chat="tmdb"
  931. )
  932. )
  933. answers.append(
  934. InlineQueryResultPhoto(
  935. photo_url=result.backdrop
  936. if result.backdrop
  937. else result.poster,
  938. caption=caption,
  939. title=result.title,
  940. description=f"{genre} • {result.releaseDate} • {result.rating} • {description}",
  941. reply_markup=buttons,
  942. )
  943. )
  944. return answers