summaryrefslogtreecommitdiff
path: root/ATRI/plugins/repo.py
blob: 9c526104dd636049df497dfeeea5ca5ae2c8350b (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from random import choice

from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, MessageEvent

from ATRI.service import Service
from ATRI.config import BotSelfConfig
from ATRI.utils.limit import FreqLimiter, DailyLimiter


_repo_flmt = FreqLimiter(20)
_repo_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇会~~"])
_repo_dlmt = DailyLimiter(5)
_repo_dlmt_notice = "阿!不能再喝了,再喝就晕过去了!"


REPO_FORMAT = """
来自用户{user}反馈:
{msg}
"""


class Repo(Service):
    def __init__(self):
        Service.__init__(self, "反馈", "向维护者发送消息")


repo = Repo().on_command("来杯红茶", "向维护者发送消息", aliases={"反馈", "报告"})


@repo.args_parser  # type: ignore
async def _get_repo(bot: Bot, event: MessageEvent, state: T_State):
    msg = str(event.message).strip()
    quit_list = ["算了", "罢了", "取消"]
    if msg in quit_list:
        await repo.finish("好吧...")
    if not msg:
        await repo.reject("需要反馈的内容呢?~")
    else:
        state["repo"] = msg


@repo.handle()
async def _ready_repo(bot: Bot, event: MessageEvent, state: T_State):
    user_id = event.get_user_id()
    if not _repo_flmt.check(user_id):
        await repo.finish(_repo_flmt_notice)
    if not _repo_dlmt.check(user_id):
        await repo.finish(_repo_dlmt_notice)

    msg = str(event.message).strip()
    if msg:
        state["repo"] = msg


@repo.got("repo", "需要反馈的内容呢?~")
async def _deal_repo(bot: Bot, event: MessageEvent, state: T_State):
    msg = state["repo"]
    user_id = event.get_user_id()
    repo_0 = REPO_FORMAT.format(user=user_id, msg=msg)

    for superuser in BotSelfConfig.superusers:
        try:
            await bot.send_private_msg(user_id=superuser, message=repo_0)
        except BaseException:
            await repo.finish("发送失败了呢...")

    _repo_flmt.start_cd(user_id)
    _repo_dlmt.increase(user_id)
    await repo.finish("吾辈的心愿已由咱转告维护者!")