diff options
| author | 2023-04-18 18:03:02 +0800 | |
|---|---|---|
| committer | 2023-04-18 18:03:02 +0800 | |
| commit | 025020c503ef5b8dc0270197c5b1e6d4e0f8807d (patch) | |
| tree | 25f8c8d8882647e22ea0acebadafef99306f4c98 /plugins/alicebot_plugin_send | |
| parent | 074ad0c914ae0b53ace46ed5d4c24205eacbabaa (diff) | |
| download | HydroRoll-025020c503ef5b8dc0270197c5b1e6d4e0f8807d.tar.gz HydroRoll-025020c503ef5b8dc0270197c5b1e6d4e0f8807d.zip | |
✨本体文件
Diffstat (limited to 'plugins/alicebot_plugin_send')
| -rw-r--r-- | plugins/alicebot_plugin_send/__init__.py | 28 | ||||
| -rw-r--r-- | plugins/alicebot_plugin_send/config.py | 15 |
2 files changed, 43 insertions, 0 deletions
diff --git a/plugins/alicebot_plugin_send/__init__.py b/plugins/alicebot_plugin_send/__init__.py new file mode 100644 index 0000000..46264ed --- /dev/null +++ b/plugins/alicebot_plugin_send/__init__.py @@ -0,0 +1,28 @@ +import re + +from plugins.alicebot_plugin_base import CommandPluginBase + +from .config import Config + + +class Send(CommandPluginBase[None, Config]): + Config = Config + + def __post_init__(self): + self.re_pattern = re.compile(r"\s*(?P<message>.*)", flags=re.I) + + async def handle(self) -> None: + try: + await self.event.adapter.send( + self.msg_match.group("message"), + "private", + self.config.send_user_id, + ) + except Exception as e: + if self.config.send_filed_msg is not None: + await self.event.reply( + self.format_str(self.config.send_filed_msg, repr(e)) + ) + else: + if self.config.send_success_msg is not None: + await self.event.reply(self.format_str(self.config.send_success_msg)) diff --git a/plugins/alicebot_plugin_send/config.py b/plugins/alicebot_plugin_send/config.py new file mode 100644 index 0000000..85f794a --- /dev/null +++ b/plugins/alicebot_plugin_send/config.py @@ -0,0 +1,15 @@ +from typing import Set, Optional + +from plugins.alicebot_plugin_base import CommandPluginConfig + + +class Config(CommandPluginConfig): + __config_name__ = "plugin_send" + command: Set[str] = {"send"} + """命令文本。""" + send_user_id: int = 0 + """发送消息的对象的 QQ 号码。""" + send_success_msg: Optional[str] = None + """发送成功时回复的消息,设置为 None 表示不发送任何消息。""" + send_filed_msg: Optional[str] = "发送失败:{message}" + """发送失败时回复的消息。""" |
