inlinefuncs.py 28 KB

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