hyper-bot 0.78__tar.gz → 0.78.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 (24) hide show
  1. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Adapters/OneBot.py +28 -17
  2. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Adapters/OneBotLib/Manager.py +16 -14
  3. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Events.py +25 -3
  4. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Listener.py +1 -2
  5. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Utils/Logic.py +18 -1
  6. hyper-bot-0.78.2/Hyper/__init__.py +1 -0
  7. {hyper-bot-0.78 → hyper-bot-0.78.2}/PKG-INFO +1 -1
  8. {hyper-bot-0.78 → hyper-bot-0.78.2}/hyper_bot.egg-info/PKG-INFO +1 -1
  9. hyper-bot-0.78/Hyper/__init__.py +0 -1
  10. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Adapters/OneBotLib/Res.py +0 -0
  11. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Adapters/Satori.py +0 -0
  12. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Configurator.py +0 -0
  13. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Logger.py +0 -0
  14. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Manager.py +0 -0
  15. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Network.py +0 -0
  16. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Segments.py +0 -0
  17. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Utils/Errors.py +0 -0
  18. {hyper-bot-0.78 → hyper-bot-0.78.2}/Hyper/Utils/TypeExt.py +0 -0
  19. {hyper-bot-0.78 → hyper-bot-0.78.2}/LICENSE +0 -0
  20. {hyper-bot-0.78 → hyper-bot-0.78.2}/hyper_bot.egg-info/SOURCES.txt +0 -0
  21. {hyper-bot-0.78 → hyper-bot-0.78.2}/hyper_bot.egg-info/dependency_links.txt +0 -0
  22. {hyper-bot-0.78 → hyper-bot-0.78.2}/hyper_bot.egg-info/top_level.txt +0 -0
  23. {hyper-bot-0.78 → hyper-bot-0.78.2}/setup.cfg +0 -0
  24. {hyper-bot-0.78 → hyper-bot-0.78.2}/setup.py +0 -0
@@ -178,27 +178,31 @@ class Actions:
178
178
  return Manager.Ret.fetch(packet.echo)
179
179
 
180
180
 
181
- async def tester(message_data: Event, actions: Actions) -> None:
181
+ async def tester(message_data: Union[Event, HyperNotify], actions: Actions) -> None:
182
182
  ...
183
183
 
184
184
 
185
- def __handler(data: dict, actions: Actions) -> None:
186
- if data.get("echo") is not None:
187
- reports.put(data)
188
- elif data.get("post_type") == "meta_event" or data.get("user_id") == data.get("self_id"):
189
- pass
185
+ def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
186
+ if isinstance(data, dict):
187
+ if data.get("echo") is not None:
188
+ reports.put(data.get("echo"), data)
189
+ elif data.get("post_type") == "meta_event" or data.get("user_id") == data.get("self_id"):
190
+ pass
191
+ else:
192
+ # task = asyncio.create_task(handler(Events.em.new(data), actions))
193
+ asyncio.run(handler(Events.em.new(data), actions))
194
+ # await handler(Events.em.new(data), actions)
195
+ # timed = 0
196
+ #
197
+ # while not task.done():
198
+ # time.sleep(0.1)
199
+ # timed += 0.1
200
+ # if timed >= 30:
201
+ # task.cancel()
202
+ # logger.log(f"处理{task.get_name()}超时", level=Logger.levels.ERROR)
203
+ # break
190
204
  else:
191
- # task = asyncio.create_task(handler(Events.em.new(data), actions))
192
- asyncio.run(handler(Events.em.new(data), actions))
193
- # timed = 0
194
- #
195
- # while not task.done():
196
- # time.sleep(0.1)
197
- # timed += 0.1
198
- # if timed >= 30:
199
- # task.cancel()
200
- # logger.log(f"处理{task.get_name()}超时", level=Logger.levels.ERROR)
201
- # break
205
+ asyncio.run(handler(data, actions))
202
206
 
203
207
 
204
208
  handler: callable = tester
