inlinefuncs.py 32 KB

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