PagerMaid-Pyro/pagermaid/modules/help.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

222 lines
7.1 KiB
Python
Raw Normal View History

2022-05-23 12:40:30 +00:00
""" The help module. """
2024-08-13 10:38:13 +00:00
from os import listdir
2022-07-03 10:07:55 +00:00
from pyrogram.enums import ParseMode
2023-01-31 16:24:56 +00:00
from pagermaid.common.alias import AliasManager
from pagermaid.common.reload import reload_all
from pagermaid.config import CONFIG_PATH, Config
from pagermaid.enums import Message
from pagermaid.group_manager import enforce_permission
2022-05-23 12:40:30 +00:00
from pagermaid.listener import listener
from pagermaid.static import help_messages
from pagermaid.utils import lang
from pagermaid.utils.listener import from_self, from_msg_get_sudo_uid
2022-05-23 12:40:30 +00:00
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False,
command="help",
description=lang("help_des"),
parameters=f"<{lang('command')}>",
)
2022-06-20 13:55:14 +00:00
async def help_command(message: Message):
2023-03-12 03:56:01 +00:00
"""The help new command,"""
2022-05-23 12:40:30 +00:00
if message.arguments:
if message.arguments in help_messages:
2023-03-12 03:56:01 +00:00
if from_self(message) or enforce_permission(
from_msg_get_sudo_uid(message),
help_messages[message.arguments]["permission"],
):
2022-05-23 12:40:30 +00:00
await message.edit(f"{help_messages[message.arguments]['use']}")
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("help_no_permission"))
2022-05-23 12:40:30 +00:00
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("arg_error"))
2022-05-23 12:40:30 +00:00
else:
result = f"**{lang('help_list')}: \n**"
2023-03-12 03:56:01 +00:00
support_commands = [
"username",
"name",
"pfp",
"bio",
"rmpfp",
"profile",
"block",
"unblock",
"ghost",
"deny",
"convert",
"caption",
"ocr",
"highlight",
"time",
"translate",
"tts",
"google",
"animate",
"teletype",
"widen",
"owo",
"flip",
"rng",
"aaa",
"tuxsay",
"coin",
"help",
"lang",
"alias",
"id",
"uslog",
"log",
"re",
"leave",
"hitokoto",
"apt",
"prune",
"selfprune",
"yourprune",
"del",
"genqr",
"parseqr",
"sb",
"sysinfo",
"status",
"stats",
"speedtest",
"connection",
"pingdc",
"ping",
"topcloud",
"s",
"sticker",
"sh",
"restart",
"trace",
"chat",
"update",
]
2022-05-23 12:40:30 +00:00
for command in sorted(help_messages, reverse=False):
if str(command) in support_commands:
continue
2023-03-12 03:56:01 +00:00
if from_self(message) or enforce_permission(
from_msg_get_sudo_uid(message), help_messages[command]["permission"]
):
2022-05-23 12:40:30 +00:00
result += f"`{command}`, "
if result == f"**{lang('help_list')}: \n**":
2023-03-12 03:56:01 +00:00
"""The help raw command,"""
2022-05-23 12:40:30 +00:00
for command in sorted(help_messages, reverse=False):
2023-03-12 03:56:01 +00:00
if from_self(message) or enforce_permission(
from_msg_get_sudo_uid(message), help_messages[command]["permission"]
):
2022-05-23 12:40:30 +00:00
result += f"`{command}`, "
2023-03-12 03:56:01 +00:00
await message.edit(
result[:-2]
+ f"\n**{lang('help_send')} \",help <{lang('command')}>\" {lang('help_see')}**\n"
f"[{lang('help_source')}](https://t.me/PagerMaid_Modify) "
f"[{lang('help_plugin')}](https://index.xtaolabs.com/) "
f"[{lang('help_module')}](https://wiki.xtaolabs.com/)",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True,
)
2022-05-23 12:40:30 +00:00
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False,
command="help_raw",
description=lang("help_des"),
parameters=f"<{lang('command')}>",
)
2022-06-20 13:55:14 +00:00
async def help_raw_command(message: Message):
2023-03-12 03:56:01 +00:00
"""The help raw command,"""
2022-05-23 12:40:30 +00:00
if message.arguments:
if message.arguments in help_messages:
2023-03-12 03:56:01 +00:00
if from_self(message) or enforce_permission(
from_msg_get_sudo_uid(message),
help_messages[message.arguments]["permission"],
):
2022-05-23 12:40:30 +00:00
await message.edit(f"{help_messages[message.arguments]['use']}")
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("help_no_permission"))
2022-05-23 12:40:30 +00:00
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("arg_error"))
2022-05-23 12:40:30 +00:00
else:
result = f"**{lang('help_list')}: \n**"
for command in sorted(help_messages, reverse=False):
2023-03-12 03:56:01 +00:00
if from_self(message) or enforce_permission(
from_msg_get_sudo_uid(message), help_messages[command]["permission"]
):
2022-05-23 12:40:30 +00:00
result += f"`{command}`, "
2022-06-20 13:55:14 +00:00
await message.edit(
f"""{result[:-2]}\n**{lang('help_send')} ",help <{lang('command')}>" {lang('help_see')}** [{lang('help_source')}](https://t.me/PagerMaid_Modify)""",
2022-07-03 10:07:55 +00:00
parse_mode=ParseMode.MARKDOWN,
2022-06-20 13:55:14 +00:00
disable_web_page_preview=True,
)
2022-05-23 12:40:30 +00:00
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False, command="lang", need_admin=True, description=lang("lang_des")
)
2022-06-20 13:55:14 +00:00
async def lang_change(message: Message):
2022-05-23 12:40:30 +00:00
to_lang = message.arguments
from_lang = Config.LANGUAGE
2023-03-12 03:56:01 +00:00
dir_, dir__ = listdir("languages/built-in"), []
2022-05-23 12:40:30 +00:00
for i in dir_:
2023-03-12 03:56:01 +00:00
if i.find("yml") != -1:
2022-05-23 12:40:30 +00:00
dir__.append(i[:-4])
file = CONFIG_PATH.read_text()
2022-05-23 12:40:30 +00:00
if to_lang in dir__:
2023-03-12 03:56:01 +00:00
file = file.replace(
f'application_language: "{from_lang}"', f'application_language: "{to_lang}"'
)
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
2022-05-23 12:40:30 +00:00
f.write(file)
await message.edit(f"{lang('lang_change_to')} {to_lang}, {lang('lang_reboot')}")
2022-11-14 14:11:27 +00:00
await reload_all()
2022-05-23 12:40:30 +00:00
else:
2023-03-12 03:56:01 +00:00
await message.edit(
f'{lang("lang_current_lang")} {Config.LANGUAGE}\n\n'
f'{lang("lang_all_lang")}{"".join(dir__)}'
)
2022-05-23 12:40:30 +00:00
2023-03-12 03:56:01 +00:00
@listener(
is_plugin=False,
outgoing=True,
command="alias",
disallow_alias=True,
need_admin=True,
description=lang("alias_des"),
parameters="{list|del|set} <source> <to>",
)
2022-06-20 13:55:14 +00:00
async def alias_commands(message: Message):
2023-01-31 16:24:56 +00:00
alias_manager = AliasManager()
2022-05-23 12:40:30 +00:00
if len(message.parameter) == 0:
2023-03-12 03:56:01 +00:00
await message.edit(lang("arg_error"))
2022-05-23 12:40:30 +00:00
elif len(message.parameter) == 1:
2023-01-31 16:24:56 +00:00
if alias_manager.alias_list:
2023-03-12 03:56:01 +00:00
await message.edit(
lang("alias_list") + "\n\n" + alias_manager.get_all_alias_text()
)
2022-05-23 12:40:30 +00:00
else:
2023-03-12 03:56:01 +00:00
await message.edit(lang("alias_no"))
2022-05-23 12:40:30 +00:00
elif len(message.parameter) == 2:
source_command = message.parameter[1]
try:
2023-01-31 16:24:56 +00:00
alias_manager.delete_alias(source_command)
2023-03-12 03:56:01 +00:00
await message.edit(lang("alias_success"))
2022-11-14 14:11:27 +00:00
await reload_all()
2022-05-23 12:40:30 +00:00
except KeyError:
2023-03-12 03:56:01 +00:00
await message.edit(lang("alias_no_exist"))
2022-05-23 12:40:30 +00:00
return
elif len(message.parameter) == 3:
source_command = message.parameter[1]
to_command = message.parameter[2]
if to_command in help_messages:
2023-03-12 03:56:01 +00:00
await message.edit(lang("alias_exist"))
2022-05-23 12:40:30 +00:00
return
2023-01-31 16:24:56 +00:00
alias_manager.add_alias(source_command, to_command)
2023-03-12 03:56:01 +00:00
await message.edit(lang("alias_success"))
2022-11-14 14:11:27 +00:00
await reload_all()