summaryrefslogtreecommitdiff
path: root/ATRI/rule.py
blob: 1ed10d8b7240f2178801a2fe233395224b271ec3 (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
from re import T
from nonebot.rule import Rule
from nonebot.typing import Bot, Event

from ATRI.service import Service


def isInService(service: str) -> Rule:
    async def _isInService(bot: Bot, event: Event, state: dict) -> bool:
        return Service().Switch().auth_service(service, event.group_id)

    return Rule(_isInService)


def isInBanList() -> Rule:
    async def _isInBanList(bot: Bot, event: Event, state: dict) -> bool:
        return Service().BanList().is_in_list(event.user_id)

    return Rule(_isInBanList)


def isInDormant() -> Rule:
    async def _isInDormant(bot: Bot, event: Event, state: dict) -> bool:
        return Service().Dormant().is_sleep()

    return Rule(_isInDormant)


def toGroup() -> Rule:
    async def _toGroup(bot: Bot, event: Event, state: dict) -> bool:
        return bool(event.group_id)

    return Rule(_toGroup)


def toPrivate() -> Rule:
    async def _toPrivate(bot: Bot, event: Event, state: dict) -> bool:
        return not bool(event.group_id)

    return Rule(_toPrivate)

def toBot() -> Rule:
    async def _toBot(bot: Bot, event: Event, state: dict) -> bool:
        return bool(event.to_me)
    
    return Rule(_toBot)