inlinefuncs.py 27 KB

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