inlinefuncs.py 30 KB

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