inlinefuncs.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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 = f"{i.album} | {duration} " + f"| {i.singers} ({i.year})"
  256. answers.append(
  257. InlineQueryResultArticle(
  258. title=i.song,
  259. input_message_content=InputTextMessageContent(
  260. caption, disable_web_page_preview=True
  261. ),
  262. description=description,
  263. thumb_url=i.image,
  264. reply_markup=buttons_list[count],
  265. )
  266. )
  267. return answers
  268. async def deezer_func(answers, text):
  269. buttons_list = []
  270. results = await arq.deezer(text, 5)
  271. if not results.ok:
  272. answers.append(
  273. InlineQueryResultArticle(
  274. title="Error",
  275. description=results.result,
  276. input_message_content=InputTextMessageContent(results.result),
  277. )
  278. )
  279. return answers
  280. results = results.result
  281. for count, i in enumerate(results):
  282. buttons = InlineKeyboard(row_width=1)
  283. buttons.add(InlineKeyboardButton("Download | Play", url=i.url))
  284. buttons_list.append(buttons)
  285. duration = await time_convert(i.duration)
  286. caption = f"""
  287. **Title:** {i.title}
  288. **Artist:** {i.artist}
  289. **Duration:** {duration}
  290. **Source:** [Deezer]({i.source})"""
  291. description = f"{i.artist} | {duration}"
  292. answers.append(
  293. InlineQueryResultArticle(
  294. title=i.title,
  295. thumb_url=i.thumbnail,
  296. description=description,
  297. input_message_content=InputTextMessageContent(
  298. caption, disable_web_page_preview=True
  299. ),
  300. reply_markup=buttons_list[count],
  301. )
  302. )
  303. return answers
  304. # Used my api key here, don't fuck with it
  305. async def shortify(url):
  306. if "." not in url:
  307. return
  308. header = {
  309. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  310. "Content-Type": "application/json",
  311. }
  312. payload = {"long_url": f"{url}"}
  313. payload = json.dumps(payload)
  314. async with aiohttp.ClientSession() as session:
  315. async with session.post(
  316. "https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload
  317. ) as resp:
  318. data = await resp.json()
  319. msg = data["link"]
  320. a = []
  321. b = InlineQueryResultArticle(
  322. title="Link Shortened!",
  323. description=data["link"],
  324. input_message_content=InputTextMessageContent(
  325. msg, disable_web_page_preview=True
  326. ),
  327. )
  328. a.append(b)
  329. return a
  330. async def torrent_func(answers, text):
  331. results = await arq.torrent(text)
  332. if not results.ok:
  333. answers.append(
  334. InlineQueryResultArticle(
  335. title="Error",
  336. description=results.result,
  337. input_message_content=InputTextMessageContent(results.result),
  338. )
  339. )
  340. return answers
  341. limit = 0
  342. results = results.result
  343. for i in results:
  344. if limit > 48:
  345. break
  346. title = i.name
  347. size = i.size
  348. seeds = i.seeds
  349. leechs = i.leechs
  350. upload_date = i.uploaded + " Ago"
  351. magnet = i.magnet
  352. caption = f"""
  353. **Title:** __{title}__
  354. **Size:** __{size}__
  355. **Seeds:** __{seeds}__
  356. **Leechs:** __{leechs}__
  357. **Uploaded:** __{upload_date}__
  358. **Magnet:** `{magnet}`"""
  359. description = f"{size} | {upload_date} | Seeds: {seeds}"
  360. answers.append(
  361. InlineQueryResultArticle(
  362. title=title,
  363. description=description,
  364. input_message_content=InputTextMessageContent(
  365. caption, disable_web_page_preview=True
  366. ),
  367. )
  368. )
  369. limit += 1
  370. pass
  371. return answers
  372. async def youtube_func(answers, text):
  373. results = await arq.youtube(text)
  374. if not results.ok:
  375. answers.append(
  376. InlineQueryResultArticle(
  377. title="Error",
  378. description=results.result,
  379. input_message_content=InputTextMessageContent(results.result),
  380. )
  381. )
  382. return answers
  383. limit = 0
  384. results = results.result
  385. for i in results:
  386. if limit > 48:
  387. break
  388. limit += 1
  389. buttons = InlineKeyboard(row_width=1)
  390. video_url = f"https://youtube.com{i.url_suffix}"
  391. buttons.add(InlineKeyboardButton("Watch", url=video_url))
  392. caption = f"""
  393. **Title:** {i.title}
  394. **Views:** {i.views}
  395. **Channel:** {i.channel}
  396. **Duration:** {i.duration}
  397. **Uploaded:** {i.publish_time}
  398. **Description:** {i.long_desc}"""
  399. description = f"{i.views} | {i.channel} | " + f"{i.duration} | {i.publish_time}"
  400. answers.append(
  401. InlineQueryResultArticle(
  402. title=i.title,
  403. thumb_url=i.thumbnails[0],
  404. description=description,
  405. input_message_content=InputTextMessageContent(
  406. caption, disable_web_page_preview=True
  407. ),
  408. reply_markup=buttons,
  409. )
  410. )
  411. return answers
  412. async def lyrics_func(answers, text):
  413. song = await arq.lyrics(text)
  414. if not song.ok:
  415. answers.append(
  416. InlineQueryResultArticle(
  417. title="Error",
  418. description=song.result,
  419. input_message_content=InputTextMessageContent(song.result),
  420. )
  421. )
  422. return answers
  423. lyrics = song.result
  424. song = lyrics.splitlines()
  425. song_name = song[0]
  426. artist = song[1]
  427. if len(lyrics) > 4095:
  428. lyrics = await paste(lyrics)
  429. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  430. msg = f"__{lyrics}__"
  431. answers.append(
  432. InlineQueryResultArticle(
  433. title=song_name,
  434. description=artist,
  435. input_message_content=InputTextMessageContent(msg),
  436. )
  437. )
  438. return answers
  439. async def github_user_func(answers, text):
  440. URL = f"https://api.github.com/users/{text}"
  441. result = await fetch(URL)
  442. buttons = InlineKeyboard(row_width=1)
  443. buttons.add(
  444. InlineKeyboardButton(text="Open On Github", url=f"https://github.com/{text}")
  445. )
  446. caption = f"""
  447. **Info Of {result['name']}**
  448. **Username:** `{text}`
  449. **Bio:** `{result['bio']}`
  450. **Profile Link:** [Here]({result['html_url']})
  451. **Company:** `{result['company']}`
  452. **Created On:** `{result['created_at']}`
  453. **Repositories:** `{result['public_repos']}`
  454. **Blog:** `{result['blog']}`
  455. **Location:** `{result['location']}`
  456. **Followers:** `{result['followers']}`
  457. **Following:** `{result['following']}`"""
  458. answers.append(
  459. InlineQueryResultPhoto(
  460. photo_url=result["avatar_url"], caption=caption, reply_markup=buttons
  461. )
  462. )
  463. return answers
  464. async def github_repo_func(answers, text):
  465. text = text.replace("https://github.com/", "")
  466. text = text.replace("http://github.com/", "")
  467. if text[-1] == "/":
  468. text = text[0:-1]
  469. URL = f"https://api.github.com/repos/{text}"
  470. URL2 = f"https://api.github.com/repos/{text}/contributors"
  471. results = await asyncio.gather(fetch(URL), fetch(URL2))
  472. r = results[0]
  473. r1 = results[1]
  474. commits = 0
  475. for developer in r1:
  476. commits += developer["contributions"]
  477. buttons = InlineKeyboard(row_width=1)
  478. buttons.add(
  479. InlineKeyboardButton("Open On Github", url=f"https://github.com/{text}")
  480. )
  481. caption = f"""
  482. **Info Of {r['full_name']}**
  483. **Stars:** `{r['stargazers_count']}`
  484. **Watchers:** `{r['watchers_count']}`
  485. **Forks:** `{r['forks_count']}`
  486. **Commits:** `{commits}`
  487. **Is Fork:** `{r['fork']}`
  488. **Language:** `{r['language']}`
  489. **Contributors:** `{len(r1)}`
  490. **License:** `{r['license']['name'] if r['license'] else None}`
  491. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  492. **Created On:** `{r['created_at']}`
  493. **Homepage:** {r['homepage']}
  494. **Description:** __{r['description']}__"""
  495. answers.append(
  496. InlineQueryResultArticle(
  497. title="Found Repo",
  498. description=text,
  499. reply_markup=buttons,
  500. input_message_content=InputTextMessageContent(
  501. caption, disable_web_page_preview=True
  502. ),
  503. )
  504. )
  505. return answers
  506. async def tg_search_func(answers, text, user_id):
  507. if user_id not in SUDOERS:
  508. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  509. answers.append(
  510. InlineQueryResultArticle(
  511. title="ERROR",
  512. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  513. input_message_content=InputTextMessageContent(msg),
  514. )
  515. )
  516. return answers
  517. if str(text)[-1] != ":":
  518. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  519. answers.append(
  520. InlineQueryResultArticle(
  521. title="ERROR",
  522. description="Put A ':' After The Text To Search",
  523. input_message_content=InputTextMessageContent(msg),
  524. )
  525. )
  526. return answers
  527. text = text[0:-1]
  528. async for message in app2.search_global(text, limit=49):
  529. buttons = InlineKeyboard(row_width=2)
  530. buttons.add(
  531. InlineKeyboardButton(
  532. text="Origin",
  533. url=message.link if message.link else "https://t.me/telegram",
  534. ),
  535. InlineKeyboardButton(
  536. text="Search again", switch_inline_query_current_chat="search"
  537. ),
  538. )
  539. name = (
  540. message.from_user.first_name if message.from_user.first_name 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({v["duration"]: v for v in messages_ids_and_duration}.values())
  592. messages_ids = []
  593. for ff_ in messages:
  594. messages_ids.append(ff_["message_id"])
  595. messages = await app.get_messages(chat_id, messages_ids[0:48])
  596. for message_ in messages:
  597. answers.append(
  598. InlineQueryResultCachedDocument(
  599. file_id=message_.audio.file_id, title=message_.audio.title
  600. )
  601. )
  602. return answers
  603. async def wiki_func(answers, text):
  604. data = await arq.wiki(text)
  605. if not data.ok:
  606. answers.append(
  607. InlineQueryResultArticle(
  608. title="Error",
  609. description=data.result,
  610. input_message_content=InputTextMessageContent(data.result),
  611. )
  612. )
  613. return answers
  614. data = data.result
  615. msg = f"""
  616. **QUERY:**
  617. {data.title}
  618. **ANSWER:**
  619. __{data.answer}__"""
  620. answers.append(
  621. InlineQueryResultArticle(
  622. title=data.title,
  623. description=data.answer,
  624. input_message_content=InputTextMessageContent(msg),
  625. )
  626. )
  627. return answers
  628. async def speedtest_init(query):
  629. answers = []
  630. user_id = query.from_user.id
  631. if user_id not in SUDOERS:
  632. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  633. answers.append(
  634. InlineQueryResultArticle(
  635. title="ERROR",
  636. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  637. input_message_content=InputTextMessageContent(msg),
  638. )
  639. )
  640. return answers
  641. msg = "**Click The Button Below To Perform A Speedtest**"
  642. button = InlineKeyboard(row_width=1)
  643. button.add(InlineKeyboardButton(text="Test", callback_data="test_speedtest"))
  644. answers.append(
  645. InlineQueryResultArticle(
  646. title="Click Here",
  647. input_message_content=InputTextMessageContent(msg),
  648. reply_markup=button,
  649. )
  650. )
  651. return answers
  652. """ callback query for the function above """
  653. @app.on_callback_query(filters.regex("test_speedtest"))
  654. async def test_speedtest_cq(_, cq):
  655. if cq.from_user.id not in SUDOERS:
  656. await cq.answer("This Isn't For You!")
  657. return
  658. inline_message_id = cq.inline_message_id
  659. await app.edit_inline_text(inline_message_id, "**Testing**")
  660. download, upload, info = await test_speedtest()
  661. msg = f"""
  662. **Download:** `{download}`
  663. **Upload:** `{upload}`
  664. **Latency:** `{info['latency']} ms`
  665. **Country:** `{info['country']} [{info['cc']}]`
  666. **Latitude:** `{info['lat']}`
  667. **Longitude:** `{info['lon']}`
  668. """
  669. await app.edit_inline_text(inline_message_id, msg)
  670. async def pastebin_func(answers, link):
  671. link = link.split("/")
  672. if link[3] == "c":
  673. chat, message_id = int("-100" + link[4]), int(link[5])
  674. else:
  675. chat, message_id = link[3], link[4]
  676. m = await app.get_messages(chat, message_ids=int(message_id))
  677. if not m.text and not m.document:
  678. m = await app2.get_messages(chat, message_ids=int(message_id))
  679. if m.text:
  680. content = m.text
  681. else:
  682. if m.document.file_size > 1048576:
  683. answers.append(
  684. InlineQueryResultArticle(
  685. title="DOCUMENT TOO BIG",
  686. description="Maximum supported size is 1MB",
  687. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  688. )
  689. )
  690. return answers
  691. doc = await m.download()
  692. async with aiofiles.open(doc, mode="r") as f:
  693. content = await f.read()
  694. os.remove(doc)
  695. link = await paste(content)
  696. preview = link + "/preview.png"
  697. status_code = await get_http_status_code(preview)
  698. i = 0
  699. while status_code != 200:
  700. if i == 5:
  701. break
  702. status_code = await get_http_status_code(preview)
  703. await asyncio.sleep(0.2)
  704. i += 1
  705. await app.send_photo(MESSAGE_DUMP_CHAT, preview) # To Pre-cache the media
  706. buttons = InlineKeyboard(row_width=1)
  707. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  708. answers.append(InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons))
  709. return answers
  710. async def pmpermit_func(answers, user_id, victim):
  711. if user_id != USERBOT_ID:
  712. return
  713. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  714. buttons = InlineKeyboard(row_width=2)
  715. buttons.add(
  716. InlineKeyboardButton(
  717. text="To Scam You", callback_data="pmpermit to_scam_you a"
  718. ),
  719. InlineKeyboardButton(
  720. text="For promotion", callback_data="pmpermit to_scam_you a"
  721. ),
  722. InlineKeyboardButton(text="Approve me", callback_data="pmpermit approve_me a"),
  723. InlineKeyboardButton(
  724. text="Approve", callback_data=f"pmpermit approve {victim}"
  725. ),
  726. )
  727. answers.append(
  728. InlineQueryResultArticle(
  729. title="do_not_click_here",
  730. reply_markup=buttons,
  731. input_message_content=InputTextMessageContent(caption),
  732. )
  733. )
  734. return answers
  735. async def ping_func(answers):
  736. t1 = time()
  737. ping = Ping(ping_id=randint(696969, 6969696))
  738. await app.send(ping)
  739. t2 = time()
  740. ping = f"{str(round((t2 - t1), 6) * 100)} ms"
  741. answers.append(
  742. InlineQueryResultArticle(
  743. title=ping, input_message_content=InputTextMessageContent(f"__**{ping}**__")
  744. )
  745. )
  746. return answers
  747. async def nsfw_scan_func(answers, url: str):
  748. t1 = time()
  749. data = await arq.nsfw_scan(url)
  750. if not data.ok:
  751. answers.append(
  752. InlineQueryResultArticle(
  753. title="Error",
  754. description=data.result,
  755. input_message_content=InputTextMessageContent(data.result),
  756. )
  757. )
  758. return answers
  759. t2 = time()
  760. tt = round(t2 - t1, 4)
  761. data = data.result
  762. content = f"""
  763. **Scanned [Image]({url}) In {tt} Seconds.**
  764. **Drawings:** `{data.drawings} %`
  765. **Neutral:** `{data.neutral} %`
  766. **Hentai:** `{data.hentai} %`
  767. **Porn:** `{data.porn} %`
  768. **Sexy:** `{data.sexy} %`
  769. """
  770. answers.append(
  771. InlineQueryResultArticle(
  772. title="Scanned",
  773. description=f"Took {tt} Seconds.",
  774. input_message_content=InputTextMessageContent(content),
  775. )
  776. )
  777. return answers
  778. async def yt_music_func(answers, url, user_id):
  779. if user_id not in SUDOERS:
  780. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  781. answers.append(
  782. InlineQueryResultArticle(
  783. title="ERROR",
  784. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  785. input_message_content=InputTextMessageContent(msg),
  786. )
  787. )
  788. return answers
  789. if "http" not in url:
  790. url = (await arq.youtube(url)).result[0]
  791. url = f"https://youtube.com{url.url_suffix}"
  792. title, performer, duration, audio, thumbnail = await download_youtube_audio(url)
  793. m = await app.send_audio(
  794. MESSAGE_DUMP_CHAT,
  795. audio,
  796. title=title,
  797. duration=duration,
  798. performer=performer,
  799. thumb=thumbnail,
  800. )
  801. os.remove(audio)
  802. os.remove(thumbnail)
  803. answers.append(
  804. InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_id)
  805. )
  806. return answers
  807. async def carbon_inline_func(answers, link):
  808. link = link.split("/")
  809. if link[3] == "c":
  810. chat, message_id = int("-100" + link[4]), int(link[5])
  811. else:
  812. chat, message_id = link[3], link[4]
  813. m = await app.get_messages(chat, message_ids=int(message_id))
  814. if not m.text and not m.document:
  815. m = await app2.get_messages(chat, message_ids=int(message_id))
  816. if m.text:
  817. content = m.text
  818. else:
  819. if m.document.file_size > 1048576:
  820. answers.append(
  821. InlineQueryResultArticle(
  822. title="DOCUMENT TOO BIG",
  823. description="Maximum supported size is 1MB",
  824. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  825. )
  826. )
  827. return answers
  828. doc = await m.download()
  829. async with aiofiles.open(doc, mode="r") as f:
  830. content = await f.read()
  831. os.remove(doc)
  832. image = await make_carbon(content)
  833. link = await paste(content)
  834. # To Pre-cache the media
  835. carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
  836. os.remove(image)
  837. buttons = InlineKeyboard(row_width=1)
  838. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  839. answers.append(
  840. InlineQueryResultCachedDocument(
  841. file_id=carbon.document.file_id, title="Carbon", reply_markup=buttons
  842. )
  843. )
  844. return answers
  845. async def user_info_inline_func(answers, user):
  846. caption, photo_id = await get_user_info(user)
  847. answers.append(
  848. InlineQueryResultArticle(
  849. title="Found User.",
  850. input_message_content=InputTextMessageContent(
  851. caption, disable_web_page_preview=True
  852. ),
  853. )
  854. )
  855. return answers
  856. async def chat_info_inline_func(answers, chat):
  857. caption, photo_id = await get_chat_info(chat)
  858. answers.append(
  859. InlineQueryResultArticle(
  860. title="Found Chat.",
  861. input_message_content=InputTextMessageContent(
  862. caption, disable_web_page_preview=True
  863. ),
  864. )
  865. )
  866. return answers