@@ -242,6 +246,12 @@ def run():
242
246
  logger.log("成功建立连接", level=Logger.levels.INFO)
243
247
  retried = 0
244
248
  actions = Actions(connection)
249
+ data = HyperListenerStartNotify(
250
+ time_now=int(time.time()),
251
+ notify_type="listener_start",
252
+ connection=connection
253
+ )
254
+ threading.Thread(target=lambda: __handler(data, actions)).start()
245
255
  while True:
246
256
  try:
247
257
  data = connection.recv()
@@ -253,6 +263,7 @@ def run():
253
263
  continue
254
264
  # threading.Thread(target=lambda: asyncio.run(__handler(data, actions))).start()
255
265
  threading.Thread(target=lambda: __handler(data, actions)).start()
266
+ # asyncio.create_task(__handler(data, actions))
256
267
  except KeyboardInterrupt:
257
268
  logger.log("正在退出(Ctrl+C)", level=Logger.levels.WARNING)
258
269
  try:
@@ -3,11 +3,12 @@ from Hyper import Configurator, Logger, Network, Segments
3
3
  from Hyper.Utils import Logic
4
4
 
5
5
  from typing import Union
6
- import queue
6
+ # import queue
7
7
  import random
8
8
  import json
9
9
 
10
- reports = queue.Queue()
10
+ # reports = queue.Queue()
11
+ reports = Logic.KeyQueue()
11
12
  config = Configurator.cm.get_cfg()
12
13
  logger = Logger.Logger()
13
14
  logger.set_level(config.log_level)
@@ -112,20 +113,21 @@ class Message:
112
113
 
113
114
 
114
115
  class Ret:
115
- def __init__(self, json_data: dict):
116
+ def __init__(self, json_data: dict, serializer):
116
117
  self.status = json_data["status"]
117
118
  self.ret_code = json_data["retcode"]
118
- self.data = Hyper.Utils.TypeExt.ObjectedJson(json_data.get("data"))
119
+ self.data = serializer(json_data.get("data"))
119
120
  self.echo = json_data.get("echo")
120
121
 
121
122
  @classmethod
122
- def fetch(cls, echo: str) -> "Ret":
123
- old = None
124
- while True:
125
- content = reports.get()
126
- if old is not None:
127
- reports.put(old)
128
- if content["echo"] == echo:
129
- return cls(content)
130
- else:
131
- old = content
123
+ def fetch(cls, echo: str, serializer=Hyper.Utils.TypeExt.ObjectedJson) -> "Ret":
124
+ # old = None
125
+ # while True:
126
+ # content = reports.get()
127
+ # if old is not None:
128
+ # reports.put(old)
129
+ # if content["echo"] == echo:
130
+ # return cls(content)
131
+ # else:
132
+ # old = content
133
+ return cls(reports.get(echo), serializer)
@@ -1,8 +1,11 @@
1
1
  from Hyper import Configurator, Logger, Manager
2
2
  from Hyper.Utils.TypeExt import Integer
3
3
  from Hyper.Segments import message_types, At
4
+ from Hyper.Network import WebsocketConnection, HTTPConnection
4
5
  from Hyper.Logger import levels
5
6
 
7
+ from typing import Union, Any
8
+
6
9
  config = Configurator.cm.get_cfg()
7
10
  logger = Logger.Logger()
8
11
  logger.set_level(config.log_level)
@@ -163,7 +166,8 @@ class GroupAdminEvent(NoticeEvent):
163
166
  self.print_log()
164
167
 
165
168
  def print_log(self) -> None:
166
- logger.log(f"用户 {self.user_id} 在群 {self.group_id} 被{'设置' if self.sub_type == 'set' else '取消'}管理员身份")
169
+ logger.log(
170
+ f"用户 {self.user_id} 在群 {self.group_id} 被{'设置' if self.sub_type == 'set' else '取消'}管理员身份")
167
171
 
168
172
 
169
173
  @em.reg("notice", "group_decrease")
@@ -203,7 +207,8 @@ class GroupMuteEvent(NoticeEvent):
203
207
  self.print_log()
