inlinefuncs.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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. ]
  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("Go Inline!", switch_inline_query_current_chat=""),
  110. )
  111. msg = f"""
  112. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  113. **MainBot:** `{bot_state}`
  114. **UserBot:** `{ubot_state}`
  115. **Python:** `{pyver.split()[0]}`
  116. **Pyrogram:** `{pyrover}`
  117. **MongoDB:** `{mongover}`
  118. **Platform:** `{sys.platform}`
  119. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  120. """
  121. answers.append(
  122. InlineQueryResultArticle(
  123. title="Alive",
  124. description="Check Bot's Stats",
  125. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  126. input_message_content=InputTextMessageContent(
  127. msg, disable_web_page_preview=True
  128. ),
  129. reply_markup=buttons,
  130. )
  131. )
  132. return answers
  133. async def translate_func(answers, lang, tex):
  134. i = Translator().translate(tex, dest=lang)
  135. msg = f"""
  136. __**Translated from {i.src} to {lang}**__
  137. **INPUT:**
  138. {tex}
  139. **OUTPUT:**
  140. {i.text}"""
  141. answers.extend(
  142. [
  143. InlineQueryResultArticle(
  144. title=f"Translated from {i.src} to {lang}.",
  145. description=i.text,
  146. input_message_content=InputTextMessageContent(msg),
  147. ),
  148. InlineQueryResultArticle(
  149. title=i.text, input_message_content=InputTextMessageContent(i.text)
  150. ),
  151. ]
  152. )
  153. return answers
  154. async def urban_func(answers, text):
  155. results = await arq.urbandict(text)
  156. if not results.ok:
  157. answers.append(
  158. InlineQueryResultArticle(
  159. title="Error",
  160. description=results.result,
  161. input_message_content=InputTextMessageContent(results.result),
  162. )
  163. )
  164. return answers
  165. results = results.result
  166. limit = 0
  167. for i in results:
  168. if limit > 48:
  169. break
  170. limit += 1
  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. limit = 0
  218. results = results.result
  219. for i in results:
  220. if limit > 48:
  221. break
  222. limit += 1
  223. answers.append(
  224. InlineQueryResultPhoto(
  225. photo_url=i.url_image,
  226. thumb_url=i.url_thumb,
  227. caption=f"[Source]({i.url_image})",
  228. )
  229. )
  230. return answers
  231. async def saavn_func(answers, text):
  232. buttons_list = []
  233. results = await arq.saavn(text)
  234. if not results.ok:
  235. answers.append(
  236. InlineQueryResultArticle(
  237. title="Error",
  238. description=results.result,
  239. input_message_content=InputTextMessageContent(results.result),
  240. )
  241. )
  242. return answers
  243. results = results.result
  244. for count, i in enumerate(results):
  245. buttons = InlineKeyboard(row_width=1)
  246. buttons.add(InlineKeyboardButton("Download | Play", url=i.media_url))
  247. buttons_list.append(buttons)
  248. duration = await time_convert(i.duration)
  249. caption = f"""
  250. **Title:** {i.song}
  251. **Album:** {i.album}
  252. **Duration:** {duration}
  253. **Release:** {i.year}
  254. **Singers:** {i.singers}"""
  255. description = (
  256. f"{i.album} | {duration} "
  257. + f"| {i.singers} ({i.year})"
  258. )
  259. answers.append(
  260. InlineQueryResultArticle(
  261. title=i.song,
  262. input_message_content=InputTextMessageContent(
  263. caption, disable_web_page_preview=True
  264. ),
  265. description=description,
  266. thumb_url=i.image,
  267. reply_markup=buttons_list[count],
  268. )
  269. )
  270. return answers
  271. async def deezer_func(answers, text):
  272. buttons_list = []
  273. results = await arq.deezer(text, 5)
  274. if not results.ok:
  275. answers.append(
  276. InlineQueryResultArticle(
  277. title="Error",
  278. description=results.result,
  279. input_message_content=InputTextMessageContent(results.result),
  280. )
  281. )
  282. return answers
  283. results = results.result
  284. for count, i in enumerate(results):
  285. buttons = InlineKeyboard(row_width=1)
  286. buttons.add(InlineKeyboardButton("Download | Play", url=i.url))
  287. buttons_list.append(buttons)
  288. duration = await time_convert(i.duration)
  289. caption = f"""
  290. **Title:** {i.title}
  291. **Artist:** {i.artist}
  292. **Duration:** {duration}
  293. **Source:** [Deezer]({i.source})"""
  294. description = f"{i.artist} | {duration}"
  295. answers.append(
  296. InlineQueryResultArticle(
  297. title=i.title,
  298. thumb_url=i.thumbnail,
  299. description=description,
  300. input_message_content=InputTextMessageContent(
  301. caption, disable_web_page_preview=True
  302. ),
  303. reply_markup=buttons_list[count],
  304. )
  305. )
  306. return answers
  307. # Used my api key here, don't fuck with it
  308. async def shortify(url):
  309. if "." not in url:
  310. return
  311. header = {
  312. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  313. "Content-Type": "application/json",
  314. }
  315. payload = {"long_url": f"{url}"}
  316. payload = json.dumps(payload)
  317. async with aiohttp.ClientSession() as session:
  318. async with session.post(
  319. "https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload
  320. ) as resp:
  321. data = await resp.json()
  322. msg = data["link"]
  323. a = []
  324. b = InlineQueryResultArticle(
  325. title="Link Shortened!",
  326. description=data["link"],
  327. input_message_content=InputTextMessageContent(
  328. msg, disable_web_page_preview=True
  329. ),
  330. )
  331. a.append(b)
  332. return a
  333. async def torrent_func(answers, text):
  334. results = await arq.torrent(text)
  335. if not results.ok:
  336. answers.append(
  337. InlineQueryResultArticle(
  338. title="Error",
  339. description=results.result,
  340. input_message_content=InputTextMessageContent(results.result),
  341. )
  342. )
  343. return answers
  344. limit = 0
  345. results = results.result
  346. for i in results:
  347. if limit > 48:
  348. break
  349. title = i.name
  350. size = i.size
  351. seeds = i.seeds
  352. leechs = i.leechs
  353. upload_date = i.uploaded + " Ago"
  354. magnet = i.magnet
  355. caption = f"""
  356. **Title:** __{title}__
  357. **Size:** __{size}__
  358. **Seeds:** __{seeds}__
  359. **Leechs:** __{leechs}__
  360. **Uploaded:** __{upload_date}__
  361. **Magnet:** `{magnet}`"""
  362. description = f"{size} | {upload_date} | Seeds: {seeds}"
  363. answers.append(
  364. InlineQueryResultArticle(
  365. title=title,
  366. description=description,
  367. input_message_content=InputTextMessageContent(
  368. caption, disable_web_page_preview=True
  369. ),
  370. )
  371. )
  372. limit += 1
  373. pass
  374. return answers
  375. async def youtube_func(answers, text):
  376. results = await arq.youtube(text)
  377. if not results.ok:
  378. answers.append(
  379. InlineQueryResultArticle(
  380. title="Error",
  381. description=results.result,
  382. input_message_content=InputTextMessageContent(results.result),
  383. )
  384. )
  385. return answers
  386. limit = 0
  387. results = results.result
  388. for i in results:
  389. if limit > 48:
  390. break
  391. limit += 1
  392. buttons = InlineKeyboard(row_width=1)
  393. video_url = f"https://youtube.com{i.url_suffix}"
  394. buttons.add(InlineKeyboardButton("Watch", url=video_url))
  395. caption = f"""
  396. **Title:** {i.title}
  397. **Views:** {i.views}
  398. **Channel:** {i.channel}
  399. **Duration:** {i.duration}
  400. **Uploaded:** {i.publish_time}
  401. **Description:** {i.long_desc}"""
  402. description = (
  403. f"{i.views} | {i.channel} | "
  404. + f"{i.duration} | {i.publish_time}"
  405. )
  406. answers.append(
  407. InlineQueryResultArticle(
  408. title=i.title,
  409. thumb_url=i.thumbnails[0],
  410. description=description,
  411. input_message_content=InputTextMessageContent(
  412. caption, disable_web_page_preview=True
  413. ),
  414. reply_markup=buttons,
  415. )
  416. )
  417. return answers
  418. async def lyrics_func(answers, text):
  419. song = await arq.lyrics(text)
  420. if not song.ok:
  421. answers.append(
  422. InlineQueryResultArticle(
  423. title="Error",
  424. description=song.result,
  425. input_message_content=InputTextMessageContent(song.result),
  426. )
  427. )
  428. return answers
  429. lyrics = song.result
  430. song = lyrics.splitlines()
  431. song_name = song[0]
  432. artist = song[1]
  433. if len(lyrics) > 4095:
  434. lyrics = await paste(lyrics)
  435. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  436. msg = f"__{lyrics}__"
  437. answers.append(
  438. InlineQueryResultArticle(
  439. title=song_name,
  440. description=artist,
  441. input_message_content=InputTextMessageContent(msg),
  442. )
  443. )
  444. return answers
  445. async def github_user_func(answers, text):
  446. URL = f"https://api.github.com/users/{text}"
  447. result = await fetch(URL)
  448. buttons = InlineKeyboard(row_width=1)
  449. buttons.add(
  450. InlineKeyboardButton(text="Open On Github", url=f"https://github.com/{text}")
  451. )
  452. caption = f"""
  453. **Info Of {result['name']}**
  454. **Username:** `{text}`
  455. **Bio:** `{result['bio']}`
  456. **Profile Link:** [Here]({result['html_url']})
  457. **Company:** `{result['company']}`
  458. **Created On:** `{result['created_at']}`
  459. **Repositories:** `{result['public_repos']}`
  460. **Blog:** `{result['blog']}`
  461. **Location:** `{result['location']}`
  462. **Followers:** `{result['followers']}`
  463. **Following:** `{result['following']}`"""
  464. answers.append(
  465. InlineQueryResultPhoto(
  466. photo_url=result["avatar_url"], caption=caption, 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("Open On Github", url=f"https://github.com/{text}")
  486. )
  487. caption = f"""
  488. **Info Of {r['full_name']}**
  489. **Stars:** `{r['stargazers_count']}`
  490. **Watchers:** `{r['watchers_count']}`
  491. **Forks:** `{r['forks_count']}`
  492. **Commits:** `{commits}`
  493. **Is Fork:** `{r['fork']}`
  494. **Language:** `{r['language']}`
  495. **Contributors:** `{len(r1)}`
  496. **License:** `{r['license']['name'] if r['license'] else None}`
  497. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  498. **Created On:** `{r['created_at']}`
  499. **Homepage:** {r['homepage']}
  500. **Description:** __{r['description']}__"""
  501. answers.append(
  502. InlineQueryResultArticle(
  503. title="Found Repo",
  504. description=text,
  505. reply_markup=buttons,
  506. input_message_content=InputTextMessageContent(
  507. caption, disable_web_page_preview=True
  508. ),
  509. )
  510. )
  511. return answers
  512. async def tg_search_func(answers, text, user_id):
  513. if user_id not in SUDOERS:
  514. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  515. answers.append(
  516. InlineQueryResultArticle(
  517. title="ERROR",
  518. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  519. input_message_content=InputTextMessageContent(msg),
  520. )
  521. )
  522. return answers
  523. if str(text)[-1] != ":":
  524. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  525. answers.append(
  526. InlineQueryResultArticle(
  527. title="ERROR",
  528. description="Put A ':' After The Text To Search",
  529. input_message_content=InputTextMessageContent(msg),
  530. )
  531. )
  532. return answers
  533. text = text[0:-1]
  534. async for message in app2.search_global(text, limit=49):
  535. buttons = InlineKeyboard(row_width=2)
  536. buttons.add(
  537. InlineKeyboardButton(
  538. text="Origin",
  539. url=message.link if message.link else "https://t.me/telegram",
  540. ),
  541. InlineKeyboardButton(
  542. text="Search again", switch_inline_query_current_chat="search"
  543. ),
  544. )
  545. name = (
  546. message.from_user.first_name if message.from_user.first_name else "NO NAME"
  547. )
  548. caption = f"""
  549. **Query:** {text}
  550. **Name:** {str(name)} [`{message.from_user.id}`]
  551. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  552. **Date:** {ctime(message.date)}
  553. **Text:** >>
  554. {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
  555. """
  556. result = InlineQueryResultArticle(
  557. title=name,
  558. description=message.text if message.text else "[NO_TEXT]",
  559. reply_markup=buttons,
  560. input_message_content=InputTextMessageContent(
  561. caption, disable_web_page_preview=True
  562. ),
  563. )
  564. answers.append(result)
  565. return answers
  566. async def music_inline_func(answers, query):
  567. chat_id = -1001445180719
  568. group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
  569. try:
  570. messages = [
  571. m
  572. async for m in app2.search_messages(
  573. chat_id, query, filter="audio", limit=199
  574. )
  575. ]
  576. except Exception as e:
  577. print(e)
  578. msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
  579. answers.append(
  580. InlineQueryResultArticle(
  581. title="ERROR",
  582. description="Click Here To Know More.",
  583. input_message_content=InputTextMessageContent(
  584. msg, disable_web_page_preview=True
  585. ),
  586. )
  587. )
  588. return answers
  589. messages_ids_and_duration = []
  590. for f_ in messages:
  591. messages_ids_and_duration.append(
  592. {
  593. "message_id": f_.message_id,
  594. "duration": f_.audio.duration if f_.audio.duration else 0,
  595. }
  596. )
  597. messages = list({v["duration"]: v for v in messages_ids_and_duration}.values())
  598. messages_ids = []
  599. for ff_ in messages:
  600. messages_ids.append(ff_["message_id"])
  601. messages = await app.get_messages(chat_id, messages_ids[0:48])
  602. for message_ in messages:
  603. answers.append(
  604. InlineQueryResultCachedDocument(
  605. file_id=message_.audio.file_id, title=message_.audio.title
  606. )
  607. )
  608. return answers
  609. async def wiki_func(answers, text):
  610. data = await arq.wiki(text)
  611. if not data.ok:
  612. answers.append(
  613. InlineQueryResultArticle(
  614. title="Error",
  615. description=data.result,
  616. input_message_content=InputTextMessageContent(data.result),
  617. )
  618. )
  619. return answers
  620. data = data.result
  621. msg = f"""
  622. **QUERY:**
  623. {data.title}
  624. **ANSWER:**
  625. __{data.answer}__"""
  626. answers.append(
  627. InlineQueryResultArticle(
  628. title=data.title,
  629. description=data.answer,
  630. input_message_content=InputTextMessageContent(msg),
  631. )
  632. )
  633. return answers
  634. async def speedtest_init(query):
  635. answers = []
  636. user_id = query.from_user.id
  637. if user_id not in SUDOERS:
  638. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  639. answers.append(
  640. InlineQueryResultArticle(
  641. title="ERROR",
  642. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  643. input_message_content=InputTextMessageContent(msg),
  644. )
  645. )
  646. return answers
  647. msg = "**Click The Button Below To Perform A Speedtest**"
  648. button = InlineKeyboard(row_width=1)
  649. button.add(InlineKeyboardButton(text="Test", callback_data="test_speedtest"))
  650. answers.append(
  651. InlineQueryResultArticle(
  652. title="Click Here",
  653. input_message_content=InputTextMessageContent(msg),
  654. reply_markup=button,
  655. )
  656. )
  657. return answers
  658. """ callback query for the function above """
  659. @app.on_callback_query(filters.regex("test_speedtest"))
  660. async def test_speedtest_cq(_, cq):
  661. if cq.from_user.id not in SUDOERS:
  662. await cq.answer("This Isn't For You!")
  663. return
  664. inline_message_id = cq.inline_message_id
  665. await app.edit_inline_text(inline_message_id, "**Testing**")
  666. download, upload, info = await test_speedtest()
  667. msg = f"""
  668. **Download:** `{download}`
  669. **Upload:** `{upload}`
  670. **Latency:** `{info['latency']} ms`
  671. **Country:** `{info['country']} [{info['cc']}]`
  672. **Latitude:** `{info['lat']}`
  673. **Longitude:** `{info['lon']}`
  674. """
  675. await app.edit_inline_text(inline_message_id, msg)
  676. async def pastebin_func(answers, link):
  677. link = link.split("/")
  678. if link[3] == "c":
  679. chat, message_id = int("-100" + link[4]), int(link[5])
  680. else:
  681. chat, message_id = link[3], link[4]
  682. m = await app.get_messages(chat, message_ids=int(message_id))
  683. if not m.text and not m.document:
  684. m = await app2.get_messages(chat, message_ids=int(message_id))
  685. if m.text:
  686. content = m.text
  687. else:
  688. if m.document.file_size > 1048576:
  689. answers.append(
  690. InlineQueryResultArticle(
  691. title="DOCUMENT TOO BIG",
  692. description="Maximum supported size is 1MB",
  693. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  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(InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons))
  715. return answers
  716. async def pmpermit_func(answers, user_id, victim):
  717. if user_id != USERBOT_ID:
  718. return
  719. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  720. buttons = InlineKeyboard(row_width=2)
  721. buttons.add(
  722. InlineKeyboardButton(
  723. text="To Scam You", callback_data="pmpermit to_scam_you a"
  724. ),
  725. InlineKeyboardButton(
  726. text="For promotion", callback_data="pmpermit to_scam_you a"
  727. ),
  728. InlineKeyboardButton(text="Approve me", callback_data="pmpermit approve_me a"),
  729. InlineKeyboardButton(
  730. text="Approve", callback_data=f"pmpermit approve {victim}"
  731. ),
  732. )
  733. answers.append(
  734. InlineQueryResultArticle(
  735. title="do_not_click_here",
  736. reply_markup=buttons,
  737. input_message_content=InputTextMessageContent(caption),
  738. )
  739. )
  740. return answers
  741. async def ping_func(answers):
  742. t1 = time()
  743. ping = Ping(ping_id=randint(696969, 6969696))
  744. await app.send(ping)
  745. t2 = time()
  746. ping = f"{str(round((t2 - t1), 6) * 100)} ms"
  747. answers.append(
  748. InlineQueryResultArticle(
  749. title=ping, input_message_content=InputTextMessageContent(f"__**{ping}**__")
  750. )
  751. )
  752. return answers
  753. async def nsfw_scan_func(answers, url: str):
  754. t1 = time()
  755. data = await arq.nsfw_scan(url)
  756. if not data.ok:
  757. answers.append(
  758. InlineQueryResultArticle(
  759. title="Error",
  760. description=data.result,
  761. input_message_content=InputTextMessageContent(data.result),
  762. )
  763. )
  764. return answers
  765. t2 = time()
  766. tt = round(t2 - t1, 4)
  767. data = data.result
  768. content = f"""
  769. **Scanned [Image]({url}) In {tt} Seconds.**
  770. **Drawings:** `{data.drawings} %`
  771. **Neutral:** `{data.neutral} %`
  772. **Hentai:** `{data.hentai} %`
  773. **Porn:** `{data.porn} %`
  774. **Sexy:** `{data.sexy} %`
  775. """
  776. answers.append(
  777. InlineQueryResultArticle(
  778. title="Scanned",
  779. description=f"Took {tt} Seconds.",
  780. input_message_content=InputTextMessageContent(content),
  781. )
  782. )
  783. return answers
  784. async def yt_music_func(answers, url, user_id):
  785. if user_id not in SUDOERS:
  786. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  787. answers.append(
  788. InlineQueryResultArticle(
  789. title="ERROR",
  790. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  791. input_message_content=InputTextMessageContent(msg),
  792. )
  793. )
  794. return answers
  795. if "http" not in url:
  796. url = (await arq.youtube(url)).result[0]
  797. url = f"https://youtube.com{url.url_suffix}"
  798. title, performer, duration, audio, thumbnail = await download_youtube_audio(url)
  799. m = await app.send_audio(
  800. MESSAGE_DUMP_CHAT,
  801. audio,
  802. title=title,
  803. duration=duration,
  804. performer=performer,
  805. thumb=thumbnail,
  806. )
  807. os.remove(audio)
  808. os.remove(thumbnail)
  809. answers.append(
  810. InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_id)
  811. )
  812. return answers
  813. async def carbon_inline_func(answers, link):
  814. link = link.split("/")
  815. if link[3] == "c":
  816. chat, message_id = int("-100" + link[4]), int(link[5])
  817. else:
  818. chat, message_id = link[3], link[4]
  819. m = await app.get_messages(chat, message_ids=int(message_id))
  820. if not m.text and not m.document:
  821. m = await app2.get_messages(chat, message_ids=int(message_id))
  822. if m.text:
  823. content = m.text
  824. else:
  825. if m.document.file_size > 1048576:
  826. answers.append(
  827. InlineQueryResultArticle(
  828. title="DOCUMENT TOO BIG",
  829. description="Maximum supported size is 1MB",
  830. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  831. )
  832. )
  833. return answers
  834. doc = await m.download()
  835. async with aiofiles.open(doc, mode="r") as f:
  836. content = await f.read()
  837. os.remove(doc)
  838. image = await make_carbon(content)
  839. link = await paste(content)
  840. # To Pre-cache the media
  841. carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
  842. os.remove(image)
  843. buttons = InlineKeyboard(row_width=1)
  844. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  845. answers.append(
  846. InlineQueryResultCachedDocument(
  847. file_id=carbon.document.file_id, title="Carbon", reply_markup=buttons
  848. )
  849. )
  850. return answers
  851. async def user_info_inline_func(answers, user):
  852. caption, photo_id = await get_user_info(user)
  853. answers.append(
  854. InlineQueryResultArticle(
  855. title="Found User.",
  856. input_message_content=InputTextMessageContent(
  857. caption, disable_web_page_preview=True
  858. ),
  859. )
  860. )
  861. return answers
  862. async def chat_info_inline_func(answers, chat):
  863. caption, photo_id = await get_chat_info(chat)
  864. answers.append(
  865. InlineQueryResultArticle(
  866. title="Found Chat.",
  867. input_message_content=InputTextMessageContent(
  868. caption, disable_web_page_preview=True
  869. ),
  870. )
  871. )
  872. return answers