inlinefuncs.py 30 KB

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