summaryrefslogtreecommitdiff
path: root/ATRI/plugins/call-owner.py
blob: c09276fb2ec4f5dddc642cf894d1c44b242c46b5 (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
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
'''
File: call-owner.py
Created Date: 2021-02-19 23:02:45
Author: Kyomotoi
Email: [email protected]
License: GPLv3
Project: https://github.com/Kyomotoi/ATRI
--------
Last Modified: Sunday, 7th March 2021 3:13:40 pm
Modified By: Kyomotoi ([email protected])
--------
Copyright (c) 2021 Kyomotoi
'''

from nonebot.permission import SUPERUSER
from nonebot.plugin import on_command
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import (
    Bot,
    MessageEvent
)

from ATRI.rule import is_in_banlist
from ATRI.config import nonebot_config
from ATRI.utils.apscheduler import scheduler
from ATRI.utils.list import count_list


repo_list = []


repo = on_command("来杯红茶", rule=is_in_banlist())

@repo.handle()
async def _repo(bot: Bot, event: MessageEvent, state: T_State) -> None:
    msg = str(event.message).strip()
    if msg:
        state["msg"] = msg

@repo.got("msg", prompt="请告诉咱需要反馈的内容~!")
async def _repo_(bot: Bot, event: MessageEvent, state: T_State) -> None:
    global repo_list
    msg = state["msg"]
    user = event.user_id
    
    if count_list(repo_list, user) == 5:
        await repo.finish("吾辈已经喝了五杯红茶啦!明天再来吧。")
    
    repo_list.append(user)

    for sup in nonebot_config["superusers"]:
        await bot.send_private_msg(
            user_id=sup,
            message=f"来自用户[{user}]反馈:\n{msg}"
        )
    
    await repo.finish("吾辈的心愿已由咱转告给咱的维护者了~!")


@scheduler.scheduled_job(
    "cron",
    hour=0,
    misfire_grace_time=60
)
async def _() -> None:
    global repo_list
    repo_list = []


reset_repo = on_command("重置红茶", permission=SUPERUSER)

@reset_repo.handle()
async def _reset_repo(bot: Bot, event: MessageEvent) -> None:
    global repo_list
    repo_list = []
    await reset_repo.finish("红茶重置完成~!")