inlinefuncs.py 25 KB

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