Fix Fheta

pull/22/head
Who? 2024-11-23 20:44:23 +07:00 committed by GitHub
parent 7538f8ee7b
commit 29fb796218
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 163 additions and 193 deletions

View File

@ -1,6 +1,15 @@
__version__ = (3, 3, 5)
__version__ = (6, 6, 6)
# ███████╗██╗ ██╗███████╗████████╗█████╗
# ██╔════╝██║ ██║██╔════╝╚══██╔══╝██╔══██╗
# █████╗ ███████║█████╗ ██║ ███████║
# ██╔══╝ ██╔══██║██╔══╝ ██║ ██╔══██║
# ██║ ██║ ██║███████╗ ██║ ██║ ██║
# meta developer: @Foxy437
# change-log: 🎉🎉🎉🎉🎉🎉🎉🎉 ADDED INLINE!!! ADDED UKRAINIAN!!!
# change-log: ?????????
# meta banner: https://camo.githubusercontent.com/5091a8298e4c92787a9aabf61f5a5797ac01b9bc0fd08b44fc54b1f8dfd6cc60/68747470733a2f2f692e696d67686970706f2e636f6d2f66696c65732f5967473232303844674d2e6a7067
# meta pic: https://camo.githubusercontent.com/5091a8298e4c92787a9aabf61f5a5797ac01b9bc0fd08b44fc54b1f8dfd6cc60/68747470733a2f2f692e696d67686970706f2e636f6d2f66696c65732f5967473232303844674d2e6a7067
# ©️ Fixyres, 2024
# 🌐 https://github.com/Fixyres/FHeta
# Licensed under the Apache License, Version 2.0 (the "License");
@ -34,14 +43,8 @@ class FHeta(loader.Module):
"result": "<emoji document_id=5188311512791393083>🔎</emoji> <b>Result {index} by query:</b> <code>{query}</code>\n<code>{module_name}</code> by {author}\n<emoji document_id=4985961065012527769>🖥</emoji> <b>Repository:</b> {repo_url}\n<emoji document_id=5307585292926984338>💾</emoji> <b>Command for installation:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"fetch_failed": "<emoji document_id=5348277823133999513>❌</emoji> <b>Error.</b>",
"closest_match": "<emoji document_id=5188311512791393083>🔎</emoji> <b>Result by query:</b> <code>{query}</code>\n<code>{module_name}</code> by {author}\n<emoji document_id=4985961065012527769>🖥</emoji> <b>Repository:</b> {repo_url}\n<emoji document_id=5307585292926984338>💾</emoji> <b>Command for installation:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"inline_no_query": "Enter a query to search.",
"inline_no_modules_found": "No modules found.",
"inline_commands": "\n👨‍💻 <b>Commands:</b>\n{commands_list}",
"inline_description": "\n📁 <b>Description:</b> {description}",
"inline_result": "<code>{module_name}</code> by {author}\n<b>🖥️ Repository:</b> {repo_url}\n<b>💾 Command for installation:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"inline_descriptioon": "{description}",
"inline_no_modules_foound": "Try another request.",
"inline_noo_query": "Name, command, description, author."
"inline_commandss": "\n<emoji document_id=5372981976804366741>🤖</emoji> <b>Inline commands:</b>\n{inline_list}",
"language": "en_doc"
}
strings_ru = {
@ -54,14 +57,8 @@ class FHeta(loader.Module):
"result": "<emoji document_id=5188311512791393083>🔎</emoji> <b>Результат {index} по запросу:</b> <code>{query}</code>\n<code>{module_name}</code> от {author}\n<emoji document_id=4985961065012527769>🖥</emoji> <b>Репозиторий:</b> {repo_url}\n<emoji document_id=5307585292926984338>💾</emoji> <b>Команда для установки:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"fetch_failed": "<emoji document_id=5348277823133999513>❌</emoji> <b>Ошибка.</b>",
"closest_match": "<emoji document_id=5188311512791393083>🔎</emoji> <b>Результат по запросу:</b> <code>{query}</code>\n<code>{module_name}</code> от {author}\n<emoji document_id=4985961065012527769>🖥</emoji> <b>Репозиторий:</b> {repo_url}\n<emoji document_id=5307585292926984338>💾</emoji> <b>Команда для установки:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"inline_no_query": "Введите запрос для поиска.",
"inline_no_modules_found": "Модули не найдены.",
"inline_commands": "\n👨‍💻 <b>Команды:</b>\n{commands_list}",
"inline_description": "\n📁 <b>Описание:</b> {description}",
"inline_result": "<code>{module_name}</code> от {author}\n<b>🖥️ Репозиторий:</b> {repo_url}\n<b>💾 Команда для установки:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"inline_descriptioon": "{description}",
"inline_no_modules_foound": "Попробуйте другой запрос.",
"inline_noo_query": "Название, команда, описание, автор."
"inline_commandss": "\n<emoji document_id=5372981976804366741>🤖</emoji> <b>Инлайн команды:</b>\n{inline_list}",
"language": "ru_doc"
}
strings_ua = {
@ -74,14 +71,8 @@ class FHeta(loader.Module):
"result": "<emoji document_id=5188311512791393083>🔎</emoji> <b>Результат {index} за запитом:</b> <code>{query}</code>\n<code>{module_name}</code> від {author}\n<emoji document_id=4985961065012527769>🖥</emoji> <b>Репозиторій:</b> {repo_url}\n<emoji document_id=5307585292926984338>💾</emoji> <b>Команда для встановлення:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"fetch_failed": "<emoji document_id=5348277823133999513>❌</emoji> <b>Помилка.</b>",
"closest_match": "<emoji document_id=5188311512791393083>🔎</emoji> <b>Результат за запитом:</b> <code>{query}</code>\n<code>{module_name}</code> від {author}\n<emoji document_id=4985961065012527769>🖥</emoji> <b>Репозиторій:</b> {repo_url}\n<emoji document_id=5307585292926984338>💾</emoji> <b>Команда для встановлення:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"inline_no_query": "Введіть запит для пошуку.",
"inline_no_modules_found": "Модулі не знайдені.",
"inline_commands": "\n👨‍💻 <b>Команди:</b>\n{commands_list}",
"inline_description": "\n📁 <b>Опис:</b> {description}",
"inline_result": "<code>{module_name}</code> від {author}\n<b>🖥️ Репозиторій:</b> {repo_url}\n<b>💾 Команда для встановлення:</b> <code>{install_command}</code>{description}{commands}\n\n\n",
"inline_descriptioon": "{description}",
"inline_no_modules_foound": "Спробуйте інший запит.",
"inline_noo_query": "Назва, команда, опис, автор."
"inline_commandss": "\n<emoji document_id=5372981976804366741>🤖</emoji> <b>Інлайн команди:</b>\n{inline_list}",
"language": "ua_doc"
}
@loader.command(ru_doc="(запрос) - искать модули.", ua_doc="(запит) - шукати модулі.")
@ -92,7 +83,7 @@ class FHeta(loader.Module):
await utils.answer(message, self.strings["no_query"])
return
await utils.answer(message, self.strings["search"])
search_message = await utils.answer(message, self.strings["search"])
modules = await self.search_modules(args)
if not modules:
@ -106,160 +97,84 @@ class FHeta(loader.Module):
data = await response.text()
all_modules = json.loads(data)
module_names = [module['name'] for module in all_modules]
module_names = [module['name'] for module in all_modules if 'name' in module]
closest_matches = difflib.get_close_matches(args, module_names, n=1, cutoff=0.5)
if closest_matches:
closest_module = next((m for m in all_modules if m['name'] == closest_matches[0]), None)
if closest_module:
formatted_module = await self.format_module(closest_module, args)
await utils.answer(message, formatted_module)
return
banner_url = closest_module.get("banner", None)
await utils.answer(message, self.strings["no_modules_found"])
else:
seen_modules = set()
formatted_modules = []
result_index = 1
if banner_url:
async with aiohttp.ClientSession() as session:
async with session.get(banner_url) as response:
if response.status == 200:
banner_data = await response.read()
file = io.BytesIO(banner_data)
file.name = "banner.jpg"
await message.client.send_file(
message.peer_id,
file,
caption=formatted_module,
reply_to=message.id
)
await search_message.delete()
return
for module in modules:
try:
repo_url = f"https://github.com/{module['repo']}"
install = module['install']
await utils.answer(search_message, formatted_module)
return
commands_section = ""
if "commands" in module and module['commands']:
commands_section = self.strings["commands"].format(commands_list="\n".join(
[f"<code>{self.get_prefix()}{cmd['name']}</code> {utils.escape_html(cmd['description'])}" for cmd in module['commands']]
))
elif "commands" not in module or not module['commands']:
commands_section = ""
description_section = ""
if "description" in module and module["description"]:
description_section = self.strings["description"].format(description=utils.escape_html(module["description"]))
elif "description" not in module or not module["description"]:
description_section = ""
author_info = utils.escape_html(module.get("author", "???"))
module_name = utils.escape_html(module['name'].replace('.py', ''))
module_namee = utils.escape_html(module['name'].replace('.py', '').lower())
module_key = f"{module_namee}_{author_info}"
if module_key in seen_modules:
continue
seen_modules.add(module_key)
result = self.strings["result"].format(
index=result_index,
query=args,
module_name=module_name,
author=author_info,
repo_url=repo_url,
install_command=f"{self.get_prefix()}{install}",
description=description_section,
commands=commands_section
)
formatted_modules.append(result)
result_index += 1
except Exception:
continue
if len(formatted_modules) == 1:
closest_match_result = self.strings["closest_match"].format(
query=args,
module_name=module_name,
author=author_info,
repo_url=repo_url,
install_command=f"{self.get_prefix()}{install}",
description=description_section,
commands=commands_section
)
await utils.answer(message, closest_match_result)
else:
results = "".join(formatted_modules)
await utils.answer(message, results)
@loader.inline_handler(ru_doc="(запрос) - искать модули.", ua_doc="(запит) - шукати модулі.")
async def fheta(self, query: InlineQuery):
'''(query) - search modules.'''
args = query.args
if not args:
await query.answer(
[
{
"type": "article",
"id": "no_query",
"title": self.strings["inline_no_query"],
"description": self.strings["inline_noo_query"],
"input_message_content": {
"message_text": self.strings["inline_no_query"],
"parse_mode": "HTML",
},
"thumb_url": "https://raw.githubusercontent.com/Fixyres/FHeta/refs/heads/main/imgonline-com-ua-Resize-4EUHOHiKpwRTb4s.png",
}
]
)
return
modules = await self.search_modules(args)
if not modules:
modules = await self.search_modules(args.replace(" ", ""))
if not modules:
url = "https://raw.githubusercontent.com/Fixyres/FHeta/refs/heads/main/modules.json"
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
if response.status == 200:
data = await response.text()
all_modules = json.loads(data)
module_names = [module['name'] for module in all_modules]
closest_matches = difflib.get_close_matches(args, module_names, n=3, cutoff=0.4)
if closest_matches:
modules = [m for m in all_modules if m['name'] in closest_matches]
if not modules:
await query.answer(
[
{
"type": "article",
"id": "no_modules_found",
"title": self.strings["inline_no_modules_found"],
"description": self.strings["inline_no_modules_foound"],
"input_message_content": {
"message_text": self.strings["inline_no_modules_found"],
"parse_mode": "HTML",
},
"thumb_url": "https://raw.githubusercontent.com/Fixyres/FHeta/refs/heads/main/imgonline-com-ua-Resize-KbaztxA3oS67p3m8.png",
}
]
)
await utils.answer(search_message, self.strings["no_modules_found"])
return
seen_modules = set()
results = []
formatted_modules = []
result_index = 1
for module in modules:
current_language = self.strings.get("language", "doc")
for module in modules[:50]:
try:
repo_url = f"https://github.com/{module['repo']}"
install = module['install']
commands_section = ""
if "commands" in module and module['commands']:
commands_list = "\n".join(
[f"<code>{self.get_prefix()}{cmd['name']}</code> {utils.escape_html(cmd['description'])}" for cmd in module['commands']]
)
commands_section = self.strings["inline_commands"].format(commands_list=commands_list)
inline_commands_section = ""
if "commands" in module and module['commands']:
normal_commands = []
inline_commands = []
for cmd in module['commands']:
description = cmd.get('description', {}).get(current_language, cmd.get('description', {}).get("doc"))
if isinstance(description, dict):
description = description.get('doc', '')
if cmd.get("inline", False):
if description:
cmd_entry = f"<code>@{self.inline.bot_username} {cmd['name']}</code> {utils.escape_html(description)}"
else:
cmd_entry = f"<code>@{self.inline.bot_username} {cmd['name']}</code>"
inline_commands.append(cmd_entry)
else:
if description:
cmd_entry = f"<code>{self.get_prefix()}{cmd['name']}</code> {utils.escape_html(description)}"
else:
cmd_entry = f"<code>{self.get_prefix()}{cmd['name']}</code>"
normal_commands.append(cmd_entry)
if normal_commands:
commands_section = self.strings["commands"].format(commands_list="\n".join(normal_commands))
if inline_commands:
inline_commands_section = self.strings["inline_commandss"].format(
inline_list="\n".join(inline_commands))
description_section = ""
if "description" in module:
description_section = self.strings["inline_description"].format(description=utils.escape_html(module['description']))
else:
description_section = ""
if "description" in module and module["description"]:
description_section = self.strings["description"].format(description=utils.escape_html(module["description"]))
author_info = utils.escape_html(module.get("author", "???"))
module_name = utils.escape_html(module['name'].replace('.py', ''))
@ -270,37 +185,64 @@ class FHeta(loader.Module):
continue
seen_modules.add(module_key)
results.append(
{
"type": "article",
"id": f"module_{result_index}",
"title": module_name,
"description": self.strings["inline_descriptioon"].format(description=module.get('description', utils.escape_html(module.get('author', '???')))),
"input_message_content": {
"message_text": self.strings["inline_result"].format(
thumb_url = module.get("banner", None)
result = self.strings["result"].format(
index=result_index,
query=args,
module_name=module_name,
author=author_info,
repo_url=repo_url,
install_command=f"{self.get_prefix()}{install}",
description=description_section,
commands=commands_section + inline_commands_section
)
formatted_modules.append((result, thumb_url))
result_index += 1
except Exception:
continue
if len(formatted_modules) == 1:
result_text, thumb_url = formatted_modules[0]
if thumb_url:
async with aiohttp.ClientSession() as session:
async with session.get(thumb_url) as response:
if response.status == 200:
banner_data = await response.read()
file = io.BytesIO(banner_data)
file.name = "banner.jpg"
closest_match_result = self.strings["closest_match"].format(
query=args,
module_name=module_name,
author=author_info,
repo_url=repo_url,
install_command=f"{self.get_prefix()}{install}",
description=description_section,
commands=commands_section,
),
"parse_mode": "HTML",
"disable_web_page_preview": True,
},
"thumb_url": "https://raw.githubusercontent.com/Fixyres/FHeta/refs/heads/main/imgonline-com-ua-Resize-SOMllzo0cPFUCor.png",
}
)
result_index += 1
commands=commands_section + inline_commands_section
)
await message.client.send_file(
message.peer_id,
file,
caption=closest_match_result,
reply_to=message.id
)
await search_message.delete()
return
if result_index > 50:
break
except Exception:
continue
await query.answer(results)
closest_match_result = self.strings["closest_match"].format(
query=args,
module_name=module_name,
author=author_info,
repo_url=repo_url,
install_command=f"{self.get_prefix()}{install}",
description=description_section,
commands=commands_section + inline_commands_section
)
await utils.answer(search_message, closest_match_result)
else:
results = "".join([item[0] for item in formatted_modules])
await utils.answer(search_message, results)
async def search_modules(self, query: str):
url = "https://raw.githubusercontent.com/Fixyres/FHeta/refs/heads/main/modules.json"
async with aiohttp.ClientSession() as session:
@ -337,18 +279,46 @@ class FHeta(loader.Module):
async def format_module(self, module, query):
repo_url = f"https://github.com/{module['repo']}"
install = module['install']
current_language = self.strings.get("language", "doc")
commands_section = ""
if "commands" in module:
commands_list = "\n".join([f"<code>{self.get_prefix()}{cmd['name']}</code> {cmd['description']}" for cmd in module['commands']])
commands_section = self.strings["commands"].format(commands_list=commands_list)
inline_commands_section = ""
if "commands" in module and module['commands']:
normal_commands = []
inline_commands = []
for cmd in module['commands']:
description = cmd.get('description', {}).get(current_language, cmd.get('description', {}).get("doc"))
if isinstance(description, dict):
description = description.get('doc', '')
if cmd.get("inline", False):
if description:
cmd_entry = f"<code>@{self.inline.bot_username} {cmd['name']}</code> {utils.escape_html(description)}"
else:
cmd_entry = f"<code>@{self.inline.bot_username} {cmd['name']}</code>"
inline_commands.append(cmd_entry)
else:
if description:
cmd_entry = f"<code>{self.get_prefix()}{cmd['name']}</code> {utils.escape_html(description)}"
else:
cmd_entry = f"<code>{self.get_prefix()}{cmd['name']}</code>"
normal_commands.append(cmd_entry)
if normal_commands:
commands_section = self.strings["commands"].format(commands_list="\n".join(normal_commands))
if inline_commands:
inline_commands_section = self.strings["inline_commandss"].format(
inline_list="\n".join(inline_commands))
description_section = ""
if "description" in module:
description_section = self.strings["description"].format(description=module["description"])
if "description" in module and module["description"]:
description_section = self.strings["description"].format(description=utils.escape_html(module["description"]))
author_info = module.get("author", "???")
module_name = module['name'].replace('.py', '')
author_info = utils.escape_html(module.get("author", "???"))
module_name = utils.escape_html(module['name'].replace('.py', ''))
return self.strings["closest_match"].format(
query=query,
@ -357,5 +327,5 @@ class FHeta(loader.Module):
repo_url=repo_url,
install_command=f"{self.get_prefix()}{install}",
description=description_section,
commands=commands_section
)
commands=commands_section + inline_commands_section
)