|
|
@@ -25,10 +25,12 @@ import asyncio
|
|
|
import json
|
|
|
import os
|
|
|
import sys
|
|
|
+from html import escape
|
|
|
from re import sub as re_sub
|
|
|
from sys import version as pyver
|
|
|
from time import ctime, time
|
|
|
|
|
|
+from fuzzysearch import find_near_matches
|
|
|
from motor import version as mongover
|
|
|
from pykeyboard import InlineKeyboard
|
|
|
from pyrogram import __version__ as pyrover
|
|
|
@@ -51,28 +53,23 @@ from wbb.utils.http import get
|
|
|
from wbb.utils.pastebin import paste
|
|
|
|
|
|
keywords_list = [
|
|
|
- "alive",
|
|
|
+ "image",
|
|
|
+ "wall",
|
|
|
+ "tmdb",
|
|
|
+ "lyrics",
|
|
|
+ "exec",
|
|
|
+ "speedtest",
|
|
|
+ "search",
|
|
|
"ping",
|
|
|
"tr",
|
|
|
"ud",
|
|
|
- "google",
|
|
|
- "bitly",
|
|
|
- "wall",
|
|
|
"yt",
|
|
|
+ "info",
|
|
|
+ "google",
|
|
|
"torrent",
|
|
|
- "lyrics",
|
|
|
"wiki",
|
|
|
- "speedtest",
|
|
|
"music",
|
|
|
- "gh_repo",
|
|
|
- "gh_user",
|
|
|
- "search",
|
|
|
"ytmusic",
|
|
|
- "info",
|
|
|
- "chat_info",
|
|
|
- "tmdb",
|
|
|
- "pypi",
|
|
|
- "image",
|
|
|
]
|
|
|
|
|
|
|
|
|
@@ -271,35 +268,6 @@ async def wall_func(answers, text):
|
|
|
return answers
|
|
|
|
|
|
|
|
|
-# Used my api key here, don't fuck it
|
|
|
-async def shortify(url):
|
|
|
- if "." not in url:
|
|
|
- return
|
|
|
- header = {
|
|
|
- "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
|
|
|
- "Content-Type": "application/json",
|
|
|
- }
|
|
|
- payload = {"long_url": f"{url}"}
|
|
|
- payload = json.dumps(payload)
|
|
|
- async with aiohttpsession.post(
|
|
|
- "https://api-ssl.bitly.com/v4/shorten",
|
|
|
- headers=header,
|
|
|
- data=payload,
|
|
|
- ) as resp:
|
|
|
- data = await resp.json()
|
|
|
- msg = data["link"]
|
|
|
- a = []
|
|
|
- b = InlineQueryResultArticle(
|
|
|
- title="Link Shortened!",
|
|
|
- description=data["link"],
|
|
|
- input_message_content=InputTextMessageContent(
|
|
|
- msg, disable_web_page_preview=True
|
|
|
- ),
|
|
|
- )
|
|
|
- a.append(b)
|
|
|
- return a
|
|
|
-
|
|
|
-
|
|
|
async def torrent_func(answers, text):
|
|
|
results = await arq.torrent(text)
|
|
|
if not results.ok:
|
|
|
@@ -416,83 +384,6 @@ async def lyrics_func(answers, text):
|
|
|
return answers
|
|
|
|
|
|
|
|
|
-async def github_user_func(answers, text):
|
|
|
- URL = f"https://api.github.com/users/{text}"
|
|
|
- result = await get(URL)
|
|
|
- buttons = InlineKeyboard(row_width=1)
|
|
|
- buttons.add(
|
|
|
- InlineKeyboardButton(
|
|
|
- text="Open On Github", url=f"https://github.com/{text}"
|
|
|
- )
|
|
|
- )
|
|
|
- caption = f"""
|
|
|
-**Info Of {result['name']}**
|
|
|
-**Username:** `{text}`
|
|
|
-**Bio:** `{result['bio']}`
|
|
|
-**Profile Link:** [Here]({result['html_url']})
|
|
|
-**Company:** `{result['company']}`
|
|
|
-**Created On:** `{result['created_at']}`
|
|
|
-**Repositories:** `{result['public_repos']}`
|
|
|
-**Blog:** `{result['blog']}`
|
|
|
-**Location:** `{result['location']}`
|
|
|
-**Followers:** `{result['followers']}`
|
|
|
-**Following:** `{result['following']}`"""
|
|
|
- answers.append(
|
|
|
- InlineQueryResultPhoto(
|
|
|
- photo_url=result["avatar_url"],
|
|
|
- caption=caption,
|
|
|
- reply_markup=buttons,
|
|
|
- )
|
|
|
- )
|
|
|
- return answers
|
|
|
-
|
|
|
-
|
|
|
-async def github_repo_func(answers, text):
|
|
|
- text = text.replace("https://github.com/", "")
|
|
|
- text = text.replace("http://github.com/", "")
|
|
|
- if text[-1] == "/":
|
|
|
- text = text[0:-1]
|
|
|
- URL = f"https://api.github.com/repos/{text}"
|
|
|
- URL2 = f"https://api.github.com/repos/{text}/contributors"
|
|
|
- results = await asyncio.gather(get(URL), get(URL2))
|
|
|
- r = results[0]
|
|
|
- r1 = results[1]
|
|
|
- commits = 0
|
|
|
- for developer in r1:
|
|
|
- commits += developer["contributions"]
|
|
|
- buttons = InlineKeyboard(row_width=1)
|
|
|
- buttons.add(
|
|
|
- InlineKeyboardButton(
|
|
|
- "Open On Github", url=f"https://github.com/{text}"
|
|
|
- )
|
|
|
- )
|
|
|
- caption = f"""
|
|
|
-**Info Of {r['full_name']}**
|
|
|
-**Stars:** `{r['stargazers_count']}`
|
|
|
-**Watchers:** `{r['watchers_count']}`
|
|
|
-**Forks:** `{r['forks_count']}`
|
|
|
-**Commits:** `{commits}`
|
|
|
-**Is Fork:** `{r['fork']}`
|
|
|
-**Language:** `{r['language']}`
|
|
|
-**Contributors:** `{len(r1)}`
|
|
|
-**License:** `{r['license']['name'] if r['license'] else None}`
|
|
|
-**Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
|
|
|
-**Created On:** `{r['created_at']}`
|
|
|
-**Homepage:** {r['homepage']}
|
|
|
-**Description:** __{r['description']}__"""
|
|
|
- answers.append(
|
|
|
- InlineQueryResultArticle(
|
|
|
- title="Found Repo",
|
|
|
- description=text,
|
|
|
- reply_markup=buttons,
|
|
|
- input_message_content=InputTextMessageContent(
|
|
|
- caption, disable_web_page_preview=True
|
|
|
- ),
|
|
|
- )
|
|
|
- )
|
|
|
- return answers
|
|
|
-
|
|
|
-
|
|
|
async def tg_search_func(answers, text, user_id):
|
|
|
if user_id not in SUDOERS:
|
|
|
msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
|
|
|
@@ -781,35 +672,28 @@ async def yt_music_func(answers, url):
|
|
|
return answers
|
|
|
|
|
|
|
|
|
-async def user_info_inline_func(answers, user):
|
|
|
+async def info_inline_func(answers, peer):
|
|
|
+ not_found = InlineQueryResultArticle(
|
|
|
+ title="PEER NOT FOUND",
|
|
|
+ input_message_content=InputTextMessageContent(
|
|
|
+ "PEER NOT FOUND"
|
|
|
+ ),
|
|
|
+ )
|
|
|
try:
|
|
|
- caption, _ = await get_user_info(user)
|
|
|
+ user = await app.get_users(peer)
|
|
|
+ caption, _ = await get_user_info(user, True)
|
|
|
+ except IndexError:
|
|
|
+ try:
|
|
|
+ chat = await app.get_chat(peer)
|
|
|
+ caption, _ = await get_chat_info(chat, True)
|
|
|
+ except Exception:
|
|
|
+ return [not_found]
|
|
|
except Exception:
|
|
|
- answers.append(
|
|
|
- InlineQueryResultArticle(
|
|
|
- title="USER NOT FOUND",
|
|
|
- input_message_content=InputTextMessageContent(
|
|
|
- "USER NOT FOUND"
|
|
|
- ),
|
|
|
- )
|
|
|
- )
|
|
|
- return answers
|
|
|
- answers.append(
|
|
|
- InlineQueryResultArticle(
|
|
|
- title="Found User.",
|
|
|
- input_message_content=InputTextMessageContent(
|
|
|
- caption, disable_web_page_preview=True
|
|
|
- ),
|
|
|
- )
|
|
|
- )
|
|
|
- return answers
|
|
|
-
|
|
|
+ return [not_found]
|
|
|
|
|
|
-async def chat_info_inline_func(answers, chat):
|
|
|
- caption, photo_id = await get_chat_info(chat)
|
|
|
answers.append(
|
|
|
InlineQueryResultArticle(
|
|
|
- title="Found Chat.",
|
|
|
+ title="Found Peer.",
|
|
|
input_message_content=InputTextMessageContent(
|
|
|
caption, disable_web_page_preview=True
|
|
|
),
|
|
|
@@ -871,64 +755,6 @@ async def tmdb_func(answers, query):
|
|
|
return answers
|
|
|
|
|
|
|
|
|
-async def pypiSearchFunc(answers: list, query: str) -> list:
|
|
|
- result = await arq.pypi(query)
|
|
|
- if not result.ok:
|
|
|
- answers.append(
|
|
|
- InlineQueryResultArticle(
|
|
|
- title="No Such Package",
|
|
|
- description=result.result,
|
|
|
- input_message_content=InputTextMessageContent(
|
|
|
- result.result
|
|
|
- ),
|
|
|
- )
|
|
|
- )
|
|
|
- return answers
|
|
|
- result = result.result
|
|
|
- pURLS = [
|
|
|
- f"**{key}**: {value}"
|
|
|
- for key, value in result.projectURLS.items()
|
|
|
- ]
|
|
|
- pURLS = ("\n" + "\n".join(pURLS)) if pURLS else None
|
|
|
- caption = f"""
|
|
|
-**Name:** {result.name}
|
|
|
-**Version:** {result.version}
|
|
|
-**License:** {result.license}
|
|
|
-**Description:** {result.description}
|
|
|
-**Size:** {result.size}
|
|
|
-**Last Update:** {result.uploadTime}
|
|
|
-**Author:** {result.author}
|
|
|
-**Author's Email:** {result.authorEmail}
|
|
|
-**Requirements:** {(f'`{" | ".join(result.requirements)}`') if result.requirements else None}
|
|
|
-**Minimum Python Version:** {result.minPyVersion}
|
|
|
-**Homepage:** {result.homepage}
|
|
|
-**Bug Tracker:** {result.bugTrackURL}
|
|
|
-**Docs Url:** {result.docsURL}
|
|
|
-**Pypi Url:** {result.pypiURL}
|
|
|
-**Releases:** {result.releaseURL}
|
|
|
-**Project Urls:** ->{pURLS}
|
|
|
-"""
|
|
|
- button = InlineKeyboard(row_width=2)
|
|
|
- button.add(
|
|
|
- InlineKeyboardButton(text="Open Page", url=result.pypiURL),
|
|
|
- InlineKeyboardButton(
|
|
|
- text="Search Again",
|
|
|
- switch_inline_query_current_chat="pypi",
|
|
|
- ),
|
|
|
- )
|
|
|
- answers.append(
|
|
|
- InlineQueryResultArticle(
|
|
|
- title=f"{result.name} | {result.version}",
|
|
|
- description=result.description,
|
|
|
- input_message_content=InputTextMessageContent(
|
|
|
- caption, disable_web_page_preview=True
|
|
|
- ),
|
|
|
- reply_markup=button,
|
|
|
- )
|
|
|
- )
|
|
|
- return answers
|
|
|
-
|
|
|
-
|
|
|
async def image_func(answers, query):
|
|
|
results = await arq.image(query)
|
|
|
if not results.ok:
|
|
|
@@ -960,3 +786,82 @@ async def image_func(answers, query):
|
|
|
)
|
|
|
)
|
|
|
return answers
|
|
|
+
|
|
|
+
|
|
|
+async def execute_code(query):
|
|
|
+ text = query.query.strip()
|
|
|
+ offset = int((query.offset or 0))
|
|
|
+ answers = []
|
|
|
+ languages = (await arq.execute()).result
|
|
|
+ if len(text.split()) == 1:
|
|
|
+ answers = [
|
|
|
+ InlineQueryResultArticle(
|
|
|
+ title=lang,
|
|
|
+ input_message_content=InputTextMessageContent(lang),
|
|
|
+ )
|
|
|
+ for lang in languages
|
|
|
+ ][offset : offset + 25]
|
|
|
+ await query.answer(
|
|
|
+ next_offset=str(offset + 25),
|
|
|
+ results=answers,
|
|
|
+ cache_time=1,
|
|
|
+ )
|
|
|
+ elif len(text.split()) == 2:
|
|
|
+ text = text.split()[1].strip()
|
|
|
+ languages = list(
|
|
|
+ filter(
|
|
|
+ lambda x: find_near_matches(text, x, max_l_dist=1),
|
|
|
+ languages,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ answers.extend(
|
|
|
+ [
|
|
|
+ InlineQueryResultArticle(
|
|
|
+ title=lang,
|
|
|
+ input_message_content=InputTextMessageContent(
|
|
|
+ lang
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ for lang in languages
|
|
|
+ ][:49]
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ lang = text.split()[1]
|
|
|
+ code = text.split(None, 2)[2]
|
|
|
+ response = await arq.execute(lang, code)
|
|
|
+ if not response.ok:
|
|
|
+ answers.append(
|
|
|
+ InlineQueryResultArticle(
|
|
|
+ title="Error",
|
|
|
+ input_message_content=InputTextMessageContent(
|
|
|
+ response.result
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ res = response.result
|
|
|
+ stdout, stderr = escape(res.stdout), escape(res.stderr)
|
|
|
+ output = stdout or stderr
|
|
|
+ out = (
|
|
|
+ "STDOUT"
|
|
|
+ if stdout
|
|
|
+ else ("STDERR" if stderr else "No output")
|
|
|
+ )
|
|
|
+
|
|
|
+ msg = f"""
|
|
|
+**{lang.capitalize()}:**
|
|
|
+```{code}```
|
|
|
+
|
|
|
+**{out}:**
|
|
|
+```{output}```
|
|
|
+ """
|
|
|
+ answers.append(
|
|
|
+ InlineQueryResultArticle(
|
|
|
+ title="Executed",
|
|
|
+ description=output[:20],
|
|
|
+ input_message_content=InputTextMessageContent(
|
|
|
+ msg
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ )
|
|
|
+ await query.answer(results=answers, cache_time=1)
|