-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
elements.py
151 lines (104 loc) · 4.35 KB
/
elements.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from graia.amnesia.message import Element
from graia.amnesia.message.element import Text as Text # noqa
from graia.amnesia.message.element import Unknown as Unknown # noqa
from avilla.core.resource import LocalFileResource, Resource
from avilla.core.selector import Selector
class Notice(Element):
"""该消息元素用于承载消息中用于提醒/呼唤特定用户的部分."""
target: Selector
display: str | None
def __init__(self, target: Selector, display: str | None = None) -> None:
"""实例化一个 Notice 消息元素,用于承载消息中用于提醒/呼唤特定用户的部分。
Args:
target (str): 需要提醒/呼唤的特定用户的 ID.
display (str, optional): 需要提醒/呼唤的特定用户的显示名称. Defaults to None.
"""
self.target = target
self.display = display
def __str__(self) -> str:
return "[$Notice]"
def __repr__(self) -> str:
return f"[$Notice:target={self.target}]"
class NoticeAll(Element):
"""该消息元素用于群组中的管理员提醒群组中的所有成员"""
def __init__(self) -> None:
super().__init__()
def __str__(self) -> str:
return "[$NoticeAll]"
def __eq__(self, other):
return isinstance(other, NotImplementedError)
class Picture(Element):
resource: Resource[bytes]
def __init__(self, resource: Resource[bytes] | Path | str):
if isinstance(resource, Path):
resource = LocalFileResource(resource)
elif isinstance(resource, str):
resource = LocalFileResource(Path(resource))
self.resource = resource
def __str__(self) -> str:
return "[$Picture]"
def __repr__(self):
return f"[$Picture:resource={self.resource.to_selector()}]"
def __eq__(self, other):
return isinstance(other, Picture) and self.resource.to_selector() == other.resource.to_selector()
class Audio(Element):
resource: Resource[bytes]
duration: int
def __init__(self, resource: Resource[bytes] | Path | str, duration: int = -1):
if isinstance(resource, Path):
resource = LocalFileResource(resource)
elif isinstance(resource, str):
resource = LocalFileResource(Path(resource))
self.resource = resource
self.duration = duration
def __str__(self) -> str:
return "[$Audio]"
def __repr__(self):
return f"[$Audio:resource={self.resource.to_selector()}]"
def __eq__(self, other):
return isinstance(other, Audio) and self.resource.to_selector() == other.resource.to_selector()
class Video(Element):
resource: Resource[bytes]
def __init__(self, resource: Resource[bytes] | Path | str):
if isinstance(resource, Path):
resource = LocalFileResource(resource)
elif isinstance(resource, str):
resource = LocalFileResource(Path(resource))
self.resource = resource
def __str__(self) -> str:
return "[$Video]"
def __repr__(self):
return f"[$Video:resource={self.resource.to_selector()}]"
def __eq__(self, other):
return isinstance(other, Video) and self.resource.to_selector() == other.resource.to_selector()
class File(Element):
resource: Resource[bytes]
def __init__(self, resource: Resource[bytes] | Path | str):
if isinstance(resource, Path):
resource = LocalFileResource(resource)
elif isinstance(resource, str):
resource = LocalFileResource(Path(resource))
self.resource = resource
def __str__(self) -> str:
return "[$File]"
def __repr__(self) -> str:
return f"[$File:resource={self.resource.to_selector()}]"
def __eq__(self, other):
return isinstance(other, File) and self.resource.to_selector() == other.resource.to_selector()
@dataclass
class Reference(Element):
message: Selector
slice: tuple[int, int] | None = None
def __str__(self):
return f"[$Reference:id={self.message}]"
def __eq__(self, other):
return isinstance(other, Reference) and self.message == other.message
@dataclass
class Face(Element):
id: str
name: str | None = None
def __str__(self) -> str:
return f"[Face:id={self.id};name={self.name}]"