hyper-bot 0.78.7__tar.gz → 0.79.5__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.
- hyper_bot-0.79.5/Hyper/Adapters/Kritor.py +244 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/Manager.py +1 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/Res.py +484 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/__init__.py +0 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/authentication/__init__.py +264 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/common/__init__.py +412 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/core/__init__.py +210 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/customization/__init__.py +58 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/developer/__init__.py +435 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/event/__init__.py +412 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/file/__init__.py +368 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/friend/__init__.py +486 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/group/__init__.py +971 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/guild/__init__.py +804 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/message/__init__.py +686 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/process/__init__.py +168 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/reverse/__init__.py +68 -0
- hyper_bot-0.79.5/Hyper/Adapters/KritorLib/protos/web/__init__.py +200 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Adapters/LagrangePy.py +17 -13
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Adapters/OneBot.py +84 -61
- hyper_bot-0.79.5/Hyper/Adapters/OneBotLib/Manager.py +46 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Adapters/OneBotLib/Res.py +6 -6
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Adapters/Satori.py +1 -1
- hyper-bot-0.78.7/Hyper/Adapters/OneBotLib/Manager.py → hyper_bot-0.79.5/Hyper/Comm.py +20 -51
- hyper_bot-0.79.5/Hyper/Configurator.py +49 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Events.py +17 -5
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Listener.py +7 -9
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Logger.py +62 -10
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Segments.py +2 -2
- hyper_bot-0.79.5/Hyper/Service.py +51 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Utils/APIRsp.py +1 -1
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Utils/ArkSignHelper.py +1 -1
- hyper_bot-0.79.5/Hyper/Utils/HyperTyping.py +15 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Utils/Logic.py +36 -2
- hyper_bot-0.79.5/Hyper/Utils/Screens.py +50 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/__init__.py +14 -7
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/PKG-INFO +1 -1
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/hyper_bot.egg-info/PKG-INFO +1 -1
- hyper_bot-0.79.5/hyper_bot.egg-info/SOURCES.txt +45 -0
- hyper_bot-0.79.5/setup.py +26 -0
- hyper-bot-0.78.7/Hyper/Adapters/Kritor.py +0 -114
- hyper-bot-0.78.7/Hyper/Configurator.py +0 -126
- hyper-bot-0.78.7/Hyper/Manager.py +0 -14
- hyper-bot-0.78.7/Hyper/Utils/Screens.py +0 -72
- hyper-bot-0.78.7/hyper_bot.egg-info/SOURCES.txt +0 -26
- hyper-bot-0.78.7/setup.py +0 -16
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Network.py +0 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Utils/Errors.py +0 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/Hyper/Utils/TypeExt.py +0 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/LICENSE +0 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/hyper_bot.egg-info/dependency_links.txt +0 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/hyper_bot.egg-info/top_level.txt +0 -0
- {hyper-bot-0.78.7 → hyper_bot-0.79.5}/setup.cfg +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import Any, 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 *
|