hyper-bot 0.82.2__tar.gz → 0.82.4__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.4/PKG-INFO +17 -0
- hyper_bot-0.82.4/pyproject.toml +27 -0
- hyper_bot-0.82.4/src/hyper_bot.egg-info/PKG-INFO +17 -0
- hyper_bot-0.82.4/src/hyper_bot.egg-info/SOURCES.txt +35 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyper_bot.egg-info/dependency_links.txt +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyper_bot.egg-info/requires.txt +3 -2
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyper_bot.egg-info/top_level.txt +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/LecAdapters/MilkyLib/translator.py +0 -1
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/LecAdapters/OneBot.py +13 -39
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/LecAdapters/OneBotLib/Manager.py +2 -3
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/__init__.py +32 -23
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/adapters/__init__.py +4 -4
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/adapters/common.py +2 -1
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/adapters/listener.py +2 -2
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/common.py +2 -2
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/configurator.py +18 -7
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/events.py +42 -9
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/hyperogger.py +8 -3
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/network.py +21 -14
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/segments.py +39 -5
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/utils/ArkSignHelper.py +12 -15
- hyper_bot-0.82.4/src/hyperot/utils/__init__.py +22 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/utils/apiresponse.py +13 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/utils/errors.py +8 -5
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/utils/hypetyping.py +1 -1
- hyper_bot-0.82.4/src/hyperot/utils/typextensions.py +49 -0
- hyper_bot-0.82.2/PKG-INFO +0 -16
- hyper_bot-0.82.2/hyper_bot.egg-info/PKG-INFO +0 -16
- hyper_bot-0.82.2/hyper_bot.egg-info/SOURCES.txt +0 -36
- hyper_bot-0.82.2/hyperot/service.py +0 -51
- hyper_bot-0.82.2/hyperot/utils/logic.py +0 -320
- hyper_bot-0.82.2/hyperot/utils/typextensions.py +0 -172
- hyper_bot-0.82.2/setup.py +0 -32
- {hyper_bot-0.82.2 → hyper_bot-0.82.4}/LICENSE +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4}/setup.cfg +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/LecAdapters/Milky.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/LecAdapters/MilkyLib/Manager.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/LecAdapters/MilkyLib/Res.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/LecAdapters/OneBotLib/Res.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/adapters/builtins.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/adapters/obuilder.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/adapters/res.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/listener.py +0 -0
- {hyper_bot-0.82.2 → hyper_bot-0.82.4/src}/hyperot/utils/screens.py +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyper-bot
|
|
3
|
+
Version: 0.82.4
|
|
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.4"
|
|
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.4
|
|
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,13 @@ 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
|
-
from .. import network, events, common, segments
|
|
8
|
-
from ..
|
|
9
|
-
from ..utils import errors, logic
|
|
7
|
+
from .. import network, events, common, segments, configurator, hyperogger
|
|
8
|
+
from ..utils import errors
|
|
10
9
|
from ..utils.apiresponse import *
|
|
11
10
|
from ..LecAdapters.OneBotLib.Manager import reports, Packet
|
|
12
11
|
from ..events import *
|
|
13
|
-
from ..utils.hypetyping import Any, Union, NoReturn, Callable
|
|
14
12
|
|
|
15
13
|
config = configurator.BotConfig.get("hyper-bot")
|
|
16
14
|
logger = hyperogger.Logger()
|
|
@@ -40,17 +38,17 @@ class Actions:
|
|
|
40
38
|
self.custom = CustomAction(self.connection)
|
|
41
39
|
|
|
42
40
|
async def send_msg(
|
|
43
|
-
self, message: Union[common.Message, str], group_id: int =
|
|
41
|
+
self, message: Union[common.Message, str], group_id: int = 0, user_id: int = 0
|
|
44
42
|
) -> common.Ret[MsgSendRsp]:
|
|
45
43
|
if isinstance(message, str):
|
|
46
44
|
message = common.Message(segments.Text(message))
|
|
47
|
-
if group_id
|
|
45
|
+
if group_id:
|
|
48
46
|
packet = Packet(
|
|
49
47
|
"send_msg",
|
|
50
48
|
group_id=group_id,
|
|
51
49
|
message=await message.get()
|
|
52
50
|
)
|
|
53
|
-
elif user_id
|
|
51
|
+
elif user_id:
|
|
54
52
|
packet = Packet(
|
|
55
53
|
"send_msg",
|
|
56
54
|
user_id=user_id,
|
|
@@ -62,14 +60,10 @@ class Actions:
|
|
|
62
60
|
logger.info(f"向{(('群 ' + str(group_id)) if group_id else ('用户' + str(user_id))) + ' '}发送:{str(message)}")
|
|
63
61
|
return await common.Ret.fetch(packet.echo, MsgSendRsp)
|
|
64
62
|
|
|
65
|
-
async def send_group_msg(
|
|
66
|
-
self, message: Union[common.Message, str], group_id: int = None
|
|
67
|
-
) -> common.Ret[MsgSendRsp]:
|
|
63
|
+
async def send_group_msg(self, message: Union[common.Message, str], group_id: int) -> common.Ret[MsgSendRsp]:
|
|
68
64
|
return await self.send_msg(message, group_id=group_id)
|
|
69
65
|
|
|
70
|
-
async def send_private_msg(
|
|
71
|
-
self, message: Union[common.Message, str], user_id: int = None
|
|
72
|
-
) -> common.Ret[MsgSendRsp]:
|
|
66
|
+
async def send_private_msg(self, message: Union[common.Message, str], user_id: int) -> common.Ret[MsgSendRsp]:
|
|
73
67
|
return await self.send_msg(message, user_id=user_id)
|
|
74
68
|
|
|
75
69
|
async def del_msg(self, message_id: int) -> None:
|
|
@@ -247,44 +241,24 @@ def reg(func: Callable) -> None:
|
|
|
247
241
|
connection: Union[network.WebsocketConnection, network.HTTPConnection]
|
|
248
242
|
|
|
249
243
|
|
|
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:
|
|
244
|
+
async def run() -> None:
|
|
269
245
|
global connection, listener_ran
|
|
270
246
|
listener_ran = True
|
|
271
247
|
try:
|
|
272
248
|
if handler is tester:
|
|
273
249
|
raise errors.ListenerNotRegisteredError("No handler registered")
|
|
274
250
|
if isinstance(config.connection, configurator.BotWSC):
|
|
275
|
-
connection = network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}")
|
|
251
|
+
connection = network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}/")
|
|
276
252
|
elif isinstance(config.connection, configurator.BotHTTPC):
|
|
277
253
|
connection = network.HTTPConnection(
|
|
278
254
|
url=f"http://{config.connection.host}:{config.connection.port}",
|
|
279
255
|
listener_url=f"http://{config.connection.listener_host}:{config.connection.listener_port}"
|
|
280
256
|
)
|
|
281
257
|
retried = 0
|
|
282
|
-
if config.connection.ob_auto_startup:
|
|
283
|
-
LagrangeOneBotService(IServiceStartUp.MANUAL).run_in_thread(config)
|
|
284
258
|
|
|
285
|
-
while
|
|
259
|
+
while 1:
|
|
286
260
|
try:
|
|
287
|
-
connection.connect()
|
|
261
|
+
await connection.connect()
|
|
288
262
|
except (ConnectionRefusedError, TimeoutError):
|
|
289
263
|
if retried >= config.connection.retries:
|
|
290
264
|
logger.critical(f"重试次数达到最大值({config.connection.retries}),退出")
|
|
@@ -292,7 +266,7 @@ async def run() -> NoReturn:
|
|
|
292
266
|
|
|
293
267
|
logger.warning(f"连接建立失败,3秒后重试({retried}/{config.connection.retries})")
|
|
294
268
|
retried += 1
|
|
295
|
-
|
|
269
|
+
await asyncio.sleep(3)
|
|
296
270
|
continue
|
|
297
271
|
retried = 0
|
|
298
272
|
logger.info(f"成功在 {connection.url} 建立连接")
|
|
@@ -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.4"
|
|
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
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import websocket
|
|
3
1
|
import httpx
|
|
4
2
|
import queue
|
|
5
3
|
import flask
|
|
@@ -7,41 +5,50 @@ import traceback
|
|
|
7
5
|
import json
|
|
8
6
|
import logging
|
|
9
7
|
import threading
|
|
8
|
+
from websockets.asyncio.client import connect as wsc
|
|
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
|
-
def __init__(self, url: str, auth: str =
|
|
23
|
-
self.ws =
|
|
23
|
+
def __init__(self, url: str, auth: str = ""):
|
|
24
|
+
self.ws: Optional[ClientConnection] = None
|
|
24
25
|
self.url = url
|
|
25
26
|
self.auth = auth
|
|
26
27
|
|
|
27
|
-
def connect(self) -> None:
|
|
28
|
+
async def connect(self) -> None:
|
|
28
29
|
if self.auth:
|
|
29
|
-
self.ws
|
|
30
|
+
self.ws = await wsc(self.url, header={"Authorization": "Bearer " + self.auth})
|
|
30
31
|
else:
|
|
31
|
-
self.ws
|
|
32
|
+
self.ws = await wsc(self.url)
|
|
32
33
|
|
|
33
34
|
async def send(self, message: str) -> None:
|
|
34
|
-
|
|
35
|
+
if self.ws is None:
|
|
36
|
+
raise RuntimeError("没有建立连接")
|
|
37
|
+
await self.ws.send(message)
|
|
35
38
|
|
|
36
39
|
async def close(self) -> None:
|
|
37
|
-
|
|
40
|
+
if self.ws is None:
|
|
41
|
+
raise RuntimeError("没有建立连接")
|
|
42
|
+
await self.ws.close()
|
|
38
43
|
|
|
39
44
|
async def recv(self) -> dict:
|
|
40
|
-
|
|
45
|
+
if self.ws is None:
|
|
46
|
+
raise RuntimeError("没有建立连接")
|
|
47
|
+
return json.loads(await self.ws.recv())
|
|
41
48
|
|
|
42
49
|
|
|
43
50
|
class HTTPConnection:
|
|
44
|
-
def __init__(self, url: str, listener_url: str, listener_endpoint: str = "/", auth: str =
|
|
51
|
+
def __init__(self, url: str, listener_url: str, listener_endpoint: str = "/", auth: str = ""):
|
|
45
52
|
self.url = url
|
|
46
53
|
listener_url = listener_url.replace("http://", "")
|
|
47
54
|
listener_url = listener_url.replace("https://", "")
|