inlinefuncs.py 27 KB

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