hyper-bot 0.78.2__tar.gz → 0.79.1__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 (55) hide show
  1. hyper-bot-0.79.1/Hyper/Adapters/Kritor.py +244 -0
  2. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/Manager.py +1 -0
  3. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/Res.py +484 -0
  4. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/__init__.py +0 -0
  5. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/authentication/__init__.py +264 -0
  6. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/common/__init__.py +412 -0
  7. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/core/__init__.py +210 -0
  8. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/customization/__init__.py +58 -0
  9. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/developer/__init__.py +435 -0
  10. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/event/__init__.py +412 -0
  11. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/file/__init__.py +368 -0
  12. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/friend/__init__.py +486 -0
  13. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/group/__init__.py +971 -0
  14. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/guild/__init__.py +804 -0
  15. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/message/__init__.py +686 -0
  16. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/process/__init__.py +168 -0
  17. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/reverse/__init__.py +68 -0
  18. hyper-bot-0.79.1/Hyper/Adapters/KritorLib/protos/web/__init__.py +200 -0
  19. hyper-bot-0.79.1/Hyper/Adapters/LagrangePy.py +113 -0
  20. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Adapters/OneBot.py +84 -64
  21. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Adapters/OneBotLib/Manager.py +22 -22
  22. hyper-bot-0.79.1/Hyper/Adapters/OneBotLib/Res.py +101 -0
  23. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Adapters/Satori.py +4 -2
  24. hyper-bot-0.79.1/Hyper/Comm.py +14 -0
  25. hyper-bot-0.79.1/Hyper/Configurator.py +48 -0
  26. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Events.py +30 -13
  27. hyper-bot-0.79.1/Hyper/Listener.py +23 -0
  28. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Logger.py +30 -9
  29. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Network.py +42 -32
  30. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Segments.py +42 -43
  31. hyper-bot-0.79.1/Hyper/Service.py +51 -0
  32. hyper-bot-0.79.1/Hyper/Utils/APIRsp.py +201 -0
  33. hyper-bot-0.79.1/Hyper/Utils/ArkSignHelper.py +175 -0
  34. hyper-bot-0.79.1/Hyper/Utils/HyperTyping.py +15 -0
  35. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Utils/Logic.py +70 -1
  36. hyper-bot-0.79.1/Hyper/Utils/Screens.py +50 -0
  37. hyper-bot-0.79.1/Hyper/__init__.py +86 -0
  38. hyper-bot-0.79.1/LICENSE +674 -0
  39. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/PKG-INFO +1 -1
  40. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/hyper_bot.egg-info/PKG-INFO +1 -1
  41. hyper-bot-0.79.1/hyper_bot.egg-info/SOURCES.txt +45 -0
  42. hyper-bot-0.79.1/setup.py +26 -0
  43. hyper-bot-0.78.2/Hyper/Adapters/OneBotLib/Res.py +0 -111
  44. hyper-bot-0.78.2/Hyper/Configurator.py +0 -118
  45. hyper-bot-0.78.2/Hyper/Listener.py +0 -17
  46. hyper-bot-0.78.2/Hyper/Manager.py +0 -8
  47. hyper-bot-0.78.2/Hyper/__init__.py +0 -1
  48. hyper-bot-0.78.2/LICENSE +0 -547
  49. hyper-bot-0.78.2/hyper_bot.egg-info/SOURCES.txt +0 -21
  50. hyper-bot-0.78.2/setup.py +0 -16
  51. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Utils/Errors.py +0 -0
  52. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/Hyper/Utils/TypeExt.py +0 -0
  53. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/hyper_bot.egg-info/dependency_links.txt +0 -0
  54. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/hyper_bot.egg-info/top_level.txt +0 -0
  55. {hyper-bot-0.78.2 → hyper-bot-0.79.1}/setup.cfg +0 -0
