inlinefuncs.py 27 KB

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