204
208
 
205
209
  def print_log(self) -> None:
206
- logger.log(f"{self.user_id} 在群 {self.group_id} 被{'' if self.sub_type == 'ban' else '解除'}禁言, 时长为{self.duration}")
210
+ logger.log(
211
+ f"{self.user_id} 在群 {self.group_id} 被{'' if self.sub_type == 'ban' else '解除'}禁言, 时长为{self.duration}")
207
212
 
208
213
 
209
214
  @em.reg("notice", "friend_add")
@@ -264,7 +269,8 @@ class GroupEssenceEvent(NoticeEvent):
264
269
 
265
270
  def print_log(self) -> None:
266
271
  action = "设置" if self.sub_type == "add" else "移除"
267
- logger.log(f"{self.operator_id} 在群 {self.group_id} 中将 {self.sender_id} 的消息 {self.message_id} {action}精华")
272
+ logger.log(
273
+ f"{self.operator_id} 在群 {self.group_id} 中将 {self.sender_id} 的消息 {self.message_id} {action}精华")
268
274
 
269
275
 
270
276
  @em.reg("notice", "reaction")
@@ -298,4 +304,20 @@ class GroupAddInviteEvent(RequestEvent):
298
304
  self.sub_type = data.get("sub_type")
299
305
 
300
306
 
307
+ class HyperNotify:
308
+ def __init__(self, time_now: int, notify_type: str):
309
+ self.time = time_now
310
+ self.type = notify_type
311
+
312
+
313
+ class HyperListenerStartNotify(HyperNotify):
314
+ def __init__(self, time_now: int, notify_type: str, connection: Union[WebsocketConnection, HTTPConnection]):
315
+ super().__init__(time_now, notify_type)
316
+ self.connection = connection
317
+
318
+
319
+ class HyperListenerStopNotify(HyperNotify):
320
+ pass
321
+
322
+
301
323
 
@@ -1,7 +1,6 @@
1
1
  from Hyper import Configurator
2
2
 
3
3
  import sys
4
- import os
5
4
 
6
5
  config = Configurator.cm.get_cfg()
7
6
 
@@ -14,5 +13,5 @@ elif config.protocol == "Satori":
14
13
  def restart() -> None:
15
14
  stop()
16
15
  os.execv(sys.executable, ['python'] + sys.argv)
17
- os._exit(1)
16
+ # os._exit(1)
18
17
 
@@ -3,7 +3,7 @@ import os
3
3
  import shutil
4
4
  import traceback
5
5
  import asyncio
6
- from typing import Union
6
+ from typing import Union, Any
7
7
  import aiohttp
8
8
  import time
9
9
  import requests
@@ -331,3 +331,20 @@ class Downloader:
331
331
  for i in range(0, len(result)):
332
332
  r += result[str(i)]
333
333
  f.write(r)
334
+
335
+
336
+ class KeyQueue:
337
+ def __init__(self):
338
+ self.contents = {}
339
+
340
+ def put(self, key: str, obj: Any) -> None:
341
+ if key in list(self.contents.keys()):
342
+ return
343
+ self.contents[key] = obj
344
+
345
+ def get(self, key: str) -> Any:
346
+ while 1:
347
+ try:
348
+ return self.contents[key]
349
+ except KeyError:
350
+ pass
@@ -0,0 +1 @@
1
+ HYPER_BOT_VERSION = "0.78.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hyper-bot
3
- Version: 0.78
3
+ Version: 0.78.2
4
4
  Summary: 稳定高效、易于开发的QQ Bot框架
5
5
  Home-page: https://github.com/HarcicYang/HypeR_Bot
6
6
  Author: Harcic
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hyper-bot
3
- Version: 0.78
3
+ Version: 0.78.2
4
4
  Summary: 稳定高效、易于开发的QQ Bot框架
5
5
  Home-page: https://github.com/HarcicYang/HypeR_Bot
6
6
  Author: Harcic
@@ -1 +0,0 @@
1
- HYPER_BOT_VERSION = "0.78"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes