inlinefuncs.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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 + " Ago"
  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. limit += 1
  360. pass
  361. return answers
  362. async def youtube_func(answers, text):
  363. results = await arq.youtube(text)
  364. if not results.ok:
  365. answers.append(
  366. InlineQueryResultArticle(
  367. title="Error",
  368. description=results.result,
  369. input_message_content=InputTextMessageContent(results.result),
  370. )
  371. )
  372. return answers
  373. results = results.result[0: 48]
  374. for i in results:
  375. buttons = InlineKeyboard(row_width=1)
  376. video_url = f"https://youtube.com{i.url_suffix}"
  377. buttons.add(InlineKeyboardButton("Watch", url=video_url))
  378. caption = f"""
  379. **Title:** {i.title}
  380. **Views:** {i.views}
  381. **Channel:** {i.channel}
  382. **Duration:** {i.duration}
  383. **Uploaded:** {i.publish_time}
  384. **Description:** {i.long_desc}"""
  385. description = f"{i.views} | {i.channel} | " + f"{i.duration} | {i.publish_time}"
  386. answers.append(
  387. InlineQueryResultArticle(
  388. title=i.title,
  389. thumb_url=i.thumbnails[0],
  390. description=description,
  391. input_message_content=InputTextMessageContent(
  392. caption, disable_web_page_preview=True
  393. ),
  394. reply_markup=buttons,
  395. )
  396. )
  397. return answers
  398. async def lyrics_func(answers, text):
  399. song = await arq.lyrics(text)
  400. if not song.ok:
  401. answers.append(
  402. InlineQueryResultArticle(
  403. title="Error",
  404. description=song.result,
  405. input_message_content=InputTextMessageContent(song.result),
  406. )
  407. )
  408. return answers
  409. lyrics = song.result
  410. song = lyrics.splitlines()
  411. song_name = song[0]
  412. artist = song[1]
  413. if len(lyrics) > 4095:
  414. lyrics = await paste(lyrics)
  415. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  416. msg = f"__{lyrics}__"
  417. answers.append(
  418. InlineQueryResultArticle(
  419. title=song_name,
  420. description=artist,
  421. input_message_content=InputTextMessageContent(msg),
  422. )
  423. )
  424. return answers
  425. async def github_user_func(answers, text):
  426. URL = f"https://api.github.com/users/{text}"
  427. result = await fetch(URL)
  428. buttons = InlineKeyboard(row_width=1)
  429. buttons.add(
  430. InlineKeyboardButton(text="Open On Github", url=f"https://github.com/{text}")
  431. )
  432. caption = f"""
  433. **Info Of {result['name']}**
  434. **Username:** `{text}`
  435. **Bio:** `{result['bio']}`
  436. **Profile Link:** [Here]({result['html_url']})
  437. **Company:** `{result['company']}`
  438. **Created On:** `{result['created_at']}`
  439. **Repositories:** `{result['public_repos']}`
  440. **Blog:** `{result['blog']}`
  441. **Location:** `{result['location']}`
  442. **Followers:** `{result['followers']}`
  443. **Following:** `{result['following']}`"""
  444. answers.append(
  445. InlineQueryResultPhoto(
  446. photo_url=result["avatar_url"], caption=caption, reply_markup=buttons
  447. )
  448. )
  449. return answers
  450. async def github_repo_func(answers, text):
  451. text = text.replace("https://github.com/", "")
  452. text = text.replace("http://github.com/", "")
  453. if text[-1] == "/":
  454. text = text[0:-1]
  455. URL = f"https://api.github.com/repos/{text}"
  456. URL2 = f"https://api.github.com/repos/{text}/contributors"
  457. results = await asyncio.gather(fetch(URL), fetch(URL2))
  458. r = results[0]
  459. r1 = results[1]
  460. commits = 0
  461. for developer in r1:
  462. commits += developer["contributions"]
  463. buttons = InlineKeyboard(row_width=1)
  464. buttons.add(
  465. InlineKeyboardButton("Open On Github", url=f"https://github.com/{text}")
  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, disable_web_page_preview=True
  488. ),
  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. )
  502. return answers
  503. if str(text)[-1] != ":":
  504. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  505. answers.append(
  506. InlineQueryResultArticle(
  507. title="ERROR",
  508. description="Put A ':' After The Text To Search",
  509. input_message_content=InputTextMessageContent(msg),
  510. )
  511. )
  512. return answers
  513. text = text[0:-1]
  514. async for message in app2.search_global(text, limit=49):
  515. buttons = InlineKeyboard(row_width=2)
  516. buttons.add(
  517. InlineKeyboardButton(
  518. text="Origin",
  519. url=message.link if message.link else "https://t.me/telegram",
  520. ),
  521. InlineKeyboardButton(
  522. text="Search again", switch_inline_query_current_chat="search"
  523. ),
  524. )
  525. name = (
  526. message.from_user.first_name if message.from_user.first_name else "NO NAME"
  527. )
  528. caption = f"""
  529. **Query:** {text}
  530. **Name:** {str(name)} [`{message.from_user.id}`]
  531. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  532. **Date:** {ctime(message.date)}
  533. **Text:** >>
  534. {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
  535. """
  536. result = InlineQueryResultArticle(
  537. title=name,
  538. description=message.text if message.text else "[NO_TEXT]",
  539. reply_markup=buttons,
  540. input_message_content=InputTextMessageContent(
  541. caption, disable_web_page_preview=True
  542. ),
  543. )
  544. answers.append(result)
  545. return answers
  546. async def music_inline_func(answers, query):
  547. chat_id = -1001445180719
  548. group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
  549. try:
  550. messages = [
  551. m
  552. async for m in app2.search_messages(
  553. chat_id, query, filter="audio", limit=199
  554. )
  555. ]
  556. except Exception as e:
  557. print(e)
  558. msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
  559. answers.append(
  560. InlineQueryResultArticle(
  561. title="ERROR",
  562. description="Click Here To Know More.",
  563. input_message_content=InputTextMessageContent(
  564. msg, disable_web_page_preview=True
  565. ),
  566. )
  567. )
  568. return answers
  569. messages_ids_and_duration = []
  570. for f_ in messages:
  571. messages_ids_and_duration.append(
  572. {
  573. "message_id": f_.message_id,
  574. "duration": f_.audio.duration if f_.audio.duration else 0,
  575. }
  576. )
  577. messages = list({v["duration"]: v for v in messages_ids_and_duration}.values())
  578. messages_ids = []
  579. for ff_ in messages:
  580. messages_ids.append(ff_["message_id"])
  581. messages = await app.get_messages(chat_id, messages_ids[0:48])
  582. for message_ in messages:
  583. answers.append(
  584. InlineQueryResultCachedDocument(
  585. file_id=message_.audio.file_id, title=message_.audio.title
  586. )
  587. )
  588. return answers
  589. async def wiki_func(answers, text):
  590. data = await arq.wiki(text)
  591. if not data.ok:
  592. answers.append(
  593. InlineQueryResultArticle(
  594. title="Error",
  595. description=data.result,
  596. input_message_content=InputTextMessageContent(data.result),
  597. )
  598. )
  599. return answers
  600. data = data.result
  601. msg = f"""
  602. **QUERY:**
  603. {data.title}
  604. **ANSWER:**
  605. __{data.answer}__"""
  606. answers.append(
  607. InlineQueryResultArticle(
  608. title=data.title,
  609. description=data.answer,
  610. input_message_content=InputTextMessageContent(msg),
  611. )
  612. )
  613. return answers
  614. async def speedtest_init(query):
  615. answers = []
  616. user_id = query.from_user.id
  617. if user_id not in SUDOERS:
  618. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  619. answers.append(
  620. InlineQueryResultArticle(
  621. title="ERROR",
  622. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  623. input_message_content=InputTextMessageContent(msg),
  624. )
  625. )
  626. return answers
  627. msg = "**Click The Button Below To Perform A Speedtest**"
  628. button = InlineKeyboard(row_width=1)
  629. button.add(InlineKeyboardButton(text="Test", callback_data="test_speedtest"))
  630. answers.append(
  631. InlineQueryResultArticle(
  632. title="Click Here",
  633. input_message_content=InputTextMessageContent(msg),
  634. reply_markup=button,
  635. )
  636. )
  637. return answers
  638. """ callback query for the function above """
  639. @app.on_callback_query(filters.regex("test_speedtest"))
  640. async def test_speedtest_cq(_, cq):
  641. if cq.from_user.id not in SUDOERS:
  642. await cq.answer("This Isn't For You!")
  643. return
  644. inline_message_id = cq.inline_message_id
  645. await app.edit_inline_text(inline_message_id, "**Testing**")
  646. download, upload, info = await test_speedtest()
  647. msg = f"""
  648. **Download:** `{download}`
  649. **Upload:** `{upload}`
  650. **Latency:** `{info['latency']} ms`
  651. **Country:** `{info['country']} [{info['cc']}]`
  652. **Latitude:** `{info['lat']}`
  653. **Longitude:** `{info['lon']}`
  654. """
  655. await app.edit_inline_text(inline_message_id, msg)
  656. async def pastebin_func(answers, link):
  657. link = link.split("/")
  658. if link[3] == "c":
  659. chat, message_id = int("-100" + link[4]), int(link[5])
  660. else:
  661. chat, message_id = link[3], link[4]
  662. m = await app.get_messages(chat, message_ids=int(message_id))
  663. if not m.text and not m.document:
  664. m = await app2.get_messages(chat, message_ids=int(message_id))
  665. if m.text:
  666. content = m.text
  667. else:
  668. if m.document.file_size > 1048576:
  669. answers.append(
  670. InlineQueryResultArticle(
  671. title="DOCUMENT TOO BIG",
  672. description="Maximum supported size is 1MB",
  673. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  674. )
  675. )
  676. return answers
  677. doc = await m.download()
  678. async with aiofiles.open(doc, mode="r") as f:
  679. content = await f.read()
  680. os.remove(doc)
  681. link = await paste(content)
  682. preview = link + "/preview.png"
  683. status_code = await get_http_status_code(preview)
  684. i = 0
  685. while status_code != 200:
  686. if i == 5:
  687. break
  688. status_code = await get_http_status_code(preview)
  689. await asyncio.sleep(0.2)
  690. i += 1
  691. await app.send_photo(MESSAGE_DUMP_CHAT, preview) # To Pre-cache the media
  692. buttons = InlineKeyboard(row_width=1)
  693. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  694. answers.append(InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons))
  695. return answers
  696. async def pmpermit_func(answers, user_id, victim):
  697. if user_id != USERBOT_ID:
  698. return
  699. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  700. buttons = InlineKeyboard(row_width=2)
  701. buttons.add(
  702. InlineKeyboardButton(
  703. text="To Scam You", callback_data="pmpermit to_scam_you a"
  704. ),
  705. InlineKeyboardButton(
  706. text="For promotion", callback_data="pmpermit to_scam_you a"
  707. ),
  708. InlineKeyboardButton(text="Approve me", callback_data="pmpermit approve_me a"),
  709. InlineKeyboardButton(
  710. text="Approve", callback_data=f"pmpermit approve {victim}"
  711. ),
  712. )
  713. answers.append(
  714. InlineQueryResultArticle(
  715. title="do_not_click_here",
  716. reply_markup=buttons,
  717. input_message_content=InputTextMessageContent(caption),
  718. )
  719. )
  720. return answers
  721. async def ping_func(answers):
  722. t1 = time()
  723. ping = Ping(ping_id=randint(696969, 6969696))
  724. await app.send(ping)
  725. t2 = time()
  726. ping = f"{str(round((t2 - t1), 6) * 100)} ms"
  727. answers.append(
  728. InlineQueryResultArticle(
  729. title=ping, input_message_content=InputTextMessageContent(f"__**{ping}**__")
  730. )
  731. )
  732. return answers
  733. async def nsfw_scan_func(answers, url: str):
  734. t1 = time()
  735. data = await arq.nsfw_scan(url)
  736. if not data.ok:
  737. answers.append(
  738. InlineQueryResultArticle(
  739. title="Error",
  740. description=data.result,
  741. input_message_content=InputTextMessageContent(data.result),
  742. )
  743. )
  744. return answers
  745. t2 = time()
  746. tt = round(t2 - t1, 4)
  747. data = data.result
  748. content = f"""
  749. **Scanned [Image]({url}) In {tt} Seconds.**
  750. **Drawings:** `{data.drawings} %`
  751. **Neutral:** `{data.neutral} %`
  752. **Hentai:** `{data.hentai} %`
  753. **Porn:** `{data.porn} %`
  754. **Sexy:** `{data.sexy} %`
  755. """
  756. answers.append(
  757. InlineQueryResultArticle(
  758. title="Scanned",
  759. description=f"Took {tt} Seconds.",
  760. input_message_content=InputTextMessageContent(content),
  761. )
  762. )
  763. return answers
  764. async def yt_music_func(answers, url, user_id):
  765. if user_id not in SUDOERS:
  766. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  767. answers.append(
  768. InlineQueryResultArticle(
  769. title="ERROR",
  770. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  771. input_message_content=InputTextMessageContent(msg),
  772. )
  773. )
  774. return answers
  775. if "http" not in url:
  776. url = (await arq.youtube(url)).result[0]
  777. url = f"https://youtube.com{url.url_suffix}"
  778. title, performer, duration, audio, thumbnail = await download_youtube_audio(url)
  779. m = await app.send_audio(
  780. MESSAGE_DUMP_CHAT,
  781. audio,
  782. title=title,
  783. duration=duration,
  784. performer=performer,
  785. thumb=thumbnail,
  786. )
  787. os.remove(audio)
  788. os.remove(thumbnail)
  789. answers.append(
  790. InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_id)
  791. )
  792. return answers
  793. async def carbon_inline_func(answers, link):
  794. link = link.split("/")
  795. if link[3] == "c":
  796. chat, message_id = int("-100" + link[4]), int(link[5])
  797. else:
  798. chat, message_id = link[3], link[4]
  799. m = await app.get_messages(chat, message_ids=int(message_id))
  800. if not m.text and not m.document:
  801. m = await app2.get_messages(chat, message_ids=int(message_id))
  802. if m.text:
  803. content = m.text
  804. else:
  805. if m.document.file_size > 1048576:
  806. answers.append(
  807. InlineQueryResultArticle(
  808. title="DOCUMENT TOO BIG",
  809. description="Maximum supported size is 1MB",
  810. input_message_content=InputTextMessageContent("DOCUMENT TOO BIG"),
  811. )
  812. )
  813. return answers
  814. doc = await m.download()
  815. async with aiofiles.open(doc, mode="r") as f:
  816. content = await f.read()
  817. os.remove(doc)
  818. image = await make_carbon(content)
  819. link = await paste(content)
  820. # To Pre-cache the media
  821. carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
  822. os.remove(image)
  823. buttons = InlineKeyboard(row_width=1)
  824. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  825. answers.append(
  826. InlineQueryResultCachedDocument(
  827. file_id=carbon.document.file_id, title="Carbon", reply_markup=buttons
  828. )
  829. )
  830. return answers
  831. async def user_info_inline_func(answers, user):
  832. caption, photo_id = await get_user_info(user)
  833. answers.append(
  834. InlineQueryResultArticle(
  835. title="Found User.",
  836. input_message_content=InputTextMessageContent(
  837. caption, disable_web_page_preview=True
  838. ),
  839. )
  840. )
  841. return answers
  842. async def chat_info_inline_func(answers, chat):
  843. caption, photo_id = await get_chat_info(chat)
  844. answers.append(
  845. InlineQueryResultArticle(
  846. title="Found Chat.",
  847. input_message_content=InputTextMessageContent(
  848. caption, disable_web_page_preview=True
  849. ),
  850. )
  851. )
  852. return answers
  853. async def tmdb_func(answers, query):
  854. response = await arq.tmdb(query)
  855. if not response.ok:
  856. answers.append(
  857. InlineQueryResultArticle(
  858. title="Error",
  859. description=response.result,
  860. input_message_content=InputTextMessageContent(response.result),
  861. )
  862. )
  863. return answers
  864. results = response.result[0:48]
  865. for result in results
  866. caption = f"""
  867. **{result.title}**
  868. **Type:** {result.type}
  869. **Rating:** {result.rating}
  870. **Genre:** {" | ".join(result.genre) if result.genre else None}
  871. **Release Date:** {result.releaseDate}
  872. **Description:** __{result.overview}__
  873. """
  874. buttons = InlineKeyboard(row_width=1)
  875. buttons.add(
  876. InlineKeyboardButton("Search Again", switch_inline_query_current_chat="tmdb")
  877. )
  878. answers.append(
  879. InlineQueryResultPhoto(
  880. photo_url=result.backdrop if result.backdrop else result.poster if result.poster else "https://cdn.hipwallpaper.com/i/82/99/EoKmFw.jpg",
  881. caption=caption,
  882. reply_markup=buttons
  883. )
  884. )
  885. return answers