mirror of
https://github.com/TeamPGM/PagerMaid-Pyro.git
synced 2024-12-01 02:37:51 +00:00
164 lines
7.1 KiB
Python
164 lines
7.1 KiB
Python
""" The help module. """
|
||
|
||
from json import dump as json_dump
|
||
from os import listdir, sep
|
||
|
||
from pyrogram.enums import ParseMode
|
||
|
||
from pagermaid import help_messages, Config
|
||
from pagermaid.group_manager import enforce_permission
|
||
from pagermaid.modules.reload import reload_all
|
||
from pagermaid.utils import lang, Message, from_self, from_msg_get_sudo_uid
|
||
from pagermaid.listener import listener
|
||
|
||
import pathlib
|
||
|
||
|
||
@listener(is_plugin=False, command="help",
|
||
description=lang('help_des'),
|
||
parameters=f"<{lang('command')}>")
|
||
async def help_command(message: Message):
|
||
""" The help new command,"""
|
||
if message.arguments:
|
||
if message.arguments in help_messages:
|
||
if from_self(message) or \
|
||
enforce_permission(from_msg_get_sudo_uid(message), help_messages[message.arguments]["permission"]):
|
||
await message.edit(f"{help_messages[message.arguments]['use']}")
|
||
else:
|
||
await message.edit(lang('help_no_permission'))
|
||
else:
|
||
await message.edit(lang('arg_error'))
|
||
else:
|
||
result = f"**{lang('help_list')}: \n**"
|
||
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']
|
||
for command in sorted(help_messages, reverse=False):
|
||
if str(command) in support_commands:
|
||
continue
|
||
if from_self(message) or \
|
||
enforce_permission(from_msg_get_sudo_uid(message), help_messages[command]["permission"]):
|
||
result += f"`{command}`, "
|
||
if result == f"**{lang('help_list')}: \n**":
|
||
""" The help raw command,"""
|
||
for command in sorted(help_messages, reverse=False):
|
||
if from_self(message) or \
|
||
enforce_permission(from_msg_get_sudo_uid(message), help_messages[command]["permission"]):
|
||
result += f"`{command}`, "
|
||
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)
|
||
|
||
|
||
@listener(is_plugin=False, command="help_raw",
|
||
description=lang('help_des'),
|
||
parameters=f"<{lang('command')}>")
|
||
async def help_raw_command(message: Message):
|
||
""" The help raw command,"""
|
||
if message.arguments:
|
||
if message.arguments in help_messages:
|
||
if from_self(message) or \
|
||
enforce_permission(from_msg_get_sudo_uid(message), help_messages[message.arguments]["permission"]):
|
||
await message.edit(f"{help_messages[message.arguments]['use']}")
|
||
else:
|
||
await message.edit(lang('help_no_permission'))
|
||
else:
|
||
await message.edit(lang('arg_error'))
|
||
else:
|
||
result = f"**{lang('help_list')}: \n**"
|
||
for command in sorted(help_messages, reverse=False):
|
||
if from_self(message) or \
|
||
enforce_permission(from_msg_get_sudo_uid(message), help_messages[command]["permission"]):
|
||
result += f"`{command}`, "
|
||
await message.edit(
|
||
f"""{result[:-2]}\n**{lang('help_send')} ",help <{lang('command')}>" {lang('help_see')}** [{lang('help_source')}](https://t.me/PagerMaid_Modify)""",
|
||
parse_mode=ParseMode.MARKDOWN,
|
||
disable_web_page_preview=True,
|
||
)
|
||
|
||
|
||
@listener(is_plugin=False, command="lang",
|
||
need_admin=True,
|
||
description=lang('lang_des'))
|
||
async def lang_change(message: Message):
|
||
to_lang = message.arguments
|
||
from_lang = Config.LANGUAGE
|
||
dir_, dir__ = listdir('languages/built-in'), []
|
||
for i in dir_:
|
||
if i.find('yml') != -1:
|
||
dir__.append(i[:-4])
|
||
file = pathlib.Path('config.yml').read_text()
|
||
if to_lang in dir__:
|
||
file = file.replace(f'application_language: "{from_lang}"', f'application_language: "{to_lang}"')
|
||
with open('config.yml', 'w', encoding="utf-8") as f:
|
||
f.write(file)
|
||
await message.edit(f"{lang('lang_change_to')} {to_lang}, {lang('lang_reboot')}")
|
||
reload_all()
|
||
else:
|
||
await message.edit(f'{lang("lang_current_lang")} {Config.LANGUAGE}\n\n'
|
||
f'{lang("lang_all_lang")}{",".join(dir__)}')
|
||
|
||
|
||
@listener(is_plugin=False, outgoing=True, command="alias",
|
||
disallow_alias=True,
|
||
need_admin=True,
|
||
description=lang('alias_des'),
|
||
parameters='{list|del|set} <source> <to>')
|
||
async def alias_commands(message: Message):
|
||
source_commands = []
|
||
to_commands = []
|
||
texts = []
|
||
for key, value in Config.alias_dict.items():
|
||
source_commands.append(key)
|
||
to_commands.append(value)
|
||
if len(message.parameter) == 0:
|
||
await message.edit(lang('arg_error'))
|
||
return
|
||
elif len(message.parameter) == 1:
|
||
if source_commands:
|
||
texts.extend(
|
||
f'`{source_commands[i]}` > `{to_commands[i]}`'
|
||
for i in range(len(source_commands))
|
||
)
|
||
|
||
await message.edit(lang('alias_list') + '\n\n' + '\n'.join(texts))
|
||
else:
|
||
await message.edit(lang('alias_no'))
|
||
elif len(message.parameter) == 2:
|
||
source_command = message.parameter[1]
|
||
try:
|
||
del Config.alias_dict[source_command]
|
||
with open(f"data{sep}alias.json", 'w', encoding="utf-8") as f:
|
||
json_dump(Config.alias_dict, f)
|
||
await message.edit(lang('alias_success'))
|
||
reload_all()
|
||
except KeyError:
|
||
await message.edit(lang('alias_no_exist'))
|
||
return
|
||
elif len(message.parameter) == 3:
|
||
source_command = message.parameter[1]
|
||
to_command = message.parameter[2]
|
||
if to_command in help_messages:
|
||
await message.edit(lang('alias_exist'))
|
||
return
|
||
Config.alias_dict[source_command] = to_command
|
||
with open(f"data{sep}alias.json", 'w', encoding="utf-8") as f:
|
||
json_dump(Config.alias_dict, f)
|
||
await message.edit(lang('alias_success'))
|
||
reload_all()
|