Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/core/prefix.py
2023-03-13 18:06:34 +08:00

33 lines
1.4 KiB
Python

from core.builtins import Bot
from core.component import module
p = module('prefix', required_admin=True, base=True)
@p.command('add <prefix> {{core.prefix.help.add}}',
'remove <prefix> {{core.prefix.help.remove}}',
'reset {{core.prefix.help.reset}}')
async def set_prefix(msg: Bot.MessageSession):
prefixes = msg.options.get('command_prefix')
arg1 = msg.parsed_msg.get('<prefix>', False)
if prefixes is None:
prefixes = []
if 'add' in msg.parsed_msg:
if arg1:
if arg1 not in prefixes:
prefixes.append(arg1)
msg.data.edit_option('command_prefix', prefixes)
await msg.sendMessage(msg.locale.t("core.prefix.message.add.success", prefix=arg1))
else:
await msg.sendMessage(msg.locale.t("core.prefix.message.add.already"))
elif 'remove' in msg.parsed_msg:
if arg1:
if arg1 in prefixes:
prefixes.remove(arg1)
msg.data.edit_option('command_prefix', prefixes)
await msg.sendMessage(msg.locale.t("core.prefix.message.remove.success") + arg1)
else:
await msg.sendMessage(msg.locale.t("core.prefix.message.remove.not_found"))
elif 'reset' in msg.parsed_msg:
msg.data.edit_option('command_prefix', [])
await msg.sendMessage(msg.locale.t("core.prefix.message.reset"))