hyper-bot 0.80.7__tar.gz → 0.81.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/LICENSE +0 -0
  2. hyper_bot-0.81.2/PKG-INFO +20 -0
  3. hyper_bot-0.81.2/hyper_bot.egg-info/PKG-INFO +20 -0
  4. hyper_bot-0.81.2/hyper_bot.egg-info/SOURCES.txt +55 -0
  5. hyper_bot-0.81.2/hyper_bot.egg-info/requires.txt +11 -0
  6. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyper_bot.egg-info/top_level.txt +1 -0
  7. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/Kritor.py +5 -5
  8. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/Manager.py +1 -0
  9. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/Res.py +2 -2
  10. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/__init__.py +0 -0
  11. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/authentication/__init__.py +0 -0
  12. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/common/__init__.py +0 -0
  13. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/core/__init__.py +0 -0
  14. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/customization/__init__.py +0 -0
  15. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/developer/__init__.py +0 -0
  16. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/event/__init__.py +0 -0
  17. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/file/__init__.py +0 -0
  18. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/friend/__init__.py +0 -0
  19. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/group/__init__.py +0 -0
  20. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/guild/__init__.py +0 -0
  21. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/message/__init__.py +0 -0
  22. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/process/__init__.py +0 -0
  23. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/reverse/__init__.py +0 -0
  24. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/KritorLib/protos/web/__init__.py +0 -0
  25. hyper_bot-0.81.2/hyperot/LecAdapters/Milky.py +205 -0
  26. hyper_bot-0.81.2/hyperot/LecAdapters/MilkyLib/Manager.py +13 -0
  27. hyper_bot-0.81.2/hyperot/LecAdapters/MilkyLib/Res.py +126 -0
  28. hyper_bot-0.81.2/hyperot/LecAdapters/MilkyLib/translator.py +218 -0
  29. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/OneBot.py +24 -24
  30. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/OneBotLib/Manager.py +0 -0
  31. {hyper_bot-0.80.7/hyperot/Adapters → hyper_bot-0.81.2/hyperot/LecAdapters}/OneBotLib/Res.py +2 -3
  32. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/__init__.py +1 -1
  33. hyper_bot-0.81.2/hyperot/adapters/__init__.py +37 -0
  34. hyper_bot-0.81.2/hyperot/adapters/builtins.py +15 -0
  35. hyper_bot-0.81.2/hyperot/adapters/common.py +7 -0
  36. hyper_bot-0.81.2/hyperot/adapters/listener.py +85 -0
  37. hyper_bot-0.81.2/hyperot/adapters/obuilder.py +317 -0
  38. hyper_bot-0.81.2/hyperot/adapters/res.py +22 -0
  39. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/common.py +4 -14
  40. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/configurator.py +2 -0
  41. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/events.py +6 -2
  42. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/hyperogger.py +3 -3
  43. hyper_bot-0.81.2/hyperot/listener.py +9 -0
  44. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/network.py +14 -5
  45. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/segments.py +25 -23
  46. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/service.py +0 -0
  47. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/utils/ArkSignHelper.py +0 -0
  48. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/utils/apiresponse.py +0 -0
  49. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/utils/errors.py +0 -0
  50. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/utils/hypetyping.py +1 -4
  51. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/utils/logic.py +8 -0
  52. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/utils/screens.py +0 -0
  53. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyperot/utils/typextensions.py +0 -0
  54. hyper_bot-0.81.2/hytil.py +56 -0
  55. hyper_bot-0.81.2/setup.py +41 -0
  56. hyper_bot-0.80.7/PKG-INFO +0 -10
  57. hyper_bot-0.80.7/hyper_bot.egg-info/PKG-INFO +0 -10
  58. hyper_bot-0.80.7/hyper_bot.egg-info/SOURCES.txt +0 -44
  59. hyper_bot-0.80.7/hyper_bot.egg-info/requires.txt +0 -1
  60. hyper_bot-0.80.7/hyperot/Adapters/KritorLib/Manager.py +0 -1
  61. hyper_bot-0.80.7/hyperot/listener.py +0 -23
  62. hyper_bot-0.80.7/setup.py +0 -28
  63. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/hyper_bot.egg-info/dependency_links.txt +0 -0
  64. {hyper_bot-0.80.7 → hyper_bot-0.81.2}/setup.cfg +0 -0
