inlinefuncs.py 32 KB

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