inlinefuncs.py 27 KB

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