File without changes
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.1
2
+ Name: hyper-bot
3
+ Version: 0.81.2
4
+ Summary: 稳定高效、易于开发的QQ Bot框架
5
+ Home-page: https://github.com/HarcicYang/HypeR_Bot
6
+ Author: Harcic
7
+ Author-email: harcic@outlook.com
8
+ Provides: hyperot
9
+ License-File: LICENSE
10
+ Requires-Dist: aiohttp~=3.9.5
11
+ Requires-Dist: requests~=2.31.0
12
+ Requires-Dist: httpx~=0.26.0
13
+ Requires-Dist: grpclib~=0.4.7
14
+ Requires-Dist: betterproto~=2.0.0b7
15
+ Requires-Dist: websocket-client~=1.8.0
16
+ Requires-Dist: Flask~=3.0.0
17
+ Requires-Dist: google~=3.0.0
18
+ Requires-Dist: protobuf~=4.25.3
19
+ Requires-Dist: ucfgr
20
+ Requires-Dist: PyYAML
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.1
2
+ Name: hyper-bot
3
+ Version: 0.81.2
4
+ Summary: 稳定高效、易于开发的QQ Bot框架
5
+ Home-page: https://github.com/HarcicYang/HypeR_Bot
6
+ Author: Harcic
7
+ Author-email: harcic@outlook.com
8
+ Provides: hyperot
9
+ License-File: LICENSE
10
+ Requires-Dist: aiohttp~=3.9.5
11
+ Requires-Dist: requests~=2.31.0
12
+ Requires-Dist: httpx~=0.26.0
13
+ Requires-Dist: grpclib~=0.4.7
14
+ Requires-Dist: betterproto~=2.0.0b7
15
+ Requires-Dist: websocket-client~=1.8.0
16
+ Requires-Dist: Flask~=3.0.0
17
+ Requires-Dist: google~=3.0.0
18
+ Requires-Dist: protobuf~=4.25.3
19
+ Requires-Dist: ucfgr
20
+ Requires-Dist: PyYAML
@@ -0,0 +1,55 @@
1
+ LICENSE
2
+ hytil.py
3
+ setup.py
4
+ hyper_bot.egg-info/PKG-INFO
5
+ hyper_bot.egg-info/SOURCES.txt
6
+ hyper_bot.egg-info/dependency_links.txt
7
+ hyper_bot.egg-info/requires.txt
8
+ hyper_bot.egg-info/top_level.txt
9
+ hyperot/__init__.py
10
+ hyperot/common.py
11
+ hyperot/configurator.py
12
+ hyperot/events.py
13
+ hyperot/hyperogger.py
14
+ hyperot/listener.py
15
+ hyperot/network.py
16
+ hyperot/segments.py
17
+ hyperot/service.py
18
+ hyperot/LecAdapters/Kritor.py
19
+ hyperot/LecAdapters/Milky.py
20
+ hyperot/LecAdapters/OneBot.py
21
+ hyperot/LecAdapters/KritorLib/Manager.py
22
+ hyperot/LecAdapters/KritorLib/Res.py
23
+ hyperot/LecAdapters/KritorLib/protos/__init__.py
24
+ hyperot/LecAdapters/KritorLib/protos/authentication/__init__.py
25
+ hyperot/LecAdapters/KritorLib/protos/common/__init__.py
26
+ hyperot/LecAdapters/KritorLib/protos/core/__init__.py
27
+ hyperot/LecAdapters/KritorLib/protos/customization/__init__.py
28
+ hyperot/LecAdapters/KritorLib/protos/developer/__init__.py
29
+ hyperot/LecAdapters/KritorLib/protos/event/__init__.py
30
+ hyperot/LecAdapters/KritorLib/protos/file/__init__.py
31
+ hyperot/LecAdapters/KritorLib/protos/friend/__init__.py
32
+ hyperot/LecAdapters/KritorLib/protos/group/__init__.py
33
+ hyperot/LecAdapters/KritorLib/protos/guild/__init__.py
34
+ hyperot/LecAdapters/KritorLib/protos/message/__init__.py
35
+ hyperot/LecAdapters/KritorLib/protos/process/__init__.py
36
+ hyperot/LecAdapters/KritorLib/protos/reverse/__init__.py
37
+ hyperot/LecAdapters/KritorLib/protos/web/__init__.py
38
+ hyperot/LecAdapters/MilkyLib/Manager.py
39
+ hyperot/LecAdapters/MilkyLib/Res.py
40
+ hyperot/LecAdapters/MilkyLib/translator.py
41
+ hyperot/LecAdapters/OneBotLib/Manager.py
42
+ hyperot/LecAdapters/OneBotLib/Res.py
43
+ hyperot/adapters/__init__.py
44
+ hyperot/adapters/builtins.py
45
+ hyperot/adapters/common.py
46
+ hyperot/adapters/listener.py
47
+ hyperot/adapters/obuilder.py
48
+ hyperot/adapters/res.py
49
+ hyperot/utils/ArkSignHelper.py
50
+ hyperot/utils/apiresponse.py
51
+ hyperot/utils/errors.py
52
+ hyperot/utils/hypetyping.py
53
+ hyperot/utils/logic.py
54
+ hyperot/utils/screens.py
55
+ hyperot/utils/typextensions.py
@@ -0,0 +1,11 @@
1
+ aiohttp~=3.9.5
2
+ requests~=2.31.0
3
+ httpx~=0.26.0
4
+ grpclib~=0.4.7
5
+ betterproto~=2.0.0b7
6
+ websocket-client~=1.8.0
7
+ Flask~=3.0.0
8
+ google~=3.0.0
9
+ protobuf~=4.25.3
10
+ ucfgr
11
+ PyYAML
@@ -5,8 +5,8 @@ import threading
5
5
  import time
