2020-02-19 15:31:39 +00:00
|
|
|
""" The help module. """
|
|
|
|
|
2021-04-12 16:25:32 +00:00
|
|
|
from os import listdir
|
2021-06-15 04:31:05 +00:00
|
|
|
from json import dump as json_dump
|
2022-02-16 15:13:41 +00:00
|
|
|
from pagermaid import help_messages, alias_dict, redis_status, redis, language
|
2021-06-15 04:31:05 +00:00
|
|
|
from pagermaid.utils import lang, alias_command
|
2021-04-12 16:25:32 +00:00
|
|
|
from pagermaid.listener import listener, config
|
2020-02-19 15:31:39 +00:00
|
|
|
|
|
|
|
|
2021-06-15 04:31:05 +00:00
|
|
|
@listener(is_plugin=False, outgoing=True, command=alias_command("help"),
|
2021-04-12 16:25:32 +00:00
|
|
|
description=lang('help_des'),
|
|
|
|
parameters=f"<{lang('command')}>")
|
2021-08-11 06:45:03 +00:00
|
|
|
async def help_command(context):
|
|
|
|
""" The help new command,"""
|
|
|
|
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']
|
|
|
|
if context.arguments:
|
|
|
|
if context.arguments in help_messages:
|
|
|
|
await context.edit(str(help_messages[context.arguments]))
|
|
|
|
else:
|
|
|
|
await context.edit(lang('arg_error'))
|
|
|
|
else:
|
|
|
|
result = f"**{lang('help_list')}: \n**"
|
|
|
|
for command in sorted(help_messages, reverse=False):
|
|
|
|
if str(command) in support_commands:
|
|
|
|
continue
|
|
|
|
result += "`" + str(command)
|
|
|
|
result += "`, "
|
|
|
|
if result == f"**{lang('help_list')}: \n**":
|
|
|
|
""" The help raw command,"""
|
|
|
|
for command in sorted(help_messages, reverse=False):
|
|
|
|
result += "`" + str(command)
|
|
|
|
result += "`, "
|
|
|
|
await context.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/)")
|
|
|
|
|
|
|
|
|
|
|
|
@listener(is_plugin=False, outgoing=True, command=alias_command("help_raw"),
|
|
|
|
description=lang('help_des'),
|
|
|
|
parameters=f"<{lang('command')}>")
|
|
|
|
async def help_raw_command(context):
|
|
|
|
""" The help raw command,"""
|
2020-02-19 15:31:39 +00:00
|
|
|
if context.arguments:
|
|
|
|
if context.arguments in help_messages:
|
|
|
|
await context.edit(str(help_messages[context.arguments]))
|
|
|
|
else:
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(lang('arg_error'))
|
2020-02-19 15:31:39 +00:00
|
|
|
else:
|
2021-04-12 16:25:32 +00:00
|
|
|
result = f"**{lang('help_list')}: \n**"
|
2020-02-19 15:31:39 +00:00
|
|
|
for command in sorted(help_messages, reverse=False):
|
|
|
|
result += "`" + str(command)
|
|
|
|
result += "`, "
|
2021-04-12 16:25:32 +00:00
|
|
|
await context.edit(result[:-2] + f"\n**{lang('help_send')} \"-help <{lang('command')}>\" {lang('help_see')}** "
|
|
|
|
f"[{lang('help_source')}](https://t.me/PagerMaid_Modify)")
|
|
|
|
|
|
|
|
|
2021-06-15 04:31:05 +00:00
|
|
|
@listener(is_plugin=False, outgoing=True, command=alias_command("lang"),
|
2021-04-12 16:25:32 +00:00
|
|
|
description=lang('lang_des'))
|
|
|
|
async def lang_change(context):
|
|
|
|
to_lang = context.arguments
|
2022-02-16 15:13:41 +00:00
|
|
|
from_lang = language.locale
|
|
|
|
|
2021-04-12 16:25:32 +00:00
|
|
|
with open('config.yml') as f:
|
|
|
|
file = f.read()
|
2022-02-16 15:13:41 +00:00
|
|
|
if to_lang in language.locales:
|
2021-04-12 16:25:32 +00:00
|
|
|
file = file.replace(f'application_language: "{from_lang}"', f'application_language: "{to_lang}"')
|
|
|
|
with open('config.yml', 'w') as f:
|
|
|
|
f.write(file)
|
2022-02-16 15:13:41 +00:00
|
|
|
await context.edit(f"{lang('lang_change_to')} {to_lang}")
|
|
|
|
language.locale = to_lang
|
2021-04-12 16:25:32 +00:00
|
|
|
else:
|
2022-02-16 15:13:41 +00:00
|
|
|
msg = ""
|
|
|
|
for i in language.help_msg:
|
|
|
|
msg += f"\n{language.help_msg[i]}"
|
2021-08-11 06:45:03 +00:00
|
|
|
await context.edit(
|
2022-02-16 15:13:41 +00:00
|
|
|
f'{lang("lang_current_lang")} {language.help_msg[from_lang]}\n\n'
|
|
|
|
f'{lang("lang_all_lang")}\n'
|
|
|
|
f'{msg}')
|
2021-06-15 04:31:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
@listener(is_plugin=False, outgoing=True, command="alias",
|
|
|
|
description=lang('alias_des'),
|
|
|
|
parameters='{list|del|set} <source> <to>')
|
|
|
|
async def alias_commands(context):
|
|
|
|
source_commands = []
|
|
|
|
to_commands = []
|
|
|
|
texts = []
|
|
|
|
for key, value in alias_dict.items():
|
|
|
|
source_commands.append(key)
|
|
|
|
to_commands.append(value)
|
|
|
|
if len(context.parameter) == 0:
|
|
|
|
await context.edit(lang('arg_error'))
|
|
|
|
return
|
|
|
|
elif len(context.parameter) == 1:
|
|
|
|
if not len(source_commands) == 0:
|
|
|
|
for i in range(0, len(source_commands)):
|
|
|
|
texts.append(f'`{source_commands[i]}` --> `{to_commands[i]}`')
|
|
|
|
await context.edit(lang('alias_list') + '\n\n' + '\n'.join(texts))
|
|
|
|
else:
|
|
|
|
await context.edit(lang('alias_no'))
|
|
|
|
elif len(context.parameter) == 2:
|
|
|
|
source_command = context.parameter[1]
|
|
|
|
try:
|
|
|
|
del alias_dict[source_command]
|
|
|
|
with open("data/alias.json", 'w') as f:
|
|
|
|
json_dump(alias_dict, f)
|
2022-01-26 13:36:11 +00:00
|
|
|
result = await context.edit(lang('alias_success'))
|
|
|
|
if redis_status():
|
2022-01-26 14:36:44 +00:00
|
|
|
redis.set("restart_edit", f"{result.id}|{result.chat_id}")
|
2021-06-15 04:31:05 +00:00
|
|
|
await context.client.disconnect()
|
|
|
|
except KeyError:
|
|
|
|
await context.edit(lang('alias_no_exist'))
|
|
|
|
return
|
|
|
|
elif len(context.parameter) == 3:
|
|
|
|
source_command = context.parameter[1]
|
|
|
|
to_command = context.parameter[2]
|
|
|
|
if to_command in help_messages:
|
|
|
|
await context.edit(lang('alias_exist'))
|
|
|
|
return
|
|
|
|
alias_dict[source_command] = to_command
|
|
|
|
with open("data/alias.json", 'w') as f:
|
|
|
|
json_dump(alias_dict, f)
|
2022-01-26 13:36:11 +00:00
|
|
|
result = await context.edit(lang('alias_success'))
|
|
|
|
if redis_status():
|
2022-01-26 14:36:44 +00:00
|
|
|
redis.set("restart_edit", f"{result.id}|{result.chat_id}")
|
2021-06-15 04:31:05 +00:00
|
|
|
await context.client.disconnect()
|