aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/hydroroll/plugins/plugin_send/__init__.py
blob: 246818922024c0dc26a4d6fa10b057c11306ac92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import re

from plugins.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))