inlinefuncs.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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, input_message_content=InputTextMessageContent(i.text)
  151. ),
  152. ]
  153. )
  154. return answers
  155. async def urban_func(answers, text):
  156. results = await arq.urbandict(text)
  157. if not results.ok:
  158. answers.append(
  159. InlineQueryResultArticle(
  160. title="Error",
  161. description=results.result,
  162. input_message_content=InputTextMessageContent(results.result),
  163. )
  164. )
  165. return answers
  166. results = results.result[0:48]
  167. for i in results:
  168. msg = f"""
  169. **Query:** {text}
  170. **Definition:** __{i.definition}__
  171. **Example:** __{i.example}__"""
  172. answers.append(
  173. InlineQueryResultArticle(
  174. title=i.word,
  175. description=i.definition,
  176. input_message_content=InputTextMessageContent(msg),
  177. )
  178. )
  179. return answers
  180. async def google_search_func(answers, text):
  181. gresults = await GoogleSearch().async_search(text)
  182. limit = 0
  183. for i in gresults:
  184. if limit > 48:
  185. break
  186. limit += 1
  187. try:
  188. msg = f"""
  189. [{i['titles']}]({i['links']})
  190. {i['descriptions']}"""
  191. answers.append(
  192. InlineQueryResultArticle(
  193. title=i["titles"],
  194. description=i["descriptions"],
  195. input_message_content=InputTextMessageContent(
  196. msg, disable_web_page_preview=True
  197. ),
  198. )
  199. )
  200. except KeyError:
  201. pass
  202. return answers
  203. async def wall_func(answers, text):
  204. results = await arq.wall(text)
  205. if not results.ok:
  206. answers.append(
  207. InlineQueryResultArticle(
  208. title="Error",
  209. description=results.result,
  210. input_message_content=InputTextMessageContent(results.result),
  211. )
  212. )
  213. return answers
  214. results = results.result[0:48]
  215. for i in results:
  216. answers.append(
  217. InlineQueryResultPhoto(
  218. photo_url=i.url_image,
  219. thumb_url=i.url_thumb,
  220. caption=f"[Source]({i.url_image})",
  221. )
  222. )
  223. return answers
  224. async def saavn_func(answers, text):
  225. buttons_list = []
  226. results = await arq.saavn(text)
  227. if not results.ok:
  228. answers.append(
  229. InlineQueryResultArticle(
  230. title="Error",
  231. description=results.result,
  232. input_message_content=InputTextMessageContent(results.result),
  233. )
  234. )
  235. return answers
  236. results = results.result
  237. for count, i in enumerate(results):
  238. buttons = InlineKeyboard(row_width=1)
  239. buttons.add(InlineKeyboardButton("Download | Play", url=i.media_url))
  240. buttons_list.append(buttons)
  241. duration = await time_convert(i.duration)
  242. caption = f"""
  243. **Title:** {i.song}
  244. **Album:** {i.album}
  245. **Duration:** {duration}
  246. **Release:** {i.year}
  247. **Singers:** {i.singers}"""
  248. description = f"{i.album} | {duration} " + f"| {i.singers} ({i.year})"
  249. answers.append(
  250. InlineQueryResultArticle(
  251. title=i.song,
  252. input_message_content=InputTextMessageContent(
  253. caption, disable_web_page_preview=True
  254. ),
  255. description=description,
  256. thumb_url=i.image,
  257. reply_markup=buttons_list[count],
  258. )
  259. )
  260. return answers
  261. async def deezer_func(answers, text):
  262. buttons_list = []
  263. results = await arq.deezer(text, 5)
  264. if not results.ok:
  265. answers.append(
  266. InlineQueryResultArticle(
  267. title="Error",
  268. description=results.result,
  269. input_message_content=InputTextMessageContent(results.result),
  270. )
  271. )
  272. return answers
  273. results = results.result
  274. for count, i in enumerate(results):
  275. buttons = InlineKeyboard(row_width=1)
  276. buttons.add(InlineKeyboardButton("Download | Play", url=i.url))
  277. buttons_list.append(buttons)
  278. duration = await time_convert(i.duration)
  279. caption = f"""
  280. **Title:** {i.title}
  281. **Artist:** {i.artist}
  282. **Duration:** {duration}
  283. **Source:** [Deezer]({i.source})"""
  284. description = f"{i.artist} | {duration}"
  285. answers.append(
  286. InlineQueryResultArticle(
  287. title=i.title,
  288. thumb_url=i.thumbnail,
  289. description=description,
  290. input_message_content=InputTextMessageContent(
  291. caption, disable_web_page_preview=True
  292. ),
  293. reply_markup=buttons_list[count],
  294. )
  295. )
  296. return answers
  297. # Used my api key here, don't fuck with it
  298. async def shortify(url):
  299. if "." not in url:
  300. return
  301. header = {
  302. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  303. "Content-Type": "application/json",
  304. }
  305. payload = {"long_url": f"{url}"}
  306. payload = json.dumps(payload)
  307. async with aiohttp.ClientSession() as session:
  308. async with session.post(
  309. "https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload
  310. ) as resp:
  311. data = await resp.json()
  312. msg = data["link"]
  313. a = []
  314. b = InlineQueryResultArticle(
  315. title="Link Shortened!",
  316. description=data["link"],
  317. input_message_content=InputTextMessageContent(
  318. msg, disable_web_page_preview=True
  319. ),
  320. )
  321. a.append(b)
  322. return a
  323. async def torrent_func(answers, text):
  324. results = await arq.torrent(text)
  325. if not results.ok:
  326. answers.append(
  327. InlineQueryResultArticle(
  328. title="Error",
  329. description=results.result,
  330. input_message_content=InputTextMessageContent(results.result),
  331. )
  332. )
  333. return answers
  334. results = results.result[0:48]
  335. for i in results:
  336. title = i.name
  337. size = i.size
  338. seeds = i.seeds
  339. leechs = i.leechs
  340. upload_date = i.uploaded
  341. magnet = i.magnet
  342. caption = f"""
  343. **Title:** __{title}__
  344. **Size:** __{size}__
  345. **Seeds:** __{seeds}__
  346. **Leechs:** __{leechs}__
  347. **Uploaded:** __{upload_date}__
  348. **Magnet:** `{magnet}`"""
  349. description = f"{size} | {upload_date} | Seeds: {seeds}"
  350. answers.append(
  351. InlineQueryResultArticle(
  352. title=title,
  353. description=description,
  354. input_message_content=InputTextMessageContent(
  355. caption, disable_web_page_preview=True
  356. ),
  357. )
  358. )
  359. pass
  360. return answers
  361. async def youtube_func(answers, text):
  362. results = await arq.youtube(text)
  363. if not results.ok:
  364. answers.append(
  365. InlineQueryResultArticle(
  366. title="Error",
  367. description=results.result,
  368. input_message_content=InputTextMessageContent(results.result),
  369. )
  370. )
  371. return answers
  372. results = results.result[0:48]
  373. for i in results:
  374. buttons = InlineKeyboard(row_width=1)
  375. video_url = f"https://youtube.com{i.url_suffix}"
  376. buttons.add(InlineKeyboardButton("Watch", url=video_url))
  377. caption = f"""
  378. **Title:** {i.title}
  379. **Views:** {i.views}
  380. **Channel:** {i.channel}
  381. **Duration:** {i.duration}
  382. **Uploaded:** {i.publish_time}
  383. **Description:** {i.long_desc}"""
  384. description = f"{i.views} | {i.channel} | " + f"{i.duration} | {i.publish_time}"
  385. answers.append(
  386. InlineQueryResultArticle(
  387. title=i.title,
  388. thumb_url=i.thumbnails[0],
  389. description=description,
  390. input_message_content=InputTextMessageContent(
  391. caption, disable_web_page_preview=True
  392. ),
  393. reply_markup=buttons,
  394. )
  395. )
  396. return answers
  397. async def lyrics_func(answers, text):
  398. song = await arq.lyrics(text)
  399. if not song.ok:
  400. answers.append(
  401. InlineQueryResultArticle(
  402. title="Error",
  403. description=song.result,
  404. input_message_content=InputTextMessageContent(song.result),
  405. )
  406. )
  407. return answers
  408. lyrics = song.result
  409. song = lyrics.splitlines()
  410. song_name = song[0]
  411. artist = song[1]
  412. if len(lyrics) > 4095:
  413. lyrics = await paste(lyrics)
  414. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  415. msg = f"__{lyrics}__"
  416. answers.append(
  417. InlineQueryResultArticle(
  418. title=song_name,
  419. description=artist,
  420. input_message_content=InputTextMessageContent(msg),
  421. )
  422. )
  423. return answers
  424. async def github_user_func(answers, text):
  425. URL = f"https://api.github.com/users/{text}"
  426. result = await fetch(URL)
  427. buttons = InlineKeyboard(row_width=1)
  428. buttons.add(
  429. InlineKeyboardButton(text="Open On Github", 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"], caption=caption, reply_markup=buttons
  446. )
  447. )
  448. return answers
  449. async def github_repo_func(answers, text):
  450. text = text.replace("https://github.com/", "")
  451. text = text.replace("http://github.com/", "")
  452. if text[-1] == "/":
  453. text = text[0:-1]
  454. URL = f"https://api.github.com/repos/{text}"
  455. URL2 = f"https://api.github.com/repos/{text}/contributors"
  456. results = await asyncio.gather(fetch(URL), fetch(URL2))
  457. r = results[0]
  458. r1 = results[1]
  459. commits = 0
  460. for developer in r1:
  461. commits += developer["contributions"]
  462. buttons = InlineKeyboard(row_width=1)
  463. buttons.add(
  464. InlineKeyboardButton("Open On Github", url=f"https://github.com/{text}")
  465. )
  466. caption = f"""
  467. **Info Of {r['full_name']}**
  468. **Stars:** `{r['stargazers_count']}`
  469. **Watchers:** `{r['watchers_count']}`
  470. **Forks:** `{r['forks_count']}`
  471. **Commits:** `{commits}`
  472. **Is Fork:** `{r['fork']}`
  473. **Language:** `{r['language']}`
  474. **Contributors:** `{len(r1)}`
  475. **License:** `{r['license']['name'] if r['license'] else None}`
  476. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  477. **Created On:** `{r['created_at']}`
  478. **Homepage:** {r['homepage']}
  479. **Description:** __{r['description']}__"""
  480. answers.append(
  481. InlineQueryResultArticle(
  482. title="Found Repo",
  483. description=text,
  484. reply_markup=buttons,
  485. input_message_content=InputTextMessageContent(
  486. caption, disable_web_page_preview=True
  487. ),
  488. )
  489. )
  490. return answers
  491. async def tg_search_func(answers, text, user_id):
  492. if user_id not in SUDOERS:
  493. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  494. answers.append(
  495. InlineQueryResultArticle(
  496. title="ERROR",
  497. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  498. input_message_content=InputTextMessageContent(msg),
  499. )
  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. )
  511. return answers
  512. text = text[0:-1]
  513. async for message in app2.search_global(text, limit=49):
  514. buttons = InlineKeyboard(row_width=2)
  515. buttons.add(
  516. InlineKeyboardButton(
  517. text="Origin",
  518. url=message.link if message.link else "https://t.me/telegram",
  519. ),
  520. InlineKeyboardButton(
  521. text="Search again", switch_inline_query_current_chat="search"
  522. ),
  523. )
  524. name = (
  525. message.from_user.first_name if message.from_user.first_name else "NO NAME"
  526. )
  527. caption = f"""
  528. **Query:** {text}
  529. **Name:** {str(name)} [`{message.from_user.id}`]
  530. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  531. **Date:** {ctime(message.date)}
  532. **Text:** >>
  533. {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
  534. """
  535. result = InlineQueryResultArticle(
  536. title=name,
  537. description=message.text if message.text else "[NO_TEXT]",
  538. reply_markup=buttons,
  539. input_message_content=InputTextMessageContent(
  540. caption, disable_web_page_preview=True
  541. ),
  542. )
  543. answers.append(result)
  544. return answers
  545. async def music_inline_func(answers, query):
  546. chat_id = -1001445180719
  547. group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
  548. try:
  549. messages = [
  550. m
  551. async for m in app2.search_messages(
  552. chat_id, query, filter="audio", limit=199
  553. )
  554. ]
  555. except Exception as e:
  556. print(e)
  557. msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
  558. answers.append(
  559. InlineQueryResultArticle(
  560. title="ERROR",
  561. description="Click Here To Know More.",
  562. input_message_content=InputTextMessageContent(
  563. msg, disable_web_page_preview=True
  564. ),
  565. )
  566. )
  567. return answers
  568. messages_ids_and_duration = []
  569. for f_ in messages:
  570. messages_ids_and_duration.append(
  571. {
  572. "message_id": f_.message_id,
  573. "duration": f_.audio.duration if f_.audio.duration else 0,
  574. }
  575. )
  576. messages = list({v["duration"]: v for v in messages_ids_and_duration}.values())
  577. messages_ids = []
  578. for ff_ in messages:
  579. messages_ids.append(ff_["message_id"])
  580. messages = await app.get_messages(chat_id, messages_ids[0:48])
  581. for message_ in messages:
  582. answers.append(
  583. InlineQueryResultCachedDocument(
  584. file_id=message_.audio.file_id, title=message_.audio.title
  585. )
  586. )
  587. return answers
  588. async def wiki_func(answers, text):
  589. data = await arq.wiki(text)
  590. if not data.ok:
  591. answers.append(
  592. InlineQueryResultArticle(
  593. title="Error",
  594. description=data.result,
  595. input_message_content=InputTextMessageContent(data.result),
  596. )
  597. )
  598. return answers
  599. data = data.result
  600. msg = f"""
  601. **QUERY:**
  602. {data.title}
  603. **ANSWER:**
  604. __{data.answer}__"""
  605. answers.append(
  606. InlineQueryResultArticle(
  607. title=data.title,
  608. description=data.answer,
  609. input_message_content=InputTextMessageContent(msg),
  610. )
  611. )
  612. return answers
  613. async def speedtest_init(query):
  614. answers = []
  615. user_id = query.from_user.id
  616. if user_id not in SUDOERS:
  617. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  618. answers.append(
  619. InlineQueryResultArticle(
  620. title="ERROR",
  621. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  622. input_message_content=InputTextMessageContent(msg),
  623. )
  624. )
  625. return answers
  626. msg = "**Click The Button Below To Perform A Speedtest**"
  627. button = InlineKeyboard(row_width=1)
  628. button.add(InlineKeyboardButton(text="Test", callback_data="test_speedtest"))
  629. answers.append(
  630. InlineQueryResultArticle(
  631. title="Click Here",
  632. input_message_content=InputTextMessageContent(msg),
  633. reply_markup=button,
  634. )
  635. )
  636. return answers
  637. """ callback query for the function above """
  638. @app.on_callback_query(filters.regex("test_speedtest"))
  639. async def test_speedtest_cq(_, cq):
  640. if cq.from_user.id not in SUDOERS:
  641. await cq.answer("This Isn't For You!")
  642. return
  643. inline_message_id = cq.inline_message_id
  644. await app.edit_inline_text(inline_message_id, "**Testing**")
  645. download, upload, info = await test_speedtest()
  646. msg = f"""
  647. **Download:** `{download}`
  648. **Upload:** `{upload}`
  649. **Latency:** `{info['latency']} ms`
  650. **Country:** `{info['country']} [{info['cc']}]`
  651. **Latitude:** `{info['lat']}`
  652. **Longitude:** `{info['lon']}`
  653. """
  654. await app.edit_inline_text(inline_message_id, msg)
  655. async def pastebin_func(answers, link):
  656. link = link.split("/")
  657. if link[3] == "c":
  658. chat, message_id = int("-100" + link[4]), int(link[5])
  659. else:
  660. chat, message_id = link[3], link[4]
  661. m = await app.get_messages(chat, message_ids=int(message_id))
  662. if not m.text and not m.document:
  663. m = await app2.get_messages(chat, message_ids=int(message_id))
  664. if m.text:
  665. content = m.text
  666. else:
  667. if m.document.file_size > 1048576:
  668. answers.append(
  669. InlineQueryResultArticle(
  670. title="DOCUMENT TOO BIG",
  671. description="Maximum supported size is 1MB",
  672. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  673. )
  674. )
  675. return answers
  676. doc = await m.download()
  677. async with aiofiles.open(doc, mode="r") as f:
  678. content = await f.read()
  679. os.remove(doc)
  680. link = await paste(content)
  681. preview = link + "/preview.png"
  682. status_code = await get_http_status_code(preview)
  683. i = 0
  684. while status_code != 200:
  685. if i == 5:
  686. break
  687. status_code = await get_http_status_code(preview)
  688. await asyncio.sleep(0.2)
  689. i += 1
  690. await app.send_photo(MESSAGE_DUMP_CHAT, preview) # To Pre-cache the media
  691. buttons = InlineKeyboard(row_width=1)
  692. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  693. answers.append(InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons))
  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", callback_data="pmpermit to_scam_you a"
  703. ),
  704. InlineKeyboardButton(
  705. text="For promotion", callback_data="pmpermit to_scam_you a"
  706. ),
  707. InlineKeyboardButton(text="Approve me", callback_data="pmpermit approve_me a"),
  708. InlineKeyboardButton(
  709. text="Approve", callback_data=f"pmpermit approve {victim}"
  710. ),
  711. )
  712. answers.append(
  713. InlineQueryResultArticle(
  714. title="do_not_click_here",
  715. reply_markup=buttons,
  716. input_message_content=InputTextMessageContent(caption),
  717. )
  718. )
  719. return answers
  720. async def ping_func(answers):
  721. t1 = time()
  722. ping = Ping(ping_id=randint(696969, 6969696))
  723. await app.send(ping)
  724. t2 = time()
  725. ping = f"{str(round((t2 - t1), 6) * 100)} ms"
  726. answers.append(
  727. InlineQueryResultArticle(
  728. title=ping, input_message_content=InputTextMessageContent(f"__**{ping}**__")
  729. )
  730. )
  731. return answers
  732. async def nsfw_scan_func(answers, url: str):
  733. t1 = time()
  734. data = await arq.nsfw_scan(url)
  735. if not data.ok:
  736. answers.append(
  737. InlineQueryResultArticle(
  738. title="Error",
  739. description=data.result,
  740. input_message_content=InputTextMessageContent(data.result),
  741. )
  742. )
  743. return answers
  744. t2 = time()
  745. tt = round(t2 - t1, 4)
  746. data = data.result
  747. content = f"""
  748. **Scanned [Image]({url}) In {tt} Seconds.**
  749. **Drawings:** `{data.drawings} %`
  750. **Neutral:** `{data.neutral} %`
  751. **Hentai:** `{data.hentai} %`
  752. **Porn:** `{data.porn} %`
  753. **Sexy:** `{data.sexy} %`
  754. """
  755. answers.append(
  756. InlineQueryResultArticle(
  757. title="Scanned",
  758. description=f"Took {tt} Seconds.",
  759. input_message_content=InputTextMessageContent(content),
  760. )
  761. )
  762. return answers
  763. async def yt_music_func(answers, url, user_id):
  764. if user_id not in SUDOERS:
  765. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  766. answers.append(
  767. InlineQueryResultArticle(
  768. title="ERROR",
  769. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  770. input_message_content=InputTextMessageContent(msg),
  771. )
  772. )
  773. return answers
  774. if "http" not in url:
  775. url = (await arq.youtube(url)).result[0]
  776. url = f"https://youtube.com{url.url_suffix}"
  777. title, performer, duration, audio, thumbnail = await download_youtube_audio(url)
  778. m = await app.send_audio(
  779. MESSAGE_DUMP_CHAT,
  780. audio,
  781. title=title,
  782. duration=duration,
  783. performer=performer,
  784. thumb=thumbnail,
  785. )
  786. os.remove(audio)
  787. os.remove(thumbnail)
  788. answers.append(
  789. InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_id)
  790. )
  791. return answers
  792. async def carbon_inline_func(answers, link):
  793. link = link.split("/")
  794. if link[3] == "c":
  795. chat, message_id = int("-100" + link[4]), int(link[5])
  796. else:
  797. chat, message_id = link[3], link[4]
  798. m = await app.get_messages(chat, message_ids=int(message_id))
  799. if not m.text and not m.document:
  800. m = await app2.get_messages(chat, message_ids=int(message_id))
  801. if m.text:
  802. content = m.text
  803. else:
  804. if m.document.file_size > 1048576:
  805. answers.append(
  806. InlineQueryResultArticle(
  807. title="DOCUMENT TOO BIG",
  808. description="Maximum supported size is 1MB",
  809. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  810. )
  811. )
  812. return answers
  813. doc = await m.download()
  814. async with aiofiles.open(doc, mode="r") as f:
  815. content = await f.read()
  816. os.remove(doc)
  817. image = await make_carbon(content)
  818. link = await paste(content)
  819. # To Pre-cache the media
  820. carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
  821. os.remove(image)
  822. buttons = InlineKeyboard(row_width=1)
  823. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  824. answers.append(
  825. InlineQueryResultCachedDocument(
  826. file_id=carbon.document.file_id, title="Carbon", 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(
  836. caption, disable_web_page_preview=True
  837. ),
  838. )
  839. )
  840. return answers
  841. async def chat_info_inline_func(answers, chat):
  842. caption, photo_id = await get_chat_info(chat)
  843. answers.append(
  844. InlineQueryResultArticle(
  845. title="Found Chat.",
  846. input_message_content=InputTextMessageContent(
  847. caption, disable_web_page_preview=True
  848. ),
  849. )
  850. )
  851. return answers
  852. async def tmdb_func(answers, query):
  853. response = await arq.tmdb(query)
  854. if not response.ok:
  855. answers.append(
  856. InlineQueryResultArticle(
  857. title="Error",
  858. description=response.result,
  859. input_message_content=InputTextMessageContent(response.result),
  860. )
  861. )
  862. return answers
  863. results = response.result[0:48]
  864. for result in results:
  865. if not result.poster and not result.backdrop:
  866. continue
  867. if not result.genre:
  868. genre = None
  869. else:
  870. genre = " | ".join(result.genre)
  871. description = result.overview[0:900] if result.overview else "None"
  872. caption = f"""
  873. **{result.title}**
  874. **Type:** {result.type}
  875. **Rating:** {result.rating}
  876. **Genre:** {genre}
  877. **Release Date:** {result.releaseDate}
  878. **Description:** __{description}__
  879. """
  880. buttons = InlineKeyboard(row_width=1)
  881. buttons.add(
  882. InlineKeyboardButton(
  883. "Search Again", switch_inline_query_current_chat="tmdb"
  884. )
  885. )
  886. answers.append(
  887. InlineQueryResultPhoto(
  888. photo_url=result.backdrop
  889. if result.backdrop
  890. else result.poster,
  891. caption=caption,
  892. title=result.title,
  893. description=f"{genre} • {result.releaseDate} • {result.rating} • {description}",
  894. reply_markup=buttons,
  895. )
  896. )
  897. return answers