inlinefuncs.py 28 KB

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