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

40 lines
1.7 KiB
Python
Raw Normal View History

2023-02-06 13:21:53 +00:00
from core.builtins import Bot
2023-03-04 08:51:56 +00:00
from core.component import module
2022-08-27 16:17:01 +00:00
2023-03-04 08:51:56 +00:00
p = module('prefix', required_admin=True, base=True)
2022-08-27 16:17:01 +00:00
2023-05-19 04:46:29 +00:00
@p.command('add <prefix> {{core.help.prefix.add}}',
'remove <prefix> {{core.help.prefix.remove}}',
'reset {{core.help.prefix.reset}}',
'list {{core.help.prefix.list}}')
2023-02-06 13:21:53 +00:00
async def set_prefix(msg: Bot.MessageSession):
2022-08-27 16:17:01 +00:00
prefixes = msg.options.get('command_prefix')
2023-11-27 11:33:41 +00:00
prefix = msg.parsed_msg.get('<prefix>', False)
2022-08-27 16:17:01 +00:00
if prefixes is None:
prefixes = []
if 'add' in msg.parsed_msg:
2023-11-27 11:33:41 +00:00
if prefix:
if prefix not in prefixes:
prefixes.append(prefix)
2022-08-27 16:17:01 +00:00
msg.data.edit_option('command_prefix', prefixes)
2023-11-28 01:59:49 +00:00
await msg.finish(msg.locale.t("core.message.prefix.add.success", prefix=prefix))
2022-08-27 16:17:01 +00:00
else:
2023-11-28 01:59:49 +00:00
await msg.finish(msg.locale.t("core.message.prefix.add.already"))
2022-08-27 16:17:01 +00:00
elif 'remove' in msg.parsed_msg:
2023-11-27 11:33:41 +00:00
if prefix:
if prefix in prefixes:
prefixes.remove(prefix)
2022-08-27 16:17:01 +00:00
msg.data.edit_option('command_prefix', prefixes)
2023-11-28 01:59:49 +00:00
await msg.finish(msg.locale.t("core.message.prefix.remove.success", prefix=prefix))
2022-08-27 16:17:01 +00:00
else:
2023-11-28 01:59:49 +00:00
await msg.finish(msg.locale.t("core.message.prefix.remove.not_found"))
2022-08-27 16:17:01 +00:00
elif 'reset' in msg.parsed_msg:
msg.data.edit_option('command_prefix', [])
2023-11-28 01:59:49 +00:00
await msg.finish(msg.locale.t("core.message.prefix.reset"))
2023-05-15 15:00:33 +00:00
elif 'list' in msg.parsed_msg:
if len(prefixes) == 0:
2023-11-28 01:59:49 +00:00
await msg.finish(msg.locale.t("core.message.prefix.list.none"))
2023-05-15 15:00:33 +00:00
else:
2023-09-01 14:38:32 +00:00
await msg.finish(msg.locale.t('core.message.prefix.list', prefixes=', '.join(prefixes)))