-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
request.py
73 lines (54 loc) · 1.89 KB
/
request.py
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
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime
from typing import TYPE_CHECKING
from avilla.standard.core.request.capability import RequestCapability
from ._runtime import cx_context
from .metadata import Metadata
from .platform import Land
if TYPE_CHECKING:
from .account import BaseAccount
from .selector import Selector
@dataclass
class Request(Metadata):
id: str
land: Land
scene: Selector
sender: Selector
account: BaseAccount
time: datetime
request_type: str | None = None
operator: Selector | None = None
response: str | None = None
message: str | None = None
@property
def solved(self) -> bool:
return self.response is not None
@property
def pending(self) -> bool:
return self.response is None
@property
def accepted(self) -> bool:
return self.response == "accept"
@property
def rejected(self) -> bool:
return self.response == "reject"
@property
def cannelled(self) -> bool:
return self.response == "cancel"
@property
def ignored(self) -> bool:
return self.response == "ignore"
def to_selector(self) -> Selector:
request_id = self.id
if self.request_type is not None:
request_id = f"{self.request_type}@{request_id}"
return self.scene.request(request_id)
async def accept(self):
return await cx_context.get()[RequestCapability.accept](self.to_selector())
async def reject(self, reason: str | None = None, forever: bool = False):
return await cx_context.get()[RequestCapability.reject](self.to_selector(), reason, forever)
async def cancel(self):
return await cx_context.get()[RequestCapability.cancel](self.to_selector())
async def ignore(self):
return await cx_context.get()[RequestCapability.ignore](self.to_selector())