hyper-bot 0.82.3__tar.gz → 0.82.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.82.5/PKG-INFO +17 -0
- hyper_bot-0.82.5/pyproject.toml +27 -0
- hyper_bot-0.82.5/src/hyper_bot.egg-info/PKG-INFO +17 -0
- hyper_bot-0.82.5/src/hyper_bot.egg-info/SOURCES.txt +35 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyper_bot.egg-info/dependency_links.txt +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyper_bot.egg-info/requires.txt +3 -2
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyper_bot.egg-info/top_level.txt +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/LecAdapters/MilkyLib/translator.py +0 -1
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/LecAdapters/OneBot.py +14 -38
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/LecAdapters/OneBotLib/Manager.py +2 -3
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/__init__.py +32 -23
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/adapters/__init__.py +4 -4
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/adapters/common.py +2 -1
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/adapters/listener.py +2 -2
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/common.py +2 -2
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/configurator.py +18 -7
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/events.py +42 -9
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/hyperogger.py +8 -3
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/network.py +5 -4
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/segments.py +45 -10
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/utils/ArkSignHelper.py +12 -15
- hyper_bot-0.82.5/src/hyperot/utils/__init__.py +22 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/utils/apiresponse.py +13 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/utils/errors.py +8 -5
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/utils/hypetyping.py +1 -1
- hyper_bot-0.82.5/src/hyperot/utils/typextensions.py +49 -0
- hyper_bot-0.82.3/PKG-INFO +0 -16
- hyper_bot-0.82.3/hyper_bot.egg-info/PKG-INFO +0 -16
- hyper_bot-0.82.3/hyper_bot.egg-info/SOURCES.txt +0 -36
- hyper_bot-0.82.3/hyperot/service.py +0 -51
- hyper_bot-0.82.3/hyperot/utils/logic.py +0 -320
- hyper_bot-0.82.3/hyperot/utils/typextensions.py +0 -172
- hyper_bot-0.82.3/setup.py +0 -32
- {hyper_bot-0.82.3 → hyper_bot-0.82.5}/LICENSE +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5}/setup.cfg +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/LecAdapters/Milky.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/LecAdapters/MilkyLib/Manager.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/LecAdapters/MilkyLib/Res.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/LecAdapters/OneBotLib/Res.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/adapters/builtins.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/adapters/obuilder.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/adapters/res.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/listener.py +0 -0
- {hyper_bot-0.82.3 → hyper_bot-0.82.5/src}/hyperot/utils/screens.py +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyper-bot
|
|
3
|
+
Version: 0.82.5
|
|
4
|
+
Summary: 稳定高效、易于开发的QQ Bot框架
|
|
5
|
+
Author-email: Harcic <harcic@outlook.com>
|
|
6
|
+
Project-URL: repository, https://github.com/HarcicYang/HypeR_Bot
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: setuptools
|
|
10
|
+
Requires-Dist: aiohttp~=3.9.5
|
|
11
|
+
Requires-Dist: requests~=2.31.0
|
|
12
|
+
Requires-Dist: httpx~=0.26.0
|
|
13
|
+
Requires-Dist: websockets
|
|
14
|
+
Requires-Dist: Flask~=3.0.0
|
|
15
|
+
Requires-Dist: ucfgr>=0.0.5
|
|
16
|
+
Requires-Dist: PyYAML
|
|
17
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hyper-bot"
|
|
7
|
+
version = "0.82.5"
|
|
8
|
+
description = "稳定高效、易于开发的QQ Bot框架"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Harcic", email = "harcic@outlook.com" },
|
|
11
|
+
]
|
|
12
|
+
urls = { repository = "https://github.com/HarcicYang/HypeR_Bot" }
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"setuptools",
|
|
16
|
+
"aiohttp~=3.9.5",
|
|
17
|
+
"requests~=2.31.0",
|
|
18
|
+
"httpx~=0.26.0",
|
|
19
|
+
"websockets",
|
|
20
|
+
"Flask~=3.0.0",
|
|
21
|
+
"ucfgr>=0.0.5",
|
|
22
|
+
"PyYAML",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
include = ["hyperot*"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyper-bot
|
|
3
|
+
Version: 0.82.5
|
|
4
|
+
Summary: 稳定高效、易于开发的QQ Bot框架
|
|
5
|
+
Author-email: Harcic <harcic@outlook.com>
|
|
6
|
+
Project-URL: repository, https://github.com/HarcicYang/HypeR_Bot
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: setuptools
|
|
10
|
+
Requires-Dist: aiohttp~=3.9.5
|
|
11
|
+
Requires-Dist: requests~=2.31.0
|
|
12
|
+
Requires-Dist: httpx~=0.26.0
|
|
13
|
+
Requires-Dist: websockets
|
|
14
|
+
Requires-Dist: Flask~=3.0.0
|
|
15
|
+
Requires-Dist: ucfgr>=0.0.5
|
|
16
|
+
Requires-Dist: PyYAML
|
|
17
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/hyper_bot.egg-info/PKG-INFO
|
|
4
|
+
src/hyper_bot.egg-info/SOURCES.txt
|
|
5
|
+
src/hyper_bot.egg-info/dependency_links.txt
|
|
6
|
+
src/hyper_bot.egg-info/requires.txt
|
|
7
|
+
src/hyper_bot.egg-info/top_level.txt
|
|
8
|
+
src/hyperot/__init__.py
|
|
9
|
+
src/hyperot/common.py
|
|
10
|
+
src/hyperot/configurator.py
|
|
11
|
+
src/hyperot/events.py
|
|
12
|
+
src/hyperot/hyperogger.py
|
|
13
|
+
src/hyperot/listener.py
|
|
14
|
+
src/hyperot/network.py
|
|
15
|
+
src/hyperot/segments.py
|
|
16
|
+
src/hyperot/LecAdapters/Milky.py
|
|
17
|
+
src/hyperot/LecAdapters/OneBot.py
|
|
18
|
+
src/hyperot/LecAdapters/MilkyLib/Manager.py
|
|
19
|
+
src/hyperot/LecAdapters/MilkyLib/Res.py
|
|
20
|
+
src/hyperot/LecAdapters/MilkyLib/translator.py
|
|
21
|
+
src/hyperot/LecAdapters/OneBotLib/Manager.py
|
|
22
|
+
src/hyperot/LecAdapters/OneBotLib/Res.py
|
|
23
|
+
src/hyperot/adapters/__init__.py
|
|
24
|
+
src/hyperot/adapters/builtins.py
|
|
25
|
+
src/hyperot/adapters/common.py
|
|
26
|
+
src/hyperot/adapters/listener.py
|
|
27
|
+
src/hyperot/adapters/obuilder.py
|
|
28
|
+
src/hyperot/adapters/res.py
|
|
29
|
+
src/hyperot/utils/ArkSignHelper.py
|
|
30
|
+
src/hyperot/utils/__init__.py
|
|
31
|
+
src/hyperot/utils/apiresponse.py
|
|
32
|
+
src/hyperot/utils/errors.py
|
|
33
|
+
src/hyperot/utils/hypetyping.py
|
|
34
|
+
src/hyperot/utils/screens.py
|
|
35
|
+
src/hyperot/utils/typextensions.py
|
|
File without changes
|
|
File without changes
|
|
@@ -2,15 +2,15 @@ import json
|
|
|
2
2
|
import time
|
|
3
3
|
import asyncio
|
|
4
4
|
import sys
|
|
5
|
-
import
|
|
5
|
+
from typing import Union, Callable
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from ..
|
|
7
|
+
import websockets
|
|
8
|
+
|
|
9
|
+
from .. import network, events, common, segments, configurator, hyperogger
|
|
10
|
+
from ..utils import errors
|
|
10
11
|
from ..utils.apiresponse import *
|
|
11
12
|
from ..LecAdapters.OneBotLib.Manager import reports, Packet
|
|
12
13
|
from ..events import *
|
|
13
|
-
from ..utils.hypetyping import Any, Union, NoReturn, Callable
|
|
14
14
|
|
|
15
15
|
config = configurator.BotConfig.get("hyper-bot")
|
|
16
16
|
logger = hyperogger.Logger()
|
|
@@ -40,17 +40,17 @@ class Actions:
|
|
|
40
40
|
self.custom = CustomAction(self.connection)
|
|
41
41
|
|
|
42
42
|
async def send_msg(
|
|
43
|
-
self, message: Union[common.Message, str], group_id: int =
|
|
43
|
+
self, message: Union[common.Message, str], group_id: int = 0, user_id: int = 0
|
|
44
44
|
) -> common.Ret[MsgSendRsp]:
|
|
45
45
|
if isinstance(message, str):
|
|
46
46
|
message = common.Message(segments.Text(message))
|
|
47
|
-
if group_id
|
|
47
|
+
if group_id:
|
|
48
48
|
packet = Packet(
|
|
49
49
|
"send_msg",
|
|
50
50
|
group_id=group_id,
|
|
51
51
|
message=await message.get()
|
|
52
52
|
)
|
|
53
|
-
elif user_id
|
|
53
|
+
elif user_id:
|
|
54
54
|
packet = Packet(
|
|
55
55
|
"send_msg",
|
|
56
56
|
user_id=user_id,
|
|
@@ -62,14 +62,10 @@ class Actions:
|
|
|
62
62
|
logger.info(f"向{(('群 ' + str(group_id)) if group_id else ('用户' + str(user_id))) + ' '}发送:{str(message)}")
|
|
63
63
|
return await common.Ret.fetch(packet.echo, MsgSendRsp)
|
|
64
64
|
|
|
65
|
-
async def send_group_msg(
|
|
66
|
-
self, message: Union[common.Message, str], group_id: int = None
|
|
67
|
-
) -> common.Ret[MsgSendRsp]:
|
|
65
|
+
async def send_group_msg(self, message: Union[common.Message, str], group_id: int) -> common.Ret[MsgSendRsp]:
|
|
68
66
|
return await self.send_msg(message, group_id=group_id)
|
|
69
67
|
|
|
70
|
-
async def send_private_msg(
|
|
71
|
-
self, message: Union[common.Message, str], user_id: int = None
|
|
72
|
-
) -> common.Ret[MsgSendRsp]:
|
|
68
|
+
async def send_private_msg(self, message: Union[common.Message, str], user_id: int) -> common.Ret[MsgSendRsp]:
|
|
73
69
|
return await self.send_msg(message, user_id=user_id)
|
|
74
70
|
|
|
75
71
|
async def del_msg(self, message_id: int) -> None:
|
|
@@ -247,40 +243,20 @@ def reg(func: Callable) -> None:
|
|
|
247
243
|
connection: Union[network.WebsocketConnection, network.HTTPConnection]
|
|
248
244
|
|
|
249
245
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
def handler(self, func: FuncCall) -> Any:
|
|
253
|
-
pass
|
|
254
|
-
|
|
255
|
-
async def server(self, bot_config: configurator.BotConfig) -> None:
|
|
256
|
-
if isinstance(config.connection, dict):
|
|
257
|
-
raise errors.ListenerNotRegisteredError("未注册接收器")
|
|
258
|
-
proc = subprocess.Popen(
|
|
259
|
-
args=config.connection.ob_exec,
|
|
260
|
-
cwd=config.connection.ob_startup_path,
|
|
261
|
-
stdout=subprocess.PIPE
|
|
262
|
-
)
|
|
263
|
-
if bot_config.connection.ob_log_output:
|
|
264
|
-
for i in proc.stdout:
|
|
265
|
-
print(i.decode(), end="")
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
async def run() -> NoReturn:
|
|
246
|
+
async def run() -> None:
|
|
269
247
|
global connection, listener_ran
|
|
270
248
|
listener_ran = True
|
|
271
249
|
try:
|
|
272
250
|
if handler is tester:
|
|
273
251
|
raise errors.ListenerNotRegisteredError("No handler registered")
|
|
274
252
|
if isinstance(config.connection, configurator.BotWSC):
|
|
275
|
-
connection = network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}")
|
|
253
|
+
connection = network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}/")
|
|
276
254
|
elif isinstance(config.connection, configurator.BotHTTPC):
|
|
277
255
|
connection = network.HTTPConnection(
|
|
278
256
|
url=f"http://{config.connection.host}:{config.connection.port}",
|
|
279
257
|
listener_url=f"http://{config.connection.listener_host}:{config.connection.listener_port}"
|
|
280
258
|
)
|
|
281
259
|
retried = 0
|
|
282
|
-
if config.connection.ob_auto_startup:
|
|
283
|
-
LagrangeOneBotService(IServiceStartUp.MANUAL).run_in_thread(config)
|
|
284
260
|
|
|
285
261
|
while 1:
|
|
286
262
|
try:
|
|
@@ -292,7 +268,7 @@ async def run() -> NoReturn:
|
|
|
292
268
|
|
|
293
269
|
logger.warning(f"连接建立失败,3秒后重试({retried}/{config.connection.retries})")
|
|
294
270
|
retried += 1
|
|
295
|
-
|
|
271
|
+
await asyncio.sleep(3)
|
|
296
272
|
continue
|
|
297
273
|
retried = 0
|
|
298
274
|
logger.info(f"成功在 {connection.url} 建立连接")
|
|
@@ -308,7 +284,7 @@ async def run() -> NoReturn:
|
|
|
308
284
|
while True:
|
|
309
285
|
try:
|
|
310
286
|
data = await connection.recv()
|
|
311
|
-
except
|
|
287
|
+
except websockets.exceptions.ConnectionClosedError:
|
|
312
288
|
logger.error("连接断开")
|
|
313
289
|
break
|
|
314
290
|
except json.decoder.JSONDecodeError:
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
from ... import configurator, hyperogger, network
|
|
2
|
-
from ...utils import logic
|
|
1
|
+
from ... import configurator, hyperogger, network, utils
|
|
3
2
|
from ...utils.hypetyping import OneBotJsonPacket
|
|
4
3
|
|
|
5
4
|
from typing import Union
|
|
6
5
|
import random
|
|
7
6
|
import json
|
|
8
7
|
|
|
9
|
-
reports =
|
|
8
|
+
reports = utils.KeyQueue()
|
|
10
9
|
|
|
11
10
|
config: configurator.BotConfig
|
|
12
11
|
logger: hyperogger.Logger
|
|
@@ -1,37 +1,46 @@
|
|
|
1
1
|
from . import configurator
|
|
2
2
|
from .utils import screens
|
|
3
3
|
|
|
4
|
-
from typing import Union, Callable
|
|
4
|
+
from typing import Union, Callable, TYPE_CHECKING, Any
|
|
5
5
|
import asyncio
|
|
6
6
|
import sys
|
|
7
7
|
import os
|
|
8
8
|
import signal
|
|
9
9
|
|
|
10
|
-
HYPER_BOT_VERSION = "0.82.
|
|
10
|
+
HYPER_BOT_VERSION = "0.82.5"
|
|
11
11
|
|
|
12
12
|
# listener = None
|
|
13
13
|
|
|
14
14
|
screens.play_startup()
|
|
15
15
|
screens.play_info(HYPER_BOT_VERSION)
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from . import events, listener, hyperogger
|
|
19
|
+
|
|
20
|
+
ANY_EVENT = Union[
|
|
21
|
+
events.GroupMessageEvent,
|
|
22
|
+
events.PrivateMessageEvent,
|
|
23
|
+
events.GroupFileUploadEvent,
|
|
24
|
+
events.GroupAdminEvent,
|
|
25
|
+
events.GroupMemberDecreaseEvent,
|
|
26
|
+
events.GroupMemberIncreaseEvent,
|
|
27
|
+
events.GroupMuteEvent,
|
|
28
|
+
events.FriendAddEvent,
|
|
29
|
+
events.GroupRecallEvent,
|
|
30
|
+
events.FriendRecallEvent,
|
|
31
|
+
events.NotifyEvent,
|
|
32
|
+
events.GroupEssenceEvent,
|
|
33
|
+
events.MessageReactionEvent,
|
|
34
|
+
events.GroupAddInviteEvent,
|
|
35
|
+
events.HyperListenerStartNotify,
|
|
36
|
+
events.HyperListenerStopNotify
|
|
37
|
+
]
|
|
38
|
+
LISTENER_ACTIONS = listener.Actions
|
|
39
|
+
LOGGER = hyperogger.Logger
|
|
40
|
+
else:
|
|
41
|
+
ANY_EVENT = Any
|
|
42
|
+
LISTENER_ACTIONS = Any
|
|
43
|
+
LOGGER = Any
|
|
35
44
|
|
|
36
45
|
|
|
37
46
|
class Client:
|
|
@@ -57,7 +66,7 @@ class Client:
|
|
|
57
66
|
self.records[event].append(func)
|
|
58
67
|
|
|
59
68
|
async def distributor(
|
|
60
|
-
self, message_data: Union["events.Event", "events.HyperNotify"], actions:
|
|
69
|
+
self, message_data: Union["events.Event", "events.HyperNotify"], actions: LISTENER_ACTIONS
|
|
61
70
|
) -> None:
|
|
62
71
|
if type(message_data) in list(self.records.keys()):
|
|
63
72
|
tasks = []
|
|
@@ -76,7 +85,7 @@ class Client:
|
|
|
76
85
|
loop = asyncio.get_running_loop()
|
|
77
86
|
_wakeup_task = None
|
|
78
87
|
if sys.platform == "win32":
|
|
79
|
-
def _win32_handler(signum, frame):
|
|
88
|
+
def _win32_handler(signum, frame): # type: ignore
|
|
80
89
|
stop.set()
|
|
81
90
|
|
|
82
91
|
signal.signal(signal.SIGINT, _win32_handler)
|
|
@@ -92,7 +101,7 @@ class Client:
|
|
|
92
101
|
_wakeup_task = asyncio.create_task(_win32_wakeup())
|
|
93
102
|
else:
|
|
94
103
|
for i in (signal.SIGINT, signal.SIGTERM):
|
|
95
|
-
loop.add_signal_handler(i, stop.set)
|
|
104
|
+
loop.add_signal_handler(i, stop.set) # type: ignore
|
|
96
105
|
task = asyncio.create_task(self.lis.run())
|
|
97
106
|
await stop.wait()
|
|
98
107
|
if _wakeup_task:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
from
|
|
2
|
+
from typing import Any
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
def replace(new: Any, old: str):
|
|
@@ -11,15 +11,15 @@ def replace(new: Any, old: str):
|
|
|
11
11
|
sys.modules[old] = new
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
def replace_listener(new
|
|
14
|
+
def replace_listener(new):
|
|
15
15
|
replace(new, "hyperot.adapters.listener")
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def replace_common(new
|
|
18
|
+
def replace_common(new):
|
|
19
19
|
replace(new, "hyperot.adapters.common")
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def replace_res(new
|
|
22
|
+
def replace_res(new):
|
|
23
23
|
replace(new, "hyperot.adapters.res")
|
|
24
24
|
|
|
25
25
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from
|
|
1
|
+
from typing import Any, NoReturn, TypeVar, Callable
|
|
2
2
|
from ..utils.apiresponse import *
|
|
3
|
-
from ..
|
|
3
|
+
from .. import hyperogger, common, configurator
|
|
4
4
|
|
|
5
5
|
config = configurator.BotConfig.get("hyper-bot")
|
|
6
6
|
logger = hyperogger.Logger()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
from typing import Generic, Type, Self, TypeVar
|
|
2
|
+
|
|
1
3
|
from . import configurator
|
|
2
4
|
from .utils.typextensions import ObjectedJson
|
|
3
5
|
from . import segments
|
|
4
|
-
from .utils.hypetyping import TypeVar
|
|
5
6
|
|
|
6
|
-
from typing import Generic, Type, Self
|
|
7
7
|
|
|
8
8
|
config = configurator.BotConfig.get("hyper-bot")
|
|
9
9
|
T = TypeVar("T")
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
from cfgr.manager import BaseConfig
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
__all__ = [
|
|
5
|
+
"BotConfig",
|
|
6
|
+
"BotWSC",
|
|
7
|
+
"BotHTTPC"
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
|
|
4
11
|
class BotWSC(BaseConfig):
|
|
5
12
|
mode: str = "FWS"
|
|
6
13
|
ob_auto_startup: bool = False
|
|
@@ -43,10 +50,14 @@ class BotConfig(BaseConfig):
|
|
|
43
50
|
others: dict
|
|
44
51
|
|
|
45
52
|
def custom_post(self, **kwargs):
|
|
46
|
-
if self.
|
|
47
|
-
if self.
|
|
48
|
-
self.connection
|
|
49
|
-
|
|
50
|
-
self.connection
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
if isinstance(self.connection, dict):
|
|
54
|
+
if self.protocol == "OneBot":
|
|
55
|
+
if self.connection["mode"] == "FWS":
|
|
56
|
+
self.connection = BotWSC(**self.connection)
|
|
57
|
+
elif self.connection["mode"] == "HTTPC":
|
|
58
|
+
self.connection = BotHTTPC(**self.connection)
|
|
59
|
+
else:
|
|
60
|
+
raise TypeError()
|
|
61
|
+
|
|
62
|
+
if isinstance(self.connection, dict):
|
|
63
|
+
raise TypeError()
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
from . import configurator, hyperogger, common
|
|
2
|
-
from .utils.typextensions import Integer
|
|
3
2
|
from .segments import message_types, At
|
|
4
3
|
from .network import WebsocketConnection, HTTPConnection
|
|
5
4
|
from .hyperogger import levels
|
|
6
5
|
|
|
7
6
|
from abc import ABC
|
|
8
|
-
from typing import Union
|
|
7
|
+
from typing import Union, Callable, Optional
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"init",
|
|
11
|
+
"EventManager",
|
|
12
|
+
"em",
|
|
13
|
+
"GroupSender",
|
|
14
|
+
"PrivateSender",
|
|
15
|
+
"GroupAnonymous",
|
|
16
|
+
"gen_message",
|
|
17
|
+
"Event",
|
|
18
|
+
"UnrecognizedEvent",
|
|
19
|
+
"MessageEvent",
|
|
20
|
+
"PrivateMessageEvent",
|
|
21
|
+
"GroupMessageEvent",
|
|
22
|
+
"NoticeEvent",
|
|
23
|
+
"GroupFileUploadEvent",
|
|
24
|
+
"GroupAdminEvent",
|
|
25
|
+
"GroupMemberDecreaseEvent",
|
|
26
|
+
"GroupMemberIncreaseEvent",
|
|
27
|
+
"GroupMuteEvent",
|
|
28
|
+
"FriendAddEvent",
|
|
29
|
+
"GroupRecallEvent",
|
|
30
|
+
"FriendRecallEvent",
|
|
31
|
+
"NotifyEvent",
|
|
32
|
+
"GroupEssenceEvent",
|
|
33
|
+
"MessageReactionEvent",
|
|
34
|
+
"BotOnLineEvent",
|
|
35
|
+
"RequestEvent",
|
|
36
|
+
"FriendAddRequestEvent",
|
|
37
|
+
"GroupAddInviteEvent",
|
|
38
|
+
"HyperNotify",
|
|
39
|
+
"HyperListenerStartNotify",
|
|
40
|
+
"HyperListenerStopNotify",
|
|
41
|
+
]
|
|
9
42
|
|
|
10
43
|
config: configurator.BotConfig
|
|
11
44
|
logger: hyperogger.Logger
|
|
@@ -27,7 +60,7 @@ class EventManager:
|
|
|
27
60
|
}
|
|
28
61
|
self.events = []
|
|
29
62
|
|
|
30
|
-
def reg(self, type_of: str, str_eql: str) ->
|
|
63
|
+
def reg(self, type_of: str, str_eql: str) -> Callable:
|
|
31
64
|
def wrapper(cls):
|
|
32
65
|
self.event_lis[type_of][str_eql] = cls
|
|
33
66
|
self.events.append(cls)
|
|
@@ -99,12 +132,12 @@ class Event(ABC):
|
|
|
99
132
|
def __init__(self, data: dict):
|
|
100
133
|
self.data = data.copy()
|
|
101
134
|
self.time = data.get("time")
|
|
102
|
-
self.self_id = data.get("self_id")
|
|
135
|
+
self.self_id = data.get("self_id", 0)
|
|
103
136
|
self.post_type = data.get("post_type")
|
|
104
137
|
self.user_id = data.get("user_id")
|
|
105
138
|
self.group_id = data.get("group_id")
|
|
106
139
|
|
|
107
|
-
self.is_owner =
|
|
140
|
+
self.is_owner = self.self_id in config.owner
|
|
108
141
|
self.blocked = True if self.user_id in config.black_list or self.group_id in config.black_list else False
|
|
109
142
|
self.is_silent = self.user_id in config.silents or self.group_id in config.silents or 0 in config.silents
|
|
110
143
|
|
|
@@ -129,7 +162,7 @@ class MessageEvent(Event):
|
|
|
129
162
|
class PrivateMessageEvent(MessageEvent):
|
|
130
163
|
def __init__(self, data: dict):
|
|
131
164
|
super().__init__(data)
|
|
132
|
-
self.sender = PrivateSender(data.get("sender"))
|
|
165
|
+
self.sender = PrivateSender(data.get("sender")) # type: ignore
|
|
133
166
|
|
|
134
167
|
self.print_log()
|
|
135
168
|
|
|
@@ -141,8 +174,8 @@ class PrivateMessageEvent(MessageEvent):
|
|
|
141
174
|
class GroupMessageEvent(MessageEvent):
|
|
142
175
|
def __init__(self, data: dict):
|
|
143
176
|
super().__init__(data)
|
|
144
|
-
self.sender = GroupSender(data.get("sender"))
|
|
145
|
-
self.anonymous = GroupAnonymous(data.get("anonymous"))
|
|
177
|
+
self.sender = GroupSender(data.get("sender")) # type: ignore
|
|
178
|
+
self.anonymous = GroupAnonymous(data.get("anonymous")) # type: ignore
|
|
146
179
|
self.is_mentioned = True if At(str(self.self_id)) in self.message else False
|
|
147
180
|
|
|
148
181
|
self.print_log()
|
|
@@ -336,7 +369,7 @@ class HyperNotify:
|
|
|
336
369
|
|
|
337
370
|
class HyperListenerStartNotify(HyperNotify):
|
|
338
371
|
def __init__(self, time_now: int, notify_type: str,
|
|
339
|
-
connection: Union[WebsocketConnection, HTTPConnection] = None):
|
|
372
|
+
connection: Optional[Union[WebsocketConnection, HTTPConnection]] = None):
|
|
340
373
|
super().__init__(time_now, notify_type)
|
|
341
374
|
self.connection = connection
|
|
342
375
|
|
|
@@ -6,6 +6,14 @@ import sys
|
|
|
6
6
|
from .utils.screens import color_txt, rgb, NerdICONs
|
|
7
7
|
from . import configurator
|
|
8
8
|
|
|
9
|
+
__all__ = [
|
|
10
|
+
"config",
|
|
11
|
+
"nf_icons",
|
|
12
|
+
"Levels",
|
|
13
|
+
"levels",
|
|
14
|
+
"Logger",
|
|
15
|
+
]
|
|
16
|
+
|
|
9
17
|
|
|
10
18
|
config = configurator.BotConfig.get("hyper-bot")
|
|
11
19
|
nf_icons = NerdICONs(config.log_use_nf)
|
|
@@ -53,9 +61,6 @@ class Logger:
|
|
|
53
61
|
c = cls()
|
|
54
62
|
c.set_level(level)
|
|
55
63
|
cls.running_loggers[key] = c
|
|
56
|
-
# print(key)
|
|
57
|
-
# print(c)
|
|
58
|
-
# print(cls.running_loggers)
|
|
59
64
|
return c
|
|
60
65
|
|
|
61
66
|
@classmethod
|
|
@@ -7,20 +7,21 @@ import logging
|
|
|
7
7
|
import threading
|
|
8
8
|
from websockets.asyncio.client import connect as wsc
|
|
9
9
|
from websockets.asyncio.client import ClientConnection
|
|
10
|
+
from typing import Optional, Dict
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
async def httpx_get(url: str, headers:
|
|
13
|
+
async def httpx_get(url: str, headers: Optional[Dict] = None) -> httpx.Response:
|
|
13
14
|
async with httpx.AsyncClient(headers=headers) as client:
|
|
14
15
|
return await client.get(url)
|
|
15
16
|
|
|
16
|
-
async def httpx_post(url: str, json: dict, headers:
|
|
17
|
+
async def httpx_post(url: str, json: Optional[dict] = None, data: Optional[str] = None, headers: Optional[Dict] = None) -> httpx.Response:
|
|
17
18
|
async with httpx.AsyncClient(headers=headers) as client:
|
|
18
|
-
return await client.post(url, json=json)
|
|
19
|
+
return await client.post(url, json=json, data=data)
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
class WebsocketConnection:
|
|
22
23
|
def __init__(self, url: str, auth: str = ""):
|
|
23
|
-
self.ws: ClientConnection = None
|
|
24
|
+
self.ws: Optional[ClientConnection] = None
|
|
24
25
|
self.url = url
|
|
25
26
|
self.auth = auth
|
|
26
27
|
|