summaryrefslogtreecommitdiff
path: root/ATRI/plugins/repo.py
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/repo.py')
-rw-r--r--ATRI/plugins/repo.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/ATRI/plugins/repo.py b/ATRI/plugins/repo.py
new file mode 100644
index 0000000..db68721
--- /dev/null
+++ b/ATRI/plugins/repo.py
@@ -0,0 +1,71 @@
+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={"反馈", "报告"})
+
[email protected]_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
+
+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
+
[email protected]("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("吾辈的心愿已由咱转告维护者!")