hyper-bot 0.81.2__tar.gz → 0.82.0__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 (59) hide show
  1. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/PKG-INFO +1 -5
  2. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyper_bot.egg-info/PKG-INFO +1 -5
  3. hyper_bot-0.82.0/hyper_bot.egg-info/SOURCES.txt +36 -0
  4. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyper_bot.egg-info/requires.txt +0 -4
  5. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyper_bot.egg-info/top_level.txt +0 -1
  6. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/LecAdapters/Milky.py +9 -9
  7. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/LecAdapters/MilkyLib/Manager.py +2 -2
  8. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/LecAdapters/MilkyLib/translator.py +6 -6
  9. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/LecAdapters/OneBot.py +44 -40
  10. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/LecAdapters/OneBotLib/Manager.py +3 -3
  11. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/__init__.py +16 -3
  12. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/adapters/listener.py +1 -1
  13. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/common.py +2 -2
  14. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/events.py +2 -2
  15. hyper_bot-0.82.0/hyperot/network.py +97 -0
  16. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/utils/logic.py +3 -2
  17. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/setup.py +1 -10
  18. hyper_bot-0.81.2/hyper_bot.egg-info/SOURCES.txt +0 -55
  19. hyper_bot-0.81.2/hyperot/LecAdapters/Kritor.py +0 -243
  20. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/Manager.py +0 -1
  21. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/Res.py +0 -484
  22. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/__init__.py +0 -0
  23. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/authentication/__init__.py +0 -264
  24. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/common/__init__.py +0 -412
  25. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/core/__init__.py +0 -210
  26. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/customization/__init__.py +0 -58
  27. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/developer/__init__.py +0 -435
  28. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/event/__init__.py +0 -412
  29. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/file/__init__.py +0 -368
  30. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/friend/__init__.py +0 -486
  31. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/group/__init__.py +0 -971
  32. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/guild/__init__.py +0 -804
  33. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/message/__init__.py +0 -686
  34. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/process/__init__.py +0 -168
  35. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/reverse/__init__.py +0 -68
  36. hyper_bot-0.81.2/hyperot/LecAdapters/KritorLib/protos/web/__init__.py +0 -200
  37. hyper_bot-0.81.2/hyperot/network.py +0 -178
  38. hyper_bot-0.81.2/hytil.py +0 -56
  39. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/LICENSE +0 -0
  40. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyper_bot.egg-info/dependency_links.txt +0 -0
  41. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/LecAdapters/MilkyLib/Res.py +0 -0
  42. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/LecAdapters/OneBotLib/Res.py +0 -0
  43. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/adapters/__init__.py +0 -0
  44. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/adapters/builtins.py +0 -0
  45. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/adapters/common.py +0 -0
  46. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/adapters/obuilder.py +0 -0
  47. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/adapters/res.py +0 -0
  48. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/configurator.py +0 -0
  49. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/hyperogger.py +0 -0
  50. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/listener.py +0 -0
  51. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/segments.py +0 -0
  52. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/service.py +0 -0
  53. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/utils/ArkSignHelper.py +0 -0
  54. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/utils/apiresponse.py +0 -0
  55. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/utils/errors.py +0 -0
  56. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/utils/hypetyping.py +0 -0
  57. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/utils/screens.py +0 -0
  58. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/hyperot/utils/typextensions.py +0 -0
  59. {hyper_bot-0.81.2 → hyper_bot-0.82.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hyper-bot
3
- Version: 0.81.2
3
+ Version: 0.82.0
4
4
  Summary: 稳定高效、易于开发的QQ Bot框架
5
5
  Home-page: https://github.com/HarcicYang/HypeR_Bot
6
6
  Author: Harcic
@@ -10,11 +10,7 @@ License-File: LICENSE
10
10
  Requires-Dist: aiohttp~=3.9.5
11
11
  Requires-Dist: requests~=2.31.0
12
12
  Requires-Dist: httpx~=0.26.0
13
- Requires-Dist: grpclib~=0.4.7
14
- Requires-Dist: betterproto~=2.0.0b7
15
13
  Requires-Dist: websocket-client~=1.8.0
16
14
  Requires-Dist: Flask~=3.0.0
17
- Requires-Dist: google~=3.0.0
18
- Requires-Dist: protobuf~=4.25.3
19
15
  Requires-Dist: ucfgr
20
16
  Requires-Dist: PyYAML
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hyper-bot
3
- Version: 0.81.2
3
+ Version: 0.82.0
4
4
  Summary: 稳定高效、易于开发的QQ Bot框架
5
5
  Home-page: https://github.com/HarcicYang/HypeR_Bot
6
6
  Author: Harcic
@@ -10,11 +10,7 @@ License-File: LICENSE
10
10
  Requires-Dist: aiohttp~=3.9.5
11
11
  Requires-Dist: requests~=2.31.0
12
12
  Requires-Dist: httpx~=0.26.0
13
- Requires-Dist: grpclib~=0.4.7
14
- Requires-Dist: betterproto~=2.0.0b7
15
13
  Requires-Dist: websocket-client~=1.8.0
16
14
  Requires-Dist: Flask~=3.0.0
17
- Requires-Dist: google~=3.0.0
18
- Requires-Dist: protobuf~=4.25.3
19
15
  Requires-Dist: ucfgr
20
16
  Requires-Dist: PyYAML
@@ -0,0 +1,36 @@
1
+ LICENSE
2
+ setup.py
3
+ hyper_bot.egg-info/PKG-INFO
4
+ hyper_bot.egg-info/SOURCES.txt
5
+ hyper_bot.egg-info/dependency_links.txt
6
+ hyper_bot.egg-info/requires.txt
7
+ hyper_bot.egg-info/top_level.txt
8
+ hyperot/__init__.py
9
+ hyperot/common.py
10
+ hyperot/configurator.py
11
+ hyperot/events.py
12
+ hyperot/hyperogger.py
13
+ hyperot/listener.py
14
+ hyperot/network.py
15
+ hyperot/segments.py
16
+ hyperot/service.py
17
+ hyperot/LecAdapters/Milky.py
18
+ hyperot/LecAdapters/OneBot.py
19
+ hyperot/LecAdapters/MilkyLib/Manager.py
20
+ hyperot/LecAdapters/MilkyLib/Res.py
21
+ hyperot/LecAdapters/MilkyLib/translator.py
22
+ hyperot/LecAdapters/OneBotLib/Manager.py
23
+ hyperot/LecAdapters/OneBotLib/Res.py
24
+ hyperot/adapters/__init__.py
25
+ hyperot/adapters/builtins.py
26
+ hyperot/adapters/common.py
27
+ hyperot/adapters/listener.py
28
+ hyperot/adapters/obuilder.py
29
+ hyperot/adapters/res.py
30
+ hyperot/utils/ArkSignHelper.py
31
+ hyperot/utils/apiresponse.py
32
+ hyperot/utils/errors.py
33
+ hyperot/utils/hypetyping.py
34
+ hyperot/utils/logic.py
35
+ hyperot/utils/screens.py
36
+ hyperot/utils/typextensions.py
@@ -1,11 +1,7 @@
1
1
  aiohttp~=3.9.5
2
2
  requests~=2.31.0
3
3
  httpx~=0.26.0
4
- grpclib~=0.4.7
5
- betterproto~=2.0.0b7
6
4
  websocket-client~=1.8.0
7
5
  Flask~=3.0.0
8
- google~=3.0.0
9
- protobuf~=4.25.3
10
6
  ucfgr
11
7
  PyYAML
@@ -33,7 +33,7 @@ class Actions:
33
33
  str(item),
34
34
  **kwargs
35
35
  )
