inlinefuncs.py 28 KB

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