@@ -0,0 +1,244 @@
1
+ import asyncio
2
+ from typing import Any, Union, Self
3
+ import sys
4
+ import threading
5
+ import time
6
+
7
+ from Hyper import Comm
8
+ from Hyper.Adapters.OneBot import Actions as OneBotActions
9
+ from Hyper.Adapters.KritorLib.Res import event_queue, to_protos, message_ids
10
+ from Hyper.Events import Event, HyperNotify, HyperListenerStartNotify, em
11
+ from Hyper.Service import FuncCall, IServiceStartUp, IServiceBase
12
+ from Hyper.Network import KritorConnection
13
+ from Hyper.Utils import Errors
14
+ from Hyper.Utils.APIRsp import *
15
+ from Hyper import Configurator, Logger
16
+
17
+ from Hyper.Adapters.KritorLib.protos.common import Contact, Scene
18
+ from Hyper.Adapters.KritorLib.protos.core import GetVersionRequest, CoreServiceStub
19
+ from Hyper.Adapters.KritorLib.protos.message import (
20
+ MessageServiceStub,
21
+ SendMessageRequest,
22
+ RecallMessageRequest,
23
+ GetMessageRequest
24
+ )
25
+
26
+ config = Configurator.BotConfig.get("hyper-bot")
27
+ logger = Logger.Logger()
28
+ logger.set_level(config.log_level)
29
+
30
+
31
+ def mid_res(msg_id: str) -> tuple[str, int, int]:
32
+ ret = ["", 0, 0]
33
+ ret[0] = "group" if msg_id.startswith("g") else "private"
34
+ msg_id = msg_id.replace("g", "").replace("p", "")
35
+ ret[1] = int(msg_id[:20])
36
+ ret[2] = int(msg_id[20:])
37
+ return ret[0], ret[1], ret[2]
38
+
39
+
40
+ class Actions(OneBotActions):
41
+ def __init__(self, cnt: KritorConnection):
42
+ self.connection = cnt
43
+
44
+ @Logger.AutoLogAsync.register(Logger.AutoLog.templates().send, logger)
45
+ async def send(
46
+ self, message: Comm.Message, group_id: int = None, user_id: int = None
47
+ ) -> Comm.Ret[MsgSendRsp]:
48
+ msg = to_protos(message.get_sync())
49
+ if group_id is not None:
50
+ contact = Contact(
51
+ scene=Scene.GROUP,
52
+ peer=str(group_id),
53
+ )
54
+ else:
55
+ contact = Contact(
56
+ scene=Scene.FRIEND,
57
+ peer=str(user_id),
58
+ )
59
+ req = SendMessageRequest(
60
+ contact=contact,
61
+ elements=msg,
62
+ retry_count=3
63
+ )
64
+ res = await MessageServiceStub(self.connection.channel).send_message(req)
65
+ message_ids[res.message_id] = len(message_ids)
66
+ return Comm.Ret(
67
+ {"data": {"message_id": message_ids[res.message_id]}},
68
+ MsgSendRsp
69
+ )
70
+
71
+ async def get_version_info(self) -> Comm.Ret[GetVerInfoRsp]:
72
+ res = await CoreServiceStub(self.connection.channel).get_version(GetVersionRequest())
73
+ return Comm.Ret(
74
+ {"data": {"app_name": res.app_name, "app_version": res.version, "protocol_version": None}},
75
+ GetVerInfoRsp
76
+ )
77
+
78
+ async def get_msg(self, msg_id: int) -> Comm.Ret[GetMsgRsp]:
79
+ try:
80
+ mid = list(filter(lambda x: message_ids[x] == msg_id, message_ids))[1]
81
+ except IndexError:
82
+ mid = list(filter(lambda x: message_ids[x] == msg_id, message_ids))[0]
83
+ if str(mid).startswith("g"): # GROUP
84
+ contact = Contact(
85
+ scene=Scene.GROUP,
86
+ peer=str(mid_res(mid)[1]),
87
+ )
88
+ res = await MessageServiceStub(self.connection.channel).get_message(GetMessageRequest(contact, mid))
89
+ print(res)
90
+ return Comm.Ret(
91
+ {
92
+ "time": res.message.time,
93
+ "message_type": "group",
94
+ "message_id": msg_id,
95
+ "real_id": 0,
96
+ "sender": {
97
+ "user_id": res.message.group.uin,
98
+ "nickname": res.message.group.nick,
99
+ "sex": "unknown",
100
+ "age": 0,
101
+ "card": res.message.group.nick,
102
+ "area": "unknown",
103
+ "level": "0",
104
+ "role": "unknown",
105
+ "title": None
106
+ }
107
+ },
108
+ GetMsgRsp
109
+ )
110
+ else:
111
+ contact = Contact(
112
+ scene=Scene.FRIEND,
113
+ peer=str(mid_res(mid)[1]),
114
+ )
115
+ res = await MessageServiceStub(self.connection.channel).get_message(GetMessageRequest(contact, mid))
116
+ return Comm.Ret(
117
+ {
118
+ "time": res.message.time,
119
+ "message_type": "private",
120
+ "message_id": msg_id,
121
+ "real_id": 0,
122
+ "sender": {
123
+ "user_id": res.message.private.uin,
124
+ "nickname": res.message.private.nick,
125
+ "sex": "unknown",
126
+ "age": 0
127
+ }
128
+ },
129
+ GetMsgRsp
130
+ )
131
+
132
+
133
+ async def tester(message_data: Union[Event, HyperNotify], actions: Actions) -> None:
134
+ ...
135
+
136
+
137
+ def _handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
138
+ if isinstance(data, dict):
139
+ if data.get("post_type") == "meta_event" or data.get("user_id") == data.get("self_id"):
140
+ pass
141
+ else:
142
+ asyncio.run(handler(em.new(data), actions))
143
+ else:
144
+ asyncio.run(handler(data, actions))
145
+
146
+
147
+ handler: callable = tester
148
+
149
+
150
+ def reg(func: callable):
151
+ global handler
152
+ handler = func
153
+
154
+
155
+ connection: KritorConnection
156
+ listener_ran = False
157
+
158
+
159
+ class KritorEventGettingService(IServiceBase):
160
+ actions: Actions
161
+
162
+ def handler(self, func: FuncCall) -> Any:
163
+ pass
164
+
165
+ def set_actions(self, act: Actions) -> Self:
166
+ self.actions = act
167
+ return self
168
+
169
+ async def server(self) -> Any:
170
+ while 1:
171
+ threading.Thread(target=lambda: _handler(event_queue.get(), self.actions), daemon=True).start()
172
+
173
+
174
+ def run():
175
+ global listener_ran
176
+ listener_ran = True
177
+
178
+ async def hy_i_runner():
179
+ global connection
180
+ if handler is tester:
181
+ raise Errors.ListenerNotRegisteredError("No handler registered")
182
+ # connection = websocket.WebSocket()
183
+ # if isinstance(config.connection, Configurator.WSConnectionC):
184
+ # connection = Network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}")
185
+ # elif isinstance(config.connection, Configurator.HTTPConnectionC):
186
+ # connection = Network.HTTPConnection(
187
+ # url=f"http://{config.connection.host}:{config.connection.port}",
188
+ # listener_url=f"http://{config.connection.listener_host}:{config.connection.listener_port}"
189
+ # )
190
+ connection = KritorConnection(
191
+ host=config.connection.host,
192
+ port=config.connection.port,
193
+ )
194
+ retried = 0
195
+ while True:
196
+ try:
197
+ connection.connect()
198
+ except ConnectionRefusedError or TimeoutError:
199
+ if retried >= config.connection.retries:
200
+ logger.log(f"重试次数达到最大值({config.connection.retries}),退出",
201
+ level=Logger.levels.CRITICAL)
202
+ break
203
+
204
+ logger.log(f"连接建立失败,3秒后重试({retried}/{config.connection.retries})",
205
+ level=Logger.levels.WARNING)
206
+ retried += 1
207
+ time.sleep(3)
208
+ continue
209
+ logger.log("成功建立连接", level=Logger.levels.INFO)
210
+ retried = 0
211
+ actions = Actions(connection)
212
+ data = HyperListenerStartNotify(
213
+ time_now=int(time.time()),
214
+ notify_type="listener_start",
215
+ connection=connection
216
+ )
217
+ threading.Thread(target=lambda: _handler(data, actions), daemon=True).start()
218
+ task = None
219
+ while True:
220
+ try:
221
+ task = connection.recv()
222
+ KritorEventGettingService(IServiceStartUp.MANUAL).set_actions(actions).run_in_thread()
223
+ await task
224
+ except ConnectionResetError:
225
+ task = None
226
+ logger.log("连接断开", level=Logger.levels.ERROR)
227
+ break
228
+ # threading.Thread(target=lambda: asyncio.run(__handler(data, actions))).start()
229
+ # threading.Thread(target=lambda: __handler(data, actions)).start()
230
+ # asyncio.create_task(__handler(data, actions))
231
+
232
+ try:
233
+ asyncio.get_event_loop().run_until_complete(hy_i_runner())
234
+ except KeyboardInterrupt:
235
+ logger.log("正在退出(Ctrl+C)", level=Logger.levels.WARNING)
236
+ sys.exit()
237
+
238
+
239
+ def stop() -> None:
240
+ try:
241
+ connection.close()
242
+ except:
243
+ pass
244
+ logger.log("停止运行监听器", level=Logger.levels.WARNING)
@@ -0,0 +1 @@
1
+ from Hyper.Adapters.OneBotLib.Manager import *