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 random import randint
  25. from re import sub as re_sub
  26. from sys import version as pyver
  27. from time import ctime, time
  28. from motor import version as mongover
  29. from pykeyboard import InlineKeyboard
  30. from pyrogram import __version__ as pyrover
  31. from pyrogram import filters
  32. from pyrogram.raw.functions import Ping
  33. from pyrogram.types import (InlineKeyboardButton,
  34. InlineQueryResultArticle,
  35. InlineQueryResultPhoto,
  36. InputTextMessageContent)
  37. from search_engine_parser import GoogleSearch
  38. from wbb import (BOT_USERNAME, MESSAGE_DUMP_CHAT, SUDOERS, USERBOT_ID,
  39. USERBOT_NAME, USERBOT_USERNAME, aiohttpsession, app,
  40. app2, arq)
  41. from wbb.core.types import InlineQueryResultCachedDocument
  42. from wbb.modules.info import get_chat_info, get_user_info
  43. from wbb.modules.music import download_youtube_audio
  44. from wbb.utils.functions import test_speedtest
  45. from wbb.utils.http import get
  46. from wbb.utils.pastebin import paste
  47. keywords_list = [
  48. "alive",
  49. "ping",
  50. "tr",
  51. "ud",
  52. "google",
  53. "bitly",
  54. "wall",
  55. "yt",
  56. "torrent",
  57. "lyrics",
  58. "wiki",
  59. "speedtest",
  60. "music",
  61. "gh_repo",
  62. "gh_user",
  63. "search",
  64. "ytmusic",
  65. "info",
  66. "chat_info",
  67. "tmdb",
  68. "pypi",
  69. "image",
  70. ]
  71. async def inline_help_func(__HELP__):
  72. buttons = InlineKeyboard(row_width=4)
  73. buttons.add(
  74. *[
  75. (
  76. InlineKeyboardButton(
  77. text=i, switch_inline_query_current_chat=i
  78. )
  79. )
  80. for i in keywords_list
  81. ]
  82. )
  83. answerss = [
  84. InlineQueryResultArticle(
  85. title="Inline Commands",
  86. description="Help Related To Inline Usage.",
  87. input_message_content=InputTextMessageContent(
  88. "Click A Button To Get Started."
  89. ),
  90. thumb_url="https://hamker.me/cy00x5x.png",
  91. reply_markup=buttons,
  92. ),
  93. InlineQueryResultArticle(
  94. title="Github Repo",
  95. description="Get Github Respository Of Bot.",
  96. input_message_content=InputTextMessageContent(
  97. "https://github.com/thehamkercat/WilliamButcherBot"
  98. ),
  99. thumb_url="https://hamker.me/gjc9fo3.png",
  100. ),
  101. ]
  102. answerss = await alive_function(answerss)
  103. return answerss
  104. async def alive_function(answers):
  105. buttons = InlineKeyboard(row_width=2)
  106. bot_state = "Dead" if not await app.get_me() else "Alive"
  107. ubot_state = "Dead" if not await app2.get_me() else "Alive"
  108. buttons.add(
  109. InlineKeyboardButton("Stats", callback_data="stats_callback"),
  110. InlineKeyboardButton(
  111. "Go Inline!", switch_inline_query_current_chat=""
  112. ),
  113. )
  114. msg = f"""
  115. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  116. **MainBot:** `{bot_state}`
  117. **UserBot:** `{ubot_state}`
  118. **Python:** `{pyver.split()[0]}`
  119. **Pyrogram:** `{pyrover}`
  120. **MongoDB:** `{mongover}`
  121. **Platform:** `{sys.platform}`
  122. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  123. """
  124. answers.append(
  125. InlineQueryResultArticle(
  126. title="Alive",
  127. description="Check Bot's Stats",
  128. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  129. input_message_content=InputTextMessageContent(
  130. msg, disable_web_page_preview=True
  131. ),
  132. reply_markup=buttons,
  133. )
  134. )
  135. return answers
  136. async def translate_func(answers, lang, tex):
  137. result = await arq.translate(tex, lang)
  138. if not result.ok:
  139. answers.append(
  140. InlineQueryResultArticle(
  141. title="Error",
  142. description=result.result,
  143. input_message_content=InputTextMessageContent(
  144. result.result
  145. ),
  146. )
  147. )
  148. return answers
  149. result = result.result
  150. msg = f"""
  151. __**Translated from {result.src} to {result.dest}**__
  152. **INPUT:**
  153. {tex}
  154. **OUTPUT:**
  155. {result.translatedText}"""
  156. answers.extend(
  157. [
  158. InlineQueryResultArticle(
  159. title=f"Translated from {result.src} to {result.dest}.",
  160. description=result.translatedText,
  161. input_message_content=InputTextMessageContent(msg),
  162. ),
  163. InlineQueryResultArticle(
  164. title=result.translatedText,
  165. input_message_content=InputTextMessageContent(
  166. result.translatedText
  167. ),
  168. ),
  169. ]
  170. )
  171. return answers
  172. async def urban_func(answers, text):
  173. results = await arq.urbandict(text)
  174. if not results.ok:
  175. answers.append(
  176. InlineQueryResultArticle(
  177. title="Error",
  178. description=results.result,
  179. input_message_content=InputTextMessageContent(
  180. results.result
  181. ),
  182. )
  183. )
  184. return answers
  185. results = results.result[0:48]
  186. for i in results:
  187. clean = lambda x: re_sub(r"[\[\]]", "", x)
  188. msg = f"""
  189. **Query:** {text}
  190. **Definition:** __{clean(i.definition)}__
  191. **Example:** __{clean(i.example)}__"""
  192. answers.append(
  193. InlineQueryResultArticle(
  194. title=i.word,
  195. description=clean(i.definition),
  196. input_message_content=InputTextMessageContent(msg),
  197. )
  198. )
  199. return answers
  200. async def google_search_func(answers, text):
  201. gresults = await GoogleSearch().async_search(text)
  202. limit = 0
  203. for i in gresults:
  204. if limit > 48:
  205. break
  206. limit += 1
  207. try:
  208. msg = f"""
  209. [{i['titles']}]({i['links']})
  210. {i['descriptions']}"""
  211. answers.append(
  212. InlineQueryResultArticle(
  213. title=i["titles"],
  214. description=i["descriptions"],
  215. input_message_content=InputTextMessageContent(
  216. msg, disable_web_page_preview=True
  217. ),
  218. )
  219. )
  220. except KeyError:
  221. pass
  222. return answers
  223. async def wall_func(answers, text):
  224. results = await arq.wall(text)
  225. if not results.ok:
  226. answers.append(
  227. InlineQueryResultArticle(
  228. title="Error",
  229. description=results.result,
  230. input_message_content=InputTextMessageContent(
  231. results.result
  232. ),
  233. )
  234. )
  235. return answers
  236. results = results.result[0:48]
  237. for i in results:
  238. answers.append(
  239. InlineQueryResultPhoto(
  240. photo_url=i.url_image,
  241. thumb_url=i.url_thumb,
  242. caption=f"[Source]({i.url_image})",
  243. )
  244. )
  245. return answers
  246. # Used my api key here, don't fuck it
  247. async def shortify(url):
  248. if "." not in url:
  249. return
  250. header = {
  251. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  252. "Content-Type": "application/json",
  253. }
  254. payload = {"long_url": f"{url}"}
  255. payload = json.dumps(payload)
  256. async with aiohttpsession.post(
  257. "https://api-ssl.bitly.com/v4/shorten",
  258. headers=header,
  259. data=payload,
  260. ) as resp:
  261. data = await resp.json()
  262. msg = data["link"]
  263. a = []
  264. b = InlineQueryResultArticle(
  265. title="Link Shortened!",
  266. description=data["link"],
  267. input_message_content=InputTextMessageContent(
  268. msg, disable_web_page_preview=True
  269. ),
  270. )
  271. a.append(b)
  272. return a
  273. async def torrent_func(answers, text):
  274. results = await arq.torrent(text)
  275. if not results.ok:
  276. answers.append(
  277. InlineQueryResultArticle(
  278. title="Error",
  279. description=results.result,
  280. input_message_content=InputTextMessageContent(
  281. results.result
  282. ),
  283. )
  284. )
  285. return answers
  286. results = results.result[0:48]
  287. for i in results:
  288. title = i.name
  289. size = i.size
  290. seeds = i.seeds
  291. leechs = i.leechs
  292. upload_date = i.uploaded
  293. magnet = i.magnet
  294. caption = f"""
  295. **Title:** __{title}__
  296. **Size:** __{size}__
  297. **Seeds:** __{seeds}__
  298. **Leechs:** __{leechs}__
  299. **Uploaded:** __{upload_date}__
  300. **Magnet:** `{magnet}`"""
  301. description = f"{size} | {upload_date} | Seeds: {seeds}"
  302. answers.append(
  303. InlineQueryResultArticle(
  304. title=title,
  305. description=description,
  306. input_message_content=InputTextMessageContent(
  307. caption, disable_web_page_preview=True
  308. ),
  309. )
  310. )
  311. pass
  312. return answers
  313. async def youtube_func(answers, text):
  314. results = await arq.youtube(text)
  315. if not results.ok:
  316. answers.append(
  317. InlineQueryResultArticle(
  318. title="Error",
  319. description=results.result,
  320. input_message_content=InputTextMessageContent(
  321. results.result
  322. ),
  323. )
  324. )
  325. return answers
  326. results = results.result[0:48]
  327. for i in results:
  328. buttons = InlineKeyboard(row_width=1)
  329. video_url = f"https://youtube.com{i.url_suffix}"
  330. buttons.add(InlineKeyboardButton("Watch", url=video_url))
  331. caption = f"""
  332. **Title:** {i.title}
  333. **Views:** {i.views}
  334. **Channel:** {i.channel}
  335. **Duration:** {i.duration}
  336. **Uploaded:** {i.publish_time}
  337. **Description:** {i.long_desc}"""
  338. description = f"{i.views} | {i.channel} | {i.duration} | {i.publish_time}"
  339. answers.append(
  340. InlineQueryResultArticle(
  341. title=i.title,
  342. thumb_url=i.thumbnails[0],
  343. description=description,
  344. input_message_content=InputTextMessageContent(
  345. caption, disable_web_page_preview=True
  346. ),
  347. reply_markup=buttons,
  348. )
  349. )
  350. return answers
  351. async def lyrics_func(answers, text):
  352. song = await arq.lyrics(text)
  353. if not song.ok:
  354. answers.append(
  355. InlineQueryResultArticle(
  356. title="Error",
  357. description=song.result,
  358. input_message_content=InputTextMessageContent(
  359. song.result
  360. ),
  361. )
  362. )
  363. return answers
  364. lyrics = song.result
  365. song = lyrics.splitlines()
  366. song_name = song[0]
  367. artist = song[1]
  368. if len(lyrics) > 4095:
  369. lyrics = await paste(lyrics)
  370. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  371. msg = f"__{lyrics}__"
  372. answers.append(
  373. InlineQueryResultArticle(
  374. title=song_name,
  375. description=artist,
  376. input_message_content=InputTextMessageContent(msg),
  377. )
  378. )
  379. return answers
  380. async def github_user_func(answers, text):
  381. URL = f"https://api.github.com/users/{text}"
  382. result = await get(URL)
  383. buttons = InlineKeyboard(row_width=1)
  384. buttons.add(
  385. InlineKeyboardButton(
  386. text="Open On Github", url=f"https://github.com/{text}"
  387. )
  388. )
  389. caption = f"""
  390. **Info Of {result['name']}**
  391. **Username:** `{text}`
  392. **Bio:** `{result['bio']}`
  393. **Profile Link:** [Here]({result['html_url']})
  394. **Company:** `{result['company']}`
  395. **Created On:** `{result['created_at']}`
  396. **Repositories:** `{result['public_repos']}`
  397. **Blog:** `{result['blog']}`
  398. **Location:** `{result['location']}`
  399. **Followers:** `{result['followers']}`
  400. **Following:** `{result['following']}`"""
  401. answers.append(
  402. InlineQueryResultPhoto(
  403. photo_url=result["avatar_url"],
  404. caption=caption,
  405. reply_markup=buttons,
  406. )
  407. )
  408. return answers
  409. async def github_repo_func(answers, text):
  410. text = text.replace("https://github.com/", "")
  411. text = text.replace("http://github.com/", "")
  412. if text[-1] == "/":
  413. text = text[0:-1]
  414. URL = f"https://api.github.com/repos/{text}"
  415. URL2 = f"https://api.github.com/repos/{text}/contributors"
  416. results = await asyncio.gather(get(URL), get(URL2))
  417. r = results[0]
  418. r1 = results[1]
  419. commits = 0
  420. for developer in r1:
  421. commits += developer["contributions"]
  422. buttons = InlineKeyboard(row_width=1)
  423. buttons.add(
  424. InlineKeyboardButton(
  425. "Open On Github", url=f"https://github.com/{text}"
  426. )
  427. )
  428. caption = f"""
  429. **Info Of {r['full_name']}**
  430. **Stars:** `{r['stargazers_count']}`
  431. **Watchers:** `{r['watchers_count']}`
  432. **Forks:** `{r['forks_count']}`
  433. **Commits:** `{commits}`
  434. **Is Fork:** `{r['fork']}`
  435. **Language:** `{r['language']}`
  436. **Contributors:** `{len(r1)}`
  437. **License:** `{r['license']['name'] if r['license'] else None}`
  438. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  439. **Created On:** `{r['created_at']}`
  440. **Homepage:** {r['homepage']}
  441. **Description:** __{r['description']}__"""
  442. answers.append(
  443. InlineQueryResultArticle(
  444. title="Found Repo",
  445. description=text,
  446. reply_markup=buttons,
  447. input_message_content=InputTextMessageContent(
  448. caption, disable_web_page_preview=True
  449. ),
  450. )
  451. )
  452. return answers
  453. async def tg_search_func(answers, text, user_id):
  454. if user_id not in SUDOERS:
  455. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  456. answers.append(
  457. InlineQueryResultArticle(
  458. title="ERROR",
  459. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  460. input_message_content=InputTextMessageContent(msg),
  461. )
  462. )
  463. return answers
  464. if str(text)[-1] != ":":
  465. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  466. answers.append(
  467. InlineQueryResultArticle(
  468. title="ERROR",
  469. description="Put A ':' After The Text To Search",
  470. input_message_content=InputTextMessageContent(msg),
  471. )
  472. )
  473. return answers
  474. text = text[0:-1]
  475. async for message in app2.search_global(text, limit=49):
  476. buttons = InlineKeyboard(row_width=2)
  477. buttons.add(
  478. InlineKeyboardButton(
  479. text="Origin",
  480. url=message.link
  481. if message.link
  482. else "https://t.me/telegram",
  483. ),
  484. InlineKeyboardButton(
  485. text="Search again",
  486. switch_inline_query_current_chat="search",
  487. ),
  488. )
  489. name = (
  490. message.from_user.first_name
  491. if message.from_user.first_name
  492. else "NO NAME"
  493. )
  494. caption = f"""
  495. **Query:** {text}
  496. **Name:** {str(name)} [`{message.from_user.id}`]
  497. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  498. **Date:** {ctime(message.date)}
  499. **Text:** >>
  500. {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
  501. """
  502. result = InlineQueryResultArticle(
  503. title=name,
  504. description=message.text if message.text else "[NO_TEXT]",
  505. reply_markup=buttons,
  506. input_message_content=InputTextMessageContent(
  507. caption, disable_web_page_preview=True
  508. ),
  509. )
  510. answers.append(result)
  511. return answers
  512. async def music_inline_func(answers, query):
  513. chat_id = -1001445180719
  514. group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
  515. try:
  516. messages = [
  517. m
  518. async for m in app2.search_messages(
  519. chat_id, query, filter="audio", limit=100
  520. )
  521. ]
  522. except Exception as e:
  523. print(e)
  524. msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
  525. answers.append(
  526. InlineQueryResultArticle(
  527. title="ERROR",
  528. description="Click Here To Know More.",
  529. input_message_content=InputTextMessageContent(
  530. msg, disable_web_page_preview=True
  531. ),
  532. )
  533. )
  534. return answers
  535. messages_ids_and_duration = []
  536. for f_ in messages:
  537. messages_ids_and_duration.append(
  538. {
  539. "message_id": f_.message_id,
  540. "duration": f_.audio.duration
  541. if f_.audio.duration
  542. else 0,
  543. }
  544. )
  545. messages = list(
  546. {v["duration"]: v for v in messages_ids_and_duration}.values()
  547. )
  548. messages_ids = [ff_["message_id"] for ff_ in messages]
  549. messages = await app.get_messages(chat_id, messages_ids[0:48])
  550. return [
  551. InlineQueryResultCachedDocument(
  552. file_id=message_.audio.file_id,
  553. title=message_.audio.title,
  554. )
  555. for message_ in messages
  556. ]
  557. async def wiki_func(answers, text):
  558. data = await arq.wiki(text)
  559. if not data.ok:
  560. answers.append(
  561. InlineQueryResultArticle(
  562. title="Error",
  563. description=data.result,
  564. input_message_content=InputTextMessageContent(
  565. data.result
  566. ),
  567. )
  568. )
  569. return answers
  570. data = data.result
  571. msg = f"""
  572. **QUERY:**
  573. {data.title}
  574. **ANSWER:**
  575. __{data.answer}__"""
  576. answers.append(
  577. InlineQueryResultArticle(
  578. title=data.title,
  579. description=data.answer,
  580. input_message_content=InputTextMessageContent(msg),
  581. )
  582. )
  583. return answers
  584. async def speedtest_init(query):
  585. answers = []
  586. user_id = query.from_user.id
  587. if user_id not in SUDOERS:
  588. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  589. answers.append(
  590. InlineQueryResultArticle(
  591. title="ERROR",
  592. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  593. input_message_content=InputTextMessageContent(msg),
  594. )
  595. )
  596. return answers
  597. msg = "**Click The Button Below To Perform A Speedtest**"
  598. button = InlineKeyboard(row_width=1)
  599. button.add(
  600. InlineKeyboardButton(
  601. text="Test", callback_data="test_speedtest"
  602. )
  603. )
  604. answers.append(
  605. InlineQueryResultArticle(
  606. title="Click Here",
  607. input_message_content=InputTextMessageContent(msg),
  608. reply_markup=button,
  609. )
  610. )
  611. return answers
  612. """ callback query for the function above """
  613. @app.on_callback_query(filters.regex("test_speedtest"))
  614. async def test_speedtest_cq(_, cq):
  615. if cq.from_user.id not in SUDOERS:
  616. return await cq.answer("This Isn't For You!")
  617. inline_message_id = cq.inline_message_id
  618. await app.edit_inline_text(inline_message_id, "**Testing**")
  619. loop = asyncio.get_running_loop()
  620. download, upload, info = await loop.run_in_executor(
  621. None, test_speedtest
  622. )
  623. msg = f"""
  624. **Download:** `{download}`
  625. **Upload:** `{upload}`
  626. **Latency:** `{info['latency']} ms`
  627. **Country:** `{info['country']} [{info['cc']}]`
  628. **Latitude:** `{info['lat']}`
  629. **Longitude:** `{info['lon']}`
  630. """
  631. await app.edit_inline_text(inline_message_id, msg)
  632. async def pmpermit_func(answers, user_id, victim):
  633. if user_id != USERBOT_ID:
  634. return
  635. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  636. buttons = InlineKeyboard(row_width=2)
  637. buttons.add(
  638. InlineKeyboardButton(
  639. text="To Scam You", callback_data="pmpermit to_scam_you a"
  640. ),
  641. InlineKeyboardButton(
  642. text="For promotion",
  643. callback_data="pmpermit to_scam_you a",
  644. ),
  645. InlineKeyboardButton(
  646. text="Approve me", callback_data="pmpermit approve_me a"
  647. ),
  648. InlineKeyboardButton(
  649. text="Approve", callback_data=f"pmpermit approve {victim}"
  650. ),
  651. InlineKeyboardButton(
  652. text="Block", 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. t1 = time()
  665. ping = Ping(ping_id=randint(696969, 6969696))
  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