6
6
 
7
7
  from .. import common
8
- from ..Adapters.OneBot import Actions as OneBotActions
9
- from ..Adapters.KritorLib.Res import event_queue, to_protos, message_ids
8
+ from ..LecAdapters.OneBot import Actions as OneBotActions
9
+ from ..LecAdapters.KritorLib.Res import event_queue, to_protos, message_ids
10
10
  from ..events import Event, HyperNotify, HyperListenerStartNotify, em
11
11
  from ..service import FuncCall, IServiceStartUp, IServiceBase
12
12
  from ..network import KritorConnection
@@ -14,9 +14,9 @@ from ..utils import errors
14
14
  from ..utils.apiresponse import *
15
15
  from .. import configurator, hyperogger
16
16
 
17
- from ..Adapters.KritorLib.protos.common import Contact, Scene
18
- from ..Adapters.KritorLib.protos.core import GetVersionRequest, CoreServiceStub
19
- from ..Adapters.KritorLib.protos.message import (
17
+ from ..LecAdapters.KritorLib.protos.common import Contact, Scene
18
+ from ..LecAdapters.KritorLib.protos.core import GetVersionRequest, CoreServiceStub
19
+ from ..LecAdapters.KritorLib.protos.message import (
20
20
  MessageServiceStub,
21
21
  SendMessageRequest,
22
22
  RecallMessageRequest,
@@ -0,0 +1 @@
1
+ from ...LecAdapters.OneBotLib.Manager import *
@@ -1,4 +1,4 @@
1
- from ...Adapters.KritorLib.protos.event import (
1
+ from ...LecAdapters.KritorLib.protos.event import (
2
2
  EventServiceStub,
3
3
  RequestPushEvent,
4
4
  EventType,
@@ -7,7 +7,7 @@ from ...Adapters.KritorLib.protos.event import (
7
7
  GroupMemberDecreasedNoticeGroupMemberDecreasedType,
8
8
  GroupMemberIncreasedNoticeGroupMemberIncreasedType
9
9
  )
10
- from ...Adapters.KritorLib.protos.common import (
10
+ from ...LecAdapters.KritorLib.protos.common import (
11
11
  ElementElementType,
12
12
  PushMessageBody,
13
13
  Scene, Element,
@@ -0,0 +1,205 @@
1
+ from ..utils.hypetyping import Any, NoReturn, TypeVar, Callable
2
+ from ..utils.apiresponse import *
3
+ from ..events import *
4
+ from .. import events, network
5
+ from ..utils import errors
6
+
7
+ from .MilkyLib.translator import MilkyHttpConnection, msg_deid, msg_enid, to_milky_message
8
+ from .MilkyLib.Manager import Packet
9
+
10
+ import time
11
+ import threading
12
+ import asyncio
13
+ import json
14
+ import sys
15
+
16
+ config = configurator.BotConfig.get("hyper-bot")
17
+ logger = hyperogger.Logger()
18
+ logger.set_level(config.log_level)
19
+ listener_ran = False
20
+
21
+
22
+ class Actions:
23
+ def __init__(self, cnt: MilkyHttpConnection):
24
+ self.connection = cnt
25
+
26
+ class CustomAction:
27
+ def __init__(self, cnt_i: MilkyHttpConnection):
28
+ self.connection = cnt_i
29
+
30
+ def __getattr__(self, item) -> callable:
31
+ async def wrapper(**kwargs) -> str:
32
+ packet = Packet(
33
+ str(item),
34
+ **kwargs
35
+ )
36
+ packet.send_to(self.connection)
37
+ return packet.echo
38
+
39
+ return wrapper
40
+
41
+ self.custom = CustomAction(self.connection)
42
+
43
+ async def send(
44
+ self, message: Union[common.Message, str], group_id: int = None, user_id: int = None
45
+ ) -> common.Ret[MsgSendRsp]:
46
+ if group_id is None:
47
+ res = Packet(
48
+ "send_private_msg",
49
+ user_id=user_id,
50
+ message=to_milky_message(common.Message(message))
51
+ if not isinstance(message, common.Message) else
52
+ to_milky_message(message),
53
+ ).send_to(self.connection)
54
+ ret = common.Ret(res)
55
+ ret.data = MsgSendRsp({"message_id": msg_enid(0, res["message_seq"], user_id)})
56
+ return ret
57
+ else:
58
+ res = Packet(
59
+ "send_group_msg",
60
+ group_id=group_id,
61
+ message=to_milky_message(common.Message(message))
62
+ if not isinstance(message, common.Message) else
63
+ to_milky_message(message),
64
+ ).send_to(self.connection)
65
+ ret = common.Ret(res)
66
+ ret.data = MsgSendRsp({"message_id": msg_enid(1, res["message_seq"], group_id)})
67
+ return ret
68
+
69
+ async def del_message(self, message_id: int) -> None:
70
+ ...
71
+
72
+ async def set_group_kick(self, group_id: int, user_id: int) -> None:
73
+ ...
74
+
75
+ async def set_group_ban(self, group_id: int, user_id: int, duration: int = 60) -> None:
76
+ ...
77
+
78
+ async def get_login_info(self) -> common.Ret[GetLoginInfoRsp]:
79
+ ...
80
+
81
+ async def get_version_info(self) -> common.Ret[GetVerInfoRsp]:
82
+ ...
83
+
84
+ async def send_forward_msg(self, message: common.Message) -> common.Ret[SendForwardRsp]:
85
+ ...
86
+
87
+ async def get_forward_msg(self, sid: str) -> common.Ret[common.Message]:
88
+ ...
89
+
90
+ async def forward_solve(self, message: common.Message) -> common.Message:
91
+ ...
92
+
93
+ async def send_group_forward_msg(self, group_id: int, message: common.Message) -> common.Ret[SendGrpForwardRsp]:
94
+ ...
95
+
96
+ async def set_group_add_request(self, flag: str, sub_type: str, approve: bool,
97
+ reason: str = "Not Mentioned") -> None:
98
+ ...
99
+
100
+ async def get_stranger_info(self, user_id: int) -> common.Ret[GetStrInfoRsp]:
101
+ ...
102
+
103
+ async def get_group_member_info(self, group_id: int, user_id: int) -> common.Ret[GetGrpMemInfoRsp]:
104
+ ...
105
+
106
+ async def get_group_info(self, group_id: int) -> common.Ret[GetGrpInfoRsp]:
107
+ ...
108
+
109
+ async def get_status(self) -> common.Ret:
110
+ ...
111
+
112
+ async def set_essence_msg(self, message_id: int) -> None:
113
+ ...
114
+
115
+ async def set_group_special_title(self, group_id: int, user_id: int, title: str) -> None:
116
+ ...
117
+
118
+ async def get_msg(self, msg_id: int) -> common.Ret[GetMsgRsp]:
119
+ ...
120
+
121
+ async def send_callback(self, group_id: int, bot_id: int, data: dict) -> None:
122
+ ...
123
+
124
+
125
+ async def tester(
126
+ message_data: Union[Event, HyperNotify], actions: Actions
127
+ ) -> None:
128
+ ...
129
+
130
+
131
+ def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
132
+ if isinstance(data, dict):
133
+ asyncio.run(handler(events.em.new(data), actions))
134
+ else:
135
+ asyncio.run(handler(data, actions))
136
+
137
+
138
+ handler: callable = tester
139
+
140
+
141
+ def reg(func: callable) -> None:
142
+ global handler
143
+ handler = func
144
+
145
+
146
+ connection: MilkyHttpConnection
147
+
148
+
149
+ def run() -> NoReturn:
150
+ global connection, listener_ran
151
+ listener_ran = True
152
+ try:
153
+ if handler is tester:
154
+ raise errors.ListenerNotRegisteredError("No handler registered")
155
+ if isinstance(config.connection, configurator.BotWSC):
156
+ connection = network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}")
157
+ elif isinstance(config.connection, configurator.BotHTTPC):
158
+ connection = network.HTTPConnection(
159
+ url=f"http://{config.connection.host}:{config.connection.port}",
160
+ listener_url=f"http://{config.connection.listener_host}:{config.connection.listener_port}"
161
+ )
162
+ retried = 0
163
+
164
+ while True:
165
+ try:
166
+ connection.connect()
167
+ except ConnectionRefusedError or TimeoutError:
168
+ if retried >= config.connection.retries:
169
+ logger.critical(f"重试次数达到最大值({config.connection.retries}),退出")
170
+ break
171
+
172
+ logger.warning(f"连接建立失败,3秒后重试({retried}/{config.connection.retries})")
173
+ retried += 1
174
+ time.sleep(3)
175
+ continue
176
+ retried = 0
177
+ logger.info(f"成功在 {connection.url} 建立连接")
178
+ actions = Actions(connection)
179
+ data = HyperListenerStartNotify(
180
+ time_now=int(time.time()),
181
+ notify_type="listener_start",
182
+ connection=connection
183
+ )
184
+ threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
185
+ while True:
186
+ try:
187
+ data = connection.recv()
188
+ except ConnectionResetError:
189
+ logger.error("连接断开")
190
+ break
191
+ except json.decoder.JSONDecodeError:
192
+ logger.error("收到错误的JSON内容")
193
+ continue
194
+ threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
195
+ except KeyboardInterrupt:
196
+ logger.warning("正在退出(Ctrl+C)")
197
+ try:
198
+ connection.close()
199
+ except:
200
+ pass
201
+ sys.exit()
202
+
203
+
204
+ def stop() -> None:
205
+ ...
@@ -0,0 +1,13 @@
1
+ from .translator import MilkyHttpConnection
2
+
3
+
4
+ class Packet:
5
+ def __init__(self, endpoint: str, **kwargs):
6
+ self.endpoint = endpoint
7
+ self.paras = kwargs
8
+
9
+ def send_to(self, connection: MilkyHttpConnection) -> dict:
10
+ if isinstance(connection, MilkyHttpConnection):
11
+ return connection.http_send(self.endpoint, self.paras)
12
+ else:
13
+ raise ValueError(f"Invalid connection: {connection}")
@@ -0,0 +1,126 @@
1
+ from abc import ABC
2
+
3
+ from ...utils.hypetyping import OneBotSegReg
4
+ from ...utils.logic import Matcher
5
+ from .translator import MilkyOutGoingSegBuilder, msg_deid
6
+
7
+ message_types = {}
8
+
9
+
10
+ class SegmentBase(ABC):
11
+ def __init__(self, *args, **kwargs):
12
+ var = self.__var
13
+ anns = self.__anns
14
+ arg = {}
15
+ if len(args) > 0:
16
+ for i in args:
17
+ arg[list(anns.keys())[list(args).index(i)]] = i
18
+
19
+ if len(kwargs) > 0:
20
+ for i in kwargs:
21
+ try:
22
+ arg[i] = anns[i](kwargs[i])
23
+ except TypeError:
24
+ arg[i] = kwargs[i]
25
+ new_arg = arg.copy()
26
+
27
+ if len(anns) > len(arg):
28
+ for i in anns.keys():
29
+ if i not in arg.keys():
30
+ if i not in var.keys():
31
+ new_arg[i] = None
32
+ continue
33
+ if not isinstance(var[i], anns[i]):
34
+ new_arg[i] = anns[i](var[i])
35
+ else:
36
+ new_arg[i] = var[i]
37
+
38
+ for i in new_arg:
39
+ setattr(self, i, new_arg[i])
40
+
41
+ def __init_subclass__(cls, **kwargs):
42
+ sg_type = kwargs.get("sg_type") or kwargs.get("st")
43
+ summary_tmp = kwargs.get("summary_tmp") or kwargs.get("su")
44
+
45
+ if sg_type is summary_tmp is None:
46
+ return
47
+
48
+ cls.__sg_type = sg_type
49
+ cls.__var = dict(vars(cls))
50
+ cls.__anns: dict = cls.__var.get("__annotations__", False) or dict()
51
+
52
+ def to_str(self) -> str:
53
+ text = summary_tmp
54
+ if text is None:
55
+ text = "[]"
56
+ if "<" not in text and ">" not in text:
57
+ return text
58
+
59
+ for i in cls.__anns:
60
+ if f"<{i}>" in summary_tmp:
61
+ try:
62
+ v = self.__getattribute__(i)
63
+ except AttributeError:
64
+ v = None
65
+ text = text.replace(f"<{i}>", str(v))
66
+
67
+ return text
68
+
69
+ cls.__str__ = to_str if cls().__str__() == "__not_set__" else cls.__str__
70
+
71
+ message_types[sg_type]: OneBotSegReg = {
72
+ "type": cls,
73
+ "args": list(cls.__anns.keys()),
74
+ }
75
+
76
+ return cls
77
+
78
+ def to_json(self) -> dict:
79
+ base = {"type": self.__sg_type, "data": {}}
80
+ for i in self.__anns:
81
+ if i.startswith("__") or getattr(self, i) is None:
82
+ continue
83
+ if not isinstance(getattr(self, i), self.__anns[i]):
84
+ base["data"][i] = self.__anns[i](getattr(self, i))
85
+ else:
86
+ base["data"][i] = getattr(self, i)
87
+ return base
88
+
89
+ def milky_outgoing_seg(self) -> dict:
90
+ data = self.to_json()
91
+ builder = MilkyOutGoingSegBuilder()
92
+ seg_type = data["type"]
93
+ ma = Matcher(seg_type).match
94
+ if ma("text"):
95
+ return builder.text(data["data"]["text"]).build()[0]
96
+ elif ma("image"):
97
+ return builder.image(data["data"]["file"], data["data"].get("summary", "[Image]")).build()[0]
98
+ elif ma("at"):
99
+ if data["data"].get("user_id") == "all":
100
+ return builder.mention_all().build()[0]
101
+ return builder.mention(data["data"].get("qq")).build()[0]
102
+ elif ma("reply"):
103
+ return builder.reply(msg_deid(data["data"]["id"])[1]).build()[0]
104
+ elif ma("face"):
105
+ return builder.face(data["data"]["id"]).build()[0]
106
+ elif ma("record"):
107
+ return builder.record(data["data"]["file"]).build()[0]
108
+ elif ma("video"):
109
+ return builder.video(data["data"]["file"]).build()[0]
110
+ else:
111
+ return builder.text("").build()[0]
112
+
113
+ def __str__(self) -> str:
114
+ return "__not_set__"
115
+
116
+ def __eq__(self, other) -> bool:
117
+ if type(self) is type(other) and self.to_json() == other.to_json():
118
+ return True
119
+ else:
120
+ return False
121
+
122
+ def __ne__(self, other) -> bool:
123
+ if type(self) is type(other) and self.to_json() == other.to_json():
124
+ return False
125
+ else:
126
+ return True