36
- packet.send_to(self.connection)
36
+ await packet.send_to(self.connection)
37
37
  return packet.echo
38
38
 
39
39
  return wrapper
@@ -44,7 +44,7 @@ class Actions:
44
44
  self, message: Union[common.Message, str], group_id: int = None, user_id: int = None
45
45
  ) -> common.Ret[MsgSendRsp]:
46
46
  if group_id is None:
47
- res = Packet(
47
+ res = await Packet(
48
48
  "send_private_msg",
49
49
  user_id=user_id,
50
50
  message=to_milky_message(common.Message(message))
@@ -55,7 +55,7 @@ class Actions:
55
55
  ret.data = MsgSendRsp({"message_id": msg_enid(0, res["message_seq"], user_id)})
56
56
  return ret
57
57
  else:
58
- res = Packet(
58
+ res = await Packet(
59
59
  "send_group_msg",
60
60
  group_id=group_id,
61
61
  message=to_milky_message(common.Message(message))
@@ -128,11 +128,11 @@ async def tester(
128
128
  ...
129
129
 
130
130
 
131
- def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
131
+ async def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
132
132
  if isinstance(data, dict):
133
- asyncio.run(handler(events.em.new(data), actions))
133
+ await handler(events.em.new(data), actions)
134
134
  else:
135
- asyncio.run(handler(data, actions))
135
+ await handler(data, actions)
136
136
 
137
137
 
138
138
  handler: callable = tester
@@ -146,7 +146,7 @@ def reg(func: callable) -> None:
146
146
  connection: MilkyHttpConnection
147
147
 
148
148
 
149
- def run() -> NoReturn:
149
+ async def run() -> NoReturn:
150
150
  global connection, listener_ran
151
151
  listener_ran = True
152
152
  try:
@@ -181,7 +181,7 @@ def run() -> NoReturn:
181
181
  notify_type="listener_start",
182
182
  connection=connection
183
183
  )
184
- threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
184
+ asyncio.create_task(__handler(data, actions))
185
185
  while True:
186
186
  try:
187
187
  data = connection.recv()
@@ -191,7 +191,7 @@ def run() -> NoReturn:
191
191
  except json.decoder.JSONDecodeError:
192
192
  logger.error("收到错误的JSON内容")
193
193
  continue
194
- threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
194
+ asyncio.create_task(__handler(data, actions))
195
195
  except KeyboardInterrupt:
196
196
  logger.warning("正在退出(Ctrl+C)")
197
197
  try:
@@ -6,8 +6,8 @@ class Packet:
6
6
  self.endpoint = endpoint
7
7
  self.paras = kwargs
8
8
 
9
- def send_to(self, connection: MilkyHttpConnection) -> dict:
9
+ async def send_to(self, connection: MilkyHttpConnection) -> dict:
10
10
  if isinstance(connection, MilkyHttpConnection):
11
- return connection.http_send(self.endpoint, self.paras)
11
+ return await connection.http_send(self.endpoint, self.paras)
12
12
  else:
13
13
  raise ValueError(f"Invalid connection: {connection}")
@@ -1,7 +1,7 @@
1
1
  import httpx
2
2
  import json
3
3
 
4
- from hyperot.network import WebsocketConnection
4
+ from hyperot.network import WebsocketConnection, httpx_post, httpx_get
5
5
  from ...common import Message
6
6
  from ...utils.logic import Matcher
7
7
  from ...adapters.obuilder import OneBotEventBuilder, OneBotJsonMessageBuilder
@@ -64,8 +64,8 @@ class MilkyHttpConnection(WebsocketConnection):
64
64
  else:
65
65
  self.ws.connect(self.url + "/event")
66
66
 
67
- def recv(self) -> dict:
68
- milky_rp = json.loads(self.ws.recv())
67
+ async def recv(self) -> dict:
68
+ milky_rp = json.loads(await self.ws.recv())
69
69
  milky_event_type = milky_rp["type"]
70
70
  milky_time = milky_rp["time"]
71
71
  milky_self_id = milky_rp["self_id"]
@@ -109,14 +109,14 @@ class MilkyHttpConnection(WebsocketConnection):
109
109
 
110
110
  return milky_rp
111
111
 
112
- def http_send(self, endpoint: str, data: dict) -> dict:
112
+ async def http_send(self, endpoint: str, data: dict) -> dict:
113
113
  if not data:
114
114
  data = dict()
115
115
  if self.auth:
116
- response = httpx.post(f"{self.url}/api/{endpoint}", json=data,
116
+ response = await httpx_post(f"{self.url}/api/{endpoint}", json=data,
117
117
  headers={"Authorization": f"Bearer {self.auth}"})
118
118
  else:
119
- response = httpx.post(f"{self.url}/api/{endpoint}", json=data)
119
+ response = await httpx_post(f"{self.url}/api/{endpoint}", json=data)
120
120
  res = response.json()
121
121
  return res
122
122
 
@@ -33,7 +33,7 @@ class Actions:
33
33
  str(item),
34
34
  **kwargs
35
35
  )
36
- packet.send_to(self.connection)
36
+ await packet.send_to(self.connection)
37
37
  return packet.echo
38
38
 
39
39
  return wrapper
@@ -59,19 +59,19 @@ class Actions:
59
59
  )
60
60
  else:
61
61
  raise errors.ArgsInvalidError("'send' API requires 'group_id' or 'user_id' but none of them are provided.")
62
- packet.send_to(self.connection)
62
+ await packet.send_to(self.connection)
63
63
  logger.info(f"向{(('群 ' + str(group_id)) if group_id else ('用户' + str(user_id))) + ' '}发送:{str(message)}")
64
- return common.Ret.fetch(packet.echo, MsgSendRsp)
64
+ return await common.Ret.fetch(packet.echo, MsgSendRsp)
65
65
 
66
66
  async def del_message(self, message_id: int) -> None:
67
- Packet(
67
+ await Packet(
68
68
  "delete_msg",
69
69
  message_id=message_id,
70
70
  ).send_to(self.connection)
71
71
  logger.info(f"撤回 {message_id}")
72
72
 
73
73
  async def set_group_kick(self, group_id: int, user_id: int) -> None:
74
- Packet(
74
+ await Packet(
75
75
  "set_group_kick",
76
76
  group_id=group_id,
77
77
  user_id=user_id,
@@ -79,7 +79,7 @@ class Actions:
79
79
  logger.info(f"将用户 {user_id} 移出群 {group_id}")
80
80
 
81
81
  async def set_group_ban(self, group_id: int, user_id: int, duration: int = 60) -> None:
82
- Packet(
82
+ await Packet(
83
83
  "set_group_ban",
84
84
  group_id=group_id,
85
85
  user_id=user_id,
@@ -89,29 +89,29 @@ class Actions:
89
89
 
90
90
  async def get_login_info(self) -> common.Ret[GetLoginInfoRsp]:
91
91
  packet = Packet("get_login_info")
92
- packet.send_to(self.connection)
93
- return common.Ret.fetch(packet.echo, GetLoginInfoRsp)
92
+ await packet.send_to(self.connection)
93
+ return await common.Ret.fetch(packet.echo, GetLoginInfoRsp)
94
94
 
95
95
  async def get_version_info(self) -> common.Ret[GetVerInfoRsp]:
96
96
  packet = Packet("get_version_info")
97
- packet.send_to(self.connection)
98
- return common.Ret.fetch(packet.echo, GetVerInfoRsp)
97
+ await packet.send_to(self.connection)
98
+ return await common.Ret.fetch(packet.echo, GetVerInfoRsp)
99
99
 
100
100
  async def send_forward_msg(self, message: common.Message) -> common.Ret[SendForwardRsp]:
101
101
  packet = Packet(
102
102
  "send_forward_msg",
103
103
  messages=await message.get()
104
104
  )
105
- packet.send_to(self.connection)
106
- return common.Ret.fetch(packet.echo, SendForwardRsp)
105
+ await packet.send_to(self.connection)
106
+ return await common.Ret.fetch(packet.echo, SendForwardRsp)
107
107
 
108
108
  async def get_forward_msg(self, sid: str) -> common.Ret[common.Message]:
109
109
  packet = Packet(
110
110
  "get_forward_msg",
111
111
  id=sid,
112
112
  )
113
- packet.send_to(self.connection)
114
- ret = common.Ret.fetch(packet.echo, events.gen_message)
113
+ await packet.send_to(self.connection)
114
+ ret = await common.Ret.fetch(packet.echo, events.gen_message)
115
115
  for i in ret.data:
116
116
  if isinstance(i, segments.Node):
117
117
  i.content = gen_message({"message": i.content})
@@ -131,12 +131,12 @@ class Actions:
131
131
  group_id=group_id,
132
132
  messages=await message.get()
133
133
  )
134
- packet.send_to(self.connection)
135
- return common.Ret.fetch(packet.echo, SendForwardRsp)
134
+ await packet.send_to(self.connection)
135
+ return await common.Ret.fetch(packet.echo, SendForwardRsp)
136
136
 
137
137
  async def set_group_add_request(self, flag: str, sub_type: str, approve: bool,
138
138
  reason: str = "Not Mentioned") -> None:
139
- Packet(
139
+ await Packet(
140
140
  "set_group_add_request",
141
141
  flag=flag,
142
142
  sub_type=sub_type,
@@ -151,8 +151,8 @@ class Actions:
151
151
  user_id=user_id,
152
152
  no_cache=True,
153
153
  )
154
- packet.send_to(self.connection)
155
- return common.Ret.fetch(packet.echo, GetStrInfoRsp)
154
+ await packet.send_to(self.connection)
155
+ return await common.Ret.fetch(packet.echo, GetStrInfoRsp)
156
156
 
157
157
  async def get_group_member_info(self, group_id: int, user_id: int) -> common.Ret[GetGrpMemInfoRsp]:
158
158
  packet = Packet(
@@ -161,8 +161,8 @@ class Actions:
161
161
  user_id=user_id,
162
162
  no_cache=True
163
163
  )
164
- packet.send_to(self.connection)
165
- return common.Ret.fetch(packet.echo, GetGrpMemInfoRsp)
164
+ await packet.send_to(self.connection)
165
+ return await common.Ret.fetch(packet.echo, GetGrpMemInfoRsp)
166
166
 
167
167
  async def get_group_info(self, group_id: int) -> common.Ret[GetGrpInfoRsp]:
168
168
  packet = Packet(
@@ -170,22 +170,22 @@ class Actions:
170
170
  group_id=group_id,
171
171
  no_cache=True
172
172
  )
173
- packet.send_to(self.connection)
174
- return common.Ret.fetch(packet.echo, GetGrpInfoRsp)
173
+ await packet.send_to(self.connection)
174
+ return await common.Ret.fetch(packet.echo, GetGrpInfoRsp)
175
175
 
176
176
  async def get_status(self) -> common.Ret:
177
177
  packet = Packet("get_status")
178
- packet.send_to(self.connection)
179
- return common.Ret.fetch(packet.echo)
178
+ await packet.send_to(self.connection)
179
+ return await common.Ret.fetch(packet.echo)
180
180
 
181
181
  async def set_essence_msg(self, message_id: int) -> None:
182
- Packet(
182
+ await Packet(
183
183
  "set_essence_msg",
184
184
  message_id=message_id
185
185
  ).send_to(self.connection)
186
186
 
187
187
  async def set_group_special_title(self, group_id: int, user_id: int, title: str) -> None:
188
- Packet(
188
+ await Packet(
189
189
  "set_group_special_title",
190
190
  group_id=group_id,
191
191
  user_id=user_id,
@@ -197,11 +197,11 @@ class Actions:
197
197
  "get_msg",
198
198
  message_id=msg_id
199
199
  )
200
- packet.send_to(self.connection)
201
- return common.Ret.fetch(packet.echo, GetMsgRsp)
200
+ await packet.send_to(self.connection)
201
+ return await common.Ret.fetch(packet.echo, GetMsgRsp)
202
202
 
203
203
  async def send_callback(self, group_id: int, bot_id: int, data: dict) -> None:
204
- Packet(
204
+ await Packet(
205
205
  "send_group_bot_callback",
206
206
  group_id=group_id,
207
207
  bot_id=bot_id,
@@ -215,16 +215,16 @@ async def tester(
215
215
  ...
216
216
 
217
217
 
218
- def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
218
+ async def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
219
219
  if isinstance(data, dict):
220
220
  if data.get("echo") is not None:
221
- reports.put(data.get("echo"), data)
221
+ await reports.put(data.get("echo"), data)
222
222
  elif data.get("post_type") == "meta_event" or data.get("user_id") == data.get("self_id"):
223
223
  pass
224
224
  else:
225
- asyncio.run(handler(events.em.new(data), actions))
225
+ await handler(events.em.new(data), actions)
226
226
  else:
227
- asyncio.run(handler(data, actions))
227
+ await handler(data, actions)
228
228
 
229
229
 
230
230
  handler: callable = tester
@@ -254,7 +254,7 @@ class LagrangeOneBotService(IServiceBase):
254
254
  print(i.decode(), end="")
255
255
 
256
256
 
257
- def run() -> NoReturn:
257
+ async def run() -> NoReturn:
258
258
  global connection, listener_ran
259
259
  listener_ran = True
260
260
  try:
@@ -291,21 +291,25 @@ def run() -> NoReturn:
291
291
  notify_type="listener_start",
292
292
  connection=connection
293
293
  )
294
- threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
294
+ # threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
295
+
296
+ asyncio.create_task(__handler(data, actions))
295
297
  while True:
296
298
  try:
297
- data = connection.recv()
299
+ data = await connection.recv()
298
300
  except ConnectionResetError:
299
301
  logger.error("连接断开")
300
302
  break
301
303
  except json.decoder.JSONDecodeError:
302
304
  logger.error("收到错误的JSON内容")
303
305
  continue
304
- threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
305
- except KeyboardInterrupt:
306
+ # threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
307
+ logger.trace(str(data))
308
+ asyncio.create_task(__handler(data, actions))
309
+ except asyncio.CancelledError:
306
310
  logger.warning("正在退出(Ctrl+C)")
307
311
  try:
308
- connection.close()
312
+ await connection.close()
309
313
  except:
310
314
  pass
311
315
  sys.exit()
@@ -28,18 +28,18 @@ class Packet:
28
28
  self.paras = kwargs
29
29
  self.echo = f"{endpoint}_{random.randint(1000, 9999)}"
30
30
 
31
- def send_to(self, connection: Union[network.WebsocketConnection, network.HTTPConnection]) -> None:
31
+ async def send_to(self, connection: Union[network.WebsocketConnection, network.HTTPConnection]) -> None:
32
32
  if isinstance(connection, network.WebsocketConnection):
33
33
  payload: OneBotJsonPacket = {
34
34
  "action": self.endpoint,
35
35
  "params": self.paras,
36
36
  "echo": self.echo,
37
37
  }
38
- connection.send(json.dumps(payload))
38
+ await connection.send(json.dumps(payload))
39
39
 
40
40
  elif isinstance(connection, network.HTTPConnection):
41
41
  payload = self.paras
42
- connection.send(self.endpoint, payload, self.echo)
42
+ await connection.send(self.endpoint, payload, self.echo)
43
43
 
44
44
 
45
45
 
@@ -1,3 +1,6 @@
1
+ import signal
2
+ from asyncio import tasks
3
+
1
4
  from . import configurator
2
5
  from .utils import screens
3
6
 
@@ -6,7 +9,7 @@ import asyncio
6
9
  import sys
7
10
  import os
8
11
 
9
- HYPER_BOT_VERSION = "0.81.2"
12
+ HYPER_BOT_VERSION = "0.82.0"
10
13
 
11
14
  # listener = None
12
15
 
@@ -57,12 +60,22 @@ class Client:
57
60
  else:
58
61
  return
59
62
 
60
- def run(self):
63
+ async def run(self):
61
64
  from . import listener
62
65
  self.lis = listener
63
66
  self.lis.reg(self.distributor)
64
67
  if self.records:
65
- self.lis.run()
68
+ stop = asyncio.Event()
69
+ loop = asyncio.get_running_loop()
70
+ for i in (signal.SIGINT, signal.SIGTERM):
71
+ loop.add_signal_handler(i, stop.set)
72
+ task = asyncio.create_task(self.lis.run())
73
+ await stop.wait()
74
+ task.cancel()
75
+ try:
76
+ await task
77
+ except asyncio.CancelledError:
78
+ pass
66
79
 
67
80
  def restart(self) -> None:
68
81
  self.lis.stop()
@@ -77,7 +77,7 @@ def reg(func: Callable) -> None:
77
77
  ...
78
78
 
79
79
 
80
- def run() -> NoReturn:
80
+ async def run() -> NoReturn:
81
81
  logger.error("你没有设置适配器!")
82
82
 
83
83
 
@@ -98,5 +98,5 @@ class Ret(Generic[T]):
98
98
  self.echo = json_data.get("echo")
99
99
 
100
100
  @classmethod
101
- def fetch(cls, echo: str, serializer=ObjectedJson) -> Self:
102
- return cls(reports.get(echo), serializer)
101
+ async def fetch(cls, echo: str, serializer=ObjectedJson) -> Self:
102
+ return cls(await reports.get(echo), serializer)
@@ -1,7 +1,7 @@
1
1
  from . import configurator, hyperogger, common
2
2
  from .utils.typextensions import Integer
3
3
  from .segments import message_types, At
4
- from .network import KritorConnection, WebsocketConnection, HTTPConnection
4
+ from .network import WebsocketConnection, HTTPConnection
5
5
  from .hyperogger import levels
6
6
 
7
7
  from abc import ABC
@@ -336,7 +336,7 @@ class HyperNotify:
336
336
 
337
337
  class HyperListenerStartNotify(HyperNotify):
338
338
  def __init__(self, time_now: int, notify_type: str,
339
- connection: Union[WebsocketConnection, HTTPConnection, KritorConnection] = None):
339
+ connection: Union[WebsocketConnection, HTTPConnection] = None):
340
340
  super().__init__(time_now, notify_type)
341
341
  self.connection = connection
342
342
 
@@ -0,0 +1,97 @@
1
+ import asyncio
2
+ import websocket
3
+ import httpx
4
+ import queue
5
+ import flask
6
+ import traceback
7
+ import json
8
+ import logging
9
+ import threading
10
+
11
+
12
+ async def httpx_get(url: str, headers: dict = None) -> httpx.Response:
13
+ async with httpx.AsyncClient(headers=headers) as client:
14
+ return await client.get(url)
15
+
16
+ async def httpx_post(url: str, json: dict, headers: dict = None) -> httpx.Response:
17
+ async with httpx.AsyncClient(headers=headers) as client:
18
+ return await client.post(url, json=json)
19
+
20
+
21
+ class WebsocketConnection:
22
+ def __init__(self, url: str, auth: str = None):
23
+ self.ws = websocket.WebSocket()
24
+ self.url = url
25
+ self.auth = auth
26
+
27
+ def connect(self) -> None:
28
+ if self.auth:
29
+ self.ws.connect(self.url, header={"Authorization": "Bearer " + self.auth})
30
+ else:
31
+ self.ws.connect(self.url)
32
+
33
+ async def send(self, message: str) -> None:
34
+ await asyncio.to_thread(lambda: self.ws.send(message))
35
+
36
+ async def close(self) -> None:
37
+ await asyncio.to_thread(lambda: self.ws.close())
38
+
39
+ async def recv(self) -> dict:
40
+ return json.loads(await asyncio.to_thread(self.ws.recv))
41
+
42
+
43
+ class HTTPConnection:
44
+ def __init__(self, url: str, listener_url: str, listener_endpoint: str = "/", auth: str = None):
45
+ self.url = url
46
+ listener_url = listener_url.replace("http://", "")
47
+ listener_url = listener_url.replace("https://", "")
48
+ self.listener_url = listener_url.split(":")[0]
49
+ self.listener_endpoint = listener_endpoint
50
+ try:
51
+ self.port = int(listener_url.split(":")[1])
52
+ except IndexError:
53
+ self.port = 8080
54
+ self.app = flask.Flask(__name__)
55
+ self.app.config["LOGGER_HANDLER_POLICY"] = "never"
56
+ logging.getLogger("werkzeug").setLevel(logging.ERROR)
57
+ self.reports = queue.Queue()
58
+ self.auth = auth
59
+
60
+ self.listener_started = False
61
+
62
+ def __start_listener(self) -> None:
63
+ @self.app.route(self.listener_endpoint, methods=["POST"])
64
+ def listener():
65
+ self.reports.put(flask.request.json)
66
+ return {}
67
+
68
+ # self.app.run(host=self.listener_url, port=self.port)
69
+
70
+ threading.Thread(target=lambda: self.app.run(host=self.listener_url, port=self.port)).start()
71
+ self.listener_started = True
72
+
73
+ async def connect(self) -> None:
74
+ if not self.listener_started:
75
+ self.__start_listener()
76
+ await httpx_post(self.url, {})
77
+ traceback.print_exc()
78
+
79
+ async def recv(self) -> dict:
80
+ return self.reports.get()
81
+
82
+ async def send(self, endpoint: str, data: dict, echo: str) -> None:
83
+ if self.auth:
84
+ response = await httpx_post(f"{self.url}/{endpoint}", json=data, headers={"Authorization": f"Bearer {self.auth}"})
85
+ else:
86
+ response = await httpx_post(f"{self.url}/{endpoint}", json=data)
87
+ res = response.json()
88
+ res["echo"] = echo
89
+ self.reports.put(res)
90
+
91
+ @staticmethod
92
+ def close() -> None:
93
+ shutdown_func = flask.request.environ.get('werkzeug.server.shutdown')
94
+ if shutdown_func is None:
95
+ raise RuntimeError('Not running with the Werkzeug Server')
96
+ shutdown_func()
97
+
@@ -283,16 +283,17 @@ class KeyQueue:
283
283
  def __init__(self):
284
284
  self.contents = {}
285
285
 
286
- def put(self, key: str, obj: Any) -> None:
286
+ async def put(self, key: str, obj: Any) -> None:
287
287
  if key in list(self.contents.keys()):
288
288
  return
289
289
  self.contents[key] = obj
290
290
 
291
- def get(self, key: str) -> Any:
291
+ async def get(self, key: str) -> Any:
292
292
  while 1:
293
293
  try:
294
294
  return self.contents[key]
295
295
  except KeyError:
296
+ await asyncio.sleep(0.01)
296
297
  pass
297
298
 
298
299