hyper-bot 0.79.1__tar.gz → 0.80.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.
- {hyper-bot-0.79.1 → hyper_bot-0.80.2}/PKG-INFO +3 -1
- {hyper-bot-0.79.1 → hyper_bot-0.80.2}/hyper_bot.egg-info/PKG-INFO +3 -1
- hyper_bot-0.80.2/hyper_bot.egg-info/SOURCES.txt +44 -0
- hyper_bot-0.80.2/hyper_bot.egg-info/requires.txt +1 -0
- hyper_bot-0.80.2/hyper_bot.egg-info/top_level.txt +1 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/Kritor.py +31 -32
- hyper_bot-0.80.2/hyperot/Adapters/KritorLib/Manager.py +1 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/Res.py +4 -4
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/OneBot.py +74 -85
- hyper_bot-0.80.2/hyperot/Adapters/OneBotLib/Manager.py +45 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/OneBotLib/Res.py +1 -2
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/__init__.py +8 -7
- hyper-bot-0.79.1/Hyper/Adapters/OneBotLib/Manager.py → hyper_bot-0.80.2/hyperot/common.py +19 -40
- hyper-bot-0.79.1/Hyper/Configurator.py → hyper_bot-0.80.2/hyperot/configurator.py +4 -2
- hyper-bot-0.79.1/Hyper/Events.py → hyper_bot-0.80.2/hyperot/events.py +23 -23
- hyper_bot-0.80.2/hyperot/hyperogger.py +133 -0
- hyper-bot-0.79.1/Hyper/Listener.py → hyper_bot-0.80.2/hyperot/listener.py +8 -10
- hyper-bot-0.79.1/Hyper/Network.py → hyper_bot-0.80.2/hyperot/network.py +3 -3
- hyper-bot-0.79.1/Hyper/Segments.py → hyper_bot-0.80.2/hyperot/segments.py +7 -7
- {hyper-bot-0.79.1/Hyper/Utils → hyper_bot-0.80.2/hyperot/utils}/ArkSignHelper.py +2 -3
- hyper-bot-0.79.1/Hyper/Utils/APIRsp.py → hyper_bot-0.80.2/hyperot/utils/apiresponse.py +2 -2
- hyper-bot-0.79.1/Hyper/Utils/HyperTyping.py → hyper_bot-0.80.2/hyperot/utils/hypetyping.py +1 -1
- hyper-bot-0.79.1/Hyper/Utils/Logic.py → hyper_bot-0.80.2/hyperot/utils/logic.py +6 -114
- hyper-bot-0.79.1/Hyper/Utils/Screens.py → hyper_bot-0.80.2/hyperot/utils/screens.py +24 -1
- hyper-bot-0.79.1/Hyper/Utils/TypeExt.py → hyper_bot-0.80.2/hyperot/utils/typextensions.py +0 -19
- hyper_bot-0.80.2/setup.py +28 -0
- hyper-bot-0.79.1/Hyper/Adapters/KritorLib/Manager.py +0 -1
- hyper-bot-0.79.1/Hyper/Adapters/LagrangePy.py +0 -113
- hyper-bot-0.79.1/Hyper/Adapters/Satori.py +0 -107
- hyper-bot-0.79.1/Hyper/Comm.py +0 -14
- hyper-bot-0.79.1/Hyper/Logger.py +0 -176
- hyper-bot-0.79.1/hyper_bot.egg-info/SOURCES.txt +0 -45
- hyper-bot-0.79.1/hyper_bot.egg-info/top_level.txt +0 -1
- hyper-bot-0.79.1/setup.py +0 -26
- {hyper-bot-0.79.1 → hyper_bot-0.80.2}/LICENSE +0 -0
- {hyper-bot-0.79.1 → hyper_bot-0.80.2}/hyper_bot.egg-info/dependency_links.txt +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/authentication/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/common/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/core/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/customization/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/developer/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/event/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/file/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/friend/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/group/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/guild/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/message/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/process/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/reverse/__init__.py +0 -0
- {hyper-bot-0.79.1/Hyper → hyper_bot-0.80.2/hyperot}/Adapters/KritorLib/protos/web/__init__.py +0 -0
- /hyper-bot-0.79.1/Hyper/Service.py → /hyper_bot-0.80.2/hyperot/service.py +0 -0
- /hyper-bot-0.79.1/Hyper/Utils/Errors.py → /hyper_bot-0.80.2/hyperot/utils/errors.py +0 -0
- {hyper-bot-0.79.1 → hyper_bot-0.80.2}/setup.cfg +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hyper-bot
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.80.2
|
|
4
4
|
Summary: 稳定高效、易于开发的QQ Bot框架
|
|
5
5
|
Home-page: https://github.com/HarcicYang/HypeR_Bot
|
|
6
6
|
Author: Harcic
|
|
7
7
|
Author-email: harcic@outlook.com
|
|
8
|
+
Provides: hyperot
|
|
8
9
|
License-File: LICENSE
|
|
10
|
+
Requires-Dist: ucfgr
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hyper-bot
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.80.2
|
|
4
4
|
Summary: 稳定高效、易于开发的QQ Bot框架
|
|
5
5
|
Home-page: https://github.com/HarcicYang/HypeR_Bot
|
|
6
6
|
Author: Harcic
|
|
7
7
|
Author-email: harcic@outlook.com
|
|
8
|
+
Provides: hyperot
|
|
8
9
|
License-File: LICENSE
|
|
10
|
+
Requires-Dist: ucfgr
|
|
@@ -0,0 +1,44 @@
|
|
|
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/Adapters/Kritor.py
|
|
18
|
+
hyperot/Adapters/OneBot.py
|
|
19
|
+
hyperot/Adapters/KritorLib/Manager.py
|
|
20
|
+
hyperot/Adapters/KritorLib/Res.py
|
|
21
|
+
hyperot/Adapters/KritorLib/protos/__init__.py
|
|
22
|
+
hyperot/Adapters/KritorLib/protos/authentication/__init__.py
|
|
23
|
+
hyperot/Adapters/KritorLib/protos/common/__init__.py
|
|
24
|
+
hyperot/Adapters/KritorLib/protos/core/__init__.py
|
|
25
|
+
hyperot/Adapters/KritorLib/protos/customization/__init__.py
|
|
26
|
+
hyperot/Adapters/KritorLib/protos/developer/__init__.py
|
|
27
|
+
hyperot/Adapters/KritorLib/protos/event/__init__.py
|
|
28
|
+
hyperot/Adapters/KritorLib/protos/file/__init__.py
|
|
29
|
+
hyperot/Adapters/KritorLib/protos/friend/__init__.py
|
|
30
|
+
hyperot/Adapters/KritorLib/protos/group/__init__.py
|
|
31
|
+
hyperot/Adapters/KritorLib/protos/guild/__init__.py
|
|
32
|
+
hyperot/Adapters/KritorLib/protos/message/__init__.py
|
|
33
|
+
hyperot/Adapters/KritorLib/protos/process/__init__.py
|
|
34
|
+
hyperot/Adapters/KritorLib/protos/reverse/__init__.py
|
|
35
|
+
hyperot/Adapters/KritorLib/protos/web/__init__.py
|
|
36
|
+
hyperot/Adapters/OneBotLib/Manager.py
|
|
37
|
+
hyperot/Adapters/OneBotLib/Res.py
|
|
38
|
+
hyperot/utils/ArkSignHelper.py
|
|
39
|
+
hyperot/utils/apiresponse.py
|
|
40
|
+
hyperot/utils/errors.py
|
|
41
|
+
hyperot/utils/hypetyping.py
|
|
42
|
+
hyperot/utils/logic.py
|
|
43
|
+
hyperot/utils/screens.py
|
|
44
|
+
hyperot/utils/typextensions.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ucfgr
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hyperot
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
from typing import Any,
|
|
2
|
+
from typing import Any, Self
|
|
3
3
|
import sys
|
|
4
4
|
import threading
|
|
5
5
|
import time
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
from
|
|
16
|
-
|
|
17
|
-
from
|
|
18
|
-
from
|
|
19
|
-
from
|
|
7
|
+
from .. import common
|
|
8
|
+
from ..Adapters.OneBot import Actions as OneBotActions
|
|
9
|
+
from ..Adapters.KritorLib.Res import event_queue, to_protos, message_ids
|
|
10
|
+
from ..events import Event, HyperNotify, HyperListenerStartNotify, em
|
|
11
|
+
from ..service import FuncCall, IServiceStartUp, IServiceBase
|
|
12
|
+
from ..network import KritorConnection
|
|
13
|
+
from ..utils import errors
|
|
14
|
+
from ..utils.apiresponse import *
|
|
15
|
+
from .. import configurator, hyperogger
|
|
16
|
+
|
|
17
|
+
from ..Adapters.KritorLib.protos.common import Contact, Scene
|
|
18
|
+
from ..Adapters.KritorLib.protos.core import GetVersionRequest, CoreServiceStub
|
|
19
|
+
from ..Adapters.KritorLib.protos.message import (
|
|
20
20
|
MessageServiceStub,
|
|
21
21
|
SendMessageRequest,
|
|
22
22
|
RecallMessageRequest,
|
|
23
23
|
GetMessageRequest
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
config =
|
|
27
|
-
logger =
|
|
26
|
+
config = configurator.BotConfig.get("hyper-bot")
|
|
27
|
+
logger = hyperogger.Logger()
|
|
28
28
|
logger.set_level(config.log_level)
|
|
29
29
|
|
|
30
30
|
|
|
@@ -41,10 +41,9 @@ class Actions(OneBotActions):
|
|
|
41
41
|
def __init__(self, cnt: KritorConnection):
|
|
42
42
|
self.connection = cnt
|
|
43
43
|
|
|
44
|
-
@Logger.AutoLogAsync.register(Logger.AutoLog.templates().send, logger)
|
|
45
44
|
async def send(
|
|
46
|
-
self, message:
|
|
47
|
-
) ->
|
|
45
|
+
self, message: common.Message, group_id: int = None, user_id: int = None
|
|
46
|
+
) -> common.Ret[MsgSendRsp]:
|
|
48
47
|
msg = to_protos(message.get_sync())
|
|
49
48
|
if group_id is not None:
|
|
50
49
|
contact = Contact(
|
|
@@ -63,19 +62,19 @@ class Actions(OneBotActions):
|
|
|
63
62
|
)
|
|
64
63
|
res = await MessageServiceStub(self.connection.channel).send_message(req)
|
|
65
64
|
message_ids[res.message_id] = len(message_ids)
|
|
66
|
-
return
|
|
65
|
+
return common.Ret(
|
|
67
66
|
{"data": {"message_id": message_ids[res.message_id]}},
|
|
68
67
|
MsgSendRsp
|
|
69
68
|
)
|
|
70
69
|
|
|
71
|
-
async def get_version_info(self) ->
|
|
70
|
+
async def get_version_info(self) -> common.Ret[GetVerInfoRsp]:
|
|
72
71
|
res = await CoreServiceStub(self.connection.channel).get_version(GetVersionRequest())
|
|
73
|
-
return
|
|
72
|
+
return common.Ret(
|
|
74
73
|
{"data": {"app_name": res.app_name, "app_version": res.version, "protocol_version": None}},
|
|
75
74
|
GetVerInfoRsp
|
|
76
75
|
)
|
|
77
76
|
|
|
78
|
-
async def get_msg(self, msg_id: int) ->
|
|
77
|
+
async def get_msg(self, msg_id: int) -> common.Ret[GetMsgRsp]:
|
|
79
78
|
try:
|
|
80
79
|
mid = list(filter(lambda x: message_ids[x] == msg_id, message_ids))[1]
|
|
81
80
|
except IndexError:
|
|
@@ -87,7 +86,7 @@ class Actions(OneBotActions):
|
|
|
87
86
|
)
|
|
88
87
|
res = await MessageServiceStub(self.connection.channel).get_message(GetMessageRequest(contact, mid))
|
|
89
88
|
print(res)
|
|
90
|
-
return
|
|
89
|
+
return common.Ret(
|
|
91
90
|
{
|
|
92
91
|
"time": res.message.time,
|
|
93
92
|
"message_type": "group",
|
|
@@ -113,7 +112,7 @@ class Actions(OneBotActions):
|
|
|
113
112
|
peer=str(mid_res(mid)[1]),
|
|
114
113
|
)
|
|
115
114
|
res = await MessageServiceStub(self.connection.channel).get_message(GetMessageRequest(contact, mid))
|
|
116
|
-
return
|
|
115
|
+
return common.Ret(
|
|
117
116
|
{
|
|
118
117
|
"time": res.message.time,
|
|
119
118
|
"message_type": "private",
|
|
@@ -178,7 +177,7 @@ def run():
|
|
|
178
177
|
async def hy_i_runner():
|
|
179
178
|
global connection
|
|
180
179
|
if handler is tester:
|
|
181
|
-
raise
|
|
180
|
+
raise errors.ListenerNotRegisteredError("No handler registered")
|
|
182
181
|
# connection = websocket.WebSocket()
|
|
183
182
|
# if isinstance(config.connection, Configurator.WSConnectionC):
|
|
184
183
|
# connection = Network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}")
|
|
@@ -198,15 +197,15 @@ def run():
|
|
|
198
197
|
except ConnectionRefusedError or TimeoutError:
|
|
199
198
|
if retried >= config.connection.retries:
|
|
200
199
|
logger.log(f"重试次数达到最大值({config.connection.retries}),退出",
|
|
201
|
-
level=
|
|
200
|
+
level=hyperogger.levels.CRITICAL)
|
|
202
201
|
break
|
|
203
202
|
|
|
204
203
|
logger.log(f"连接建立失败,3秒后重试({retried}/{config.connection.retries})",
|
|
205
|
-
level=
|
|
204
|
+
level=hyperogger.levels.WARNING)
|
|
206
205
|
retried += 1
|
|
207
206
|
time.sleep(3)
|
|
208
207
|
continue
|
|
209
|
-
logger.log("成功建立连接", level=
|
|
208
|
+
logger.log("成功建立连接", level=hyperogger.levels.INFO)
|
|
210
209
|
retried = 0
|
|
211
210
|
actions = Actions(connection)
|
|
212
211
|
data = HyperListenerStartNotify(
|
|
@@ -223,7 +222,7 @@ def run():
|
|
|
223
222
|
await task
|
|
224
223
|
except ConnectionResetError:
|
|
225
224
|
task = None
|
|
226
|
-
logger.log("连接断开", level=
|
|
225
|
+
logger.log("连接断开", level=hyperogger.levels.ERROR)
|
|
227
226
|
break
|
|
228
227
|
# threading.Thread(target=lambda: asyncio.run(__handler(data, actions))).start()
|
|
229
228
|
# threading.Thread(target=lambda: __handler(data, actions)).start()
|
|
@@ -232,7 +231,7 @@ def run():
|
|
|
232
231
|
try:
|
|
233
232
|
asyncio.get_event_loop().run_until_complete(hy_i_runner())
|
|
234
233
|
except KeyboardInterrupt:
|
|
235
|
-
logger.log("正在退出(Ctrl+C)", level=
|
|
234
|
+
logger.log("正在退出(Ctrl+C)", level=hyperogger.levels.WARNING)
|
|
236
235
|
sys.exit()
|
|
237
236
|
|
|
238
237
|
|
|
@@ -241,4 +240,4 @@ def stop() -> None:
|
|
|
241
240
|
connection.close()
|
|
242
241
|
except:
|
|
243
242
|
pass
|
|
244
|
-
logger.log("停止运行监听器", level=
|
|
243
|
+
logger.log("停止运行监听器", level=hyperogger.levels.WARNING)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ...Adapters.OneBotLib.Manager import *
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from
|
|
1
|
+
from ...Adapters.KritorLib.protos.event import (
|
|
2
2
|
EventServiceStub,
|
|
3
3
|
RequestPushEvent,
|
|
4
4
|
EventType,
|
|
@@ -7,7 +7,7 @@ from Hyper.Adapters.KritorLib.protos.event import (
|
|
|
7
7
|
GroupMemberDecreasedNoticeGroupMemberDecreasedType,
|
|
8
8
|
GroupMemberIncreasedNoticeGroupMemberIncreasedType
|
|
9
9
|
)
|
|
10
|
-
from
|
|
10
|
+
from ...Adapters.KritorLib.protos.common import (
|
|
11
11
|
ElementElementType,
|
|
12
12
|
PushMessageBody,
|
|
13
13
|
Scene, Element,
|
|
@@ -18,8 +18,8 @@ from Hyper.Adapters.KritorLib.protos.common import (
|
|
|
18
18
|
VoiceElement,
|
|
19
19
|
ImageElement
|
|
20
20
|
)
|
|
21
|
-
from
|
|
22
|
-
from
|
|
21
|
+
from ...configurator import BotConfig
|
|
22
|
+
from ...utils.logic import SimpleQueue
|
|
23
23
|
|
|
24
24
|
import traceback
|
|
25
25
|
import asyncio
|
|
@@ -6,30 +6,30 @@ import sys
|
|
|
6
6
|
import subprocess
|
|
7
7
|
from typing import Any, NoReturn
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from
|
|
15
|
-
|
|
16
|
-
config =
|
|
17
|
-
logger =
|
|
9
|
+
from .. import network, events, common, segments
|
|
10
|
+
from ..service import FuncCall, IServiceBase, IServiceStartUp
|
|
11
|
+
from ..utils import errors, logic
|
|
12
|
+
from ..utils.apiresponse import *
|
|
13
|
+
from ..Adapters.OneBotLib.Manager import reports
|
|
14
|
+
from ..events import *
|
|
15
|
+
|
|
16
|
+
config = configurator.BotConfig.get("hyper-bot")
|
|
17
|
+
logger = hyperogger.Logger()
|
|
18
18
|
logger.set_level(config.log_level)
|
|
19
19
|
listener_ran = False
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class Actions:
|
|
23
|
-
def __init__(self, cnt: Union[
|
|
23
|
+
def __init__(self, cnt: Union[network.WebsocketConnection, network.HTTPConnection]):
|
|
24
24
|
self.connection = cnt
|
|
25
25
|
|
|
26
26
|
class CustomAction:
|
|
27
|
-
def __init__(self, cnt_i: Union[
|
|
27
|
+
def __init__(self, cnt_i: Union[network.WebsocketConnection, network.HTTPConnection]):
|
|
28
28
|
self.connection = cnt_i
|
|
29
29
|
|
|
30
30
|
def __getattr__(self, item) -> callable:
|
|
31
31
|
async def wrapper(**kwargs) -> str:
|
|
32
|
-
packet =
|
|
32
|
+
packet = common.Packet(
|
|
33
33
|
str(item),
|
|
34
34
|
**kwargs
|
|
35
35
|
)
|
|
@@ -40,148 +40,144 @@ class Actions:
|
|
|
40
40
|
|
|
41
41
|
self.custom = CustomAction(self.connection)
|
|
42
42
|
|
|
43
|
-
@Logger.AutoLogAsync.register(Logger.AutoLog.templates().send, logger)
|
|
44
43
|
async def send(
|
|
45
|
-
self, message:
|
|
46
|
-
) ->
|
|
44
|
+
self, message: Union[common.Message, str], group_id: int = None, user_id: int = None
|
|
45
|
+
) -> common.Ret[MsgSendRsp]:
|
|
47
46
|
if group_id is not None:
|
|
48
|
-
|
|
47
|
+
if isinstance(message, str):
|
|
48
|
+
message = common.Message(segments.Text(message))
|
|
49
|
+
packet = common.Packet(
|
|
49
50
|
"send_msg",
|
|
50
51
|
group_id=group_id,
|
|
51
52
|
message=await message.get()
|
|
52
53
|
)
|
|
53
54
|
elif user_id is not None:
|
|
54
|
-
packet =
|
|
55
|
+
packet = common.Packet(
|
|
55
56
|
"send_msg",
|
|
56
57
|
user_id=user_id,
|
|
57
58
|
message=await message.get()
|
|
58
59
|
)
|
|
59
60
|
else:
|
|
60
|
-
raise
|
|
61
|
+
raise errors.ArgsInvalidError("'send' API requires 'group_id' or 'user_id' but none of them are provided.")
|
|
61
62
|
packet.send_to(self.connection)
|
|
62
|
-
|
|
63
|
+
logger.info(f"向{(('群 ' + str(group_id)) if group_id else ('用户' + str(user_id))) + ' '}发送:{str(message)}")
|
|
64
|
+
return common.Ret.fetch(packet.echo, MsgSendRsp)
|
|
63
65
|
|
|
64
|
-
@Logger.AutoLogAsync.register(Logger.AutoLog.templates().recall, logger)
|
|
65
66
|
async def del_message(self, message_id: int) -> None:
|
|
66
|
-
|
|
67
|
+
common.Packet(
|
|
67
68
|
"delete_msg",
|
|
68
69
|
message_id=message_id,
|
|
69
70
|
).send_to(self.connection)
|
|
71
|
+
logger.info(f"撤回 {message_id}")
|
|
70
72
|
|
|
71
|
-
@Logger.AutoLogAsync.register(Logger.AutoLog.templates().kick, logger)
|
|
72
73
|
async def set_group_kick(self, group_id: int, user_id: int) -> None:
|
|
73
|
-
|
|
74
|
+
common.Packet(
|
|
74
75
|
"set_group_kick",
|
|
75
76
|
group_id=group_id,
|
|
76
77
|
user_id=user_id,
|
|
77
78
|
).send_to(self.connection)
|
|
79
|
+
logger.info(f"将用户 {user_id} 移出群 {group_id}")
|
|
78
80
|
|
|
79
|
-
@Logger.AutoLogAsync.register(Logger.AutoLog.templates().mute, logger)
|
|
80
81
|
async def set_group_ban(self, group_id: int, user_id: int, duration: int = 60) -> None:
|
|
81
|
-
|
|
82
|
+
common.Packet(
|
|
82
83
|
"set_group_ban",
|
|
83
84
|
group_id=group_id,
|
|
84
85
|
user_id=user_id,
|
|
85
86
|
duration=duration,
|
|
86
87
|
).send_to(self.connection)
|
|
88
|
+
logger.info(f"在群 {group_id} 将用户 {user_id} 禁言 {duration}s")
|
|
87
89
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
packet = Comm.Packet("get_login_info")
|
|
90
|
+
async def get_login_info(self) -> common.Ret[GetLoginInfoRsp]:
|
|
91
|
+
packet = common.Packet("get_login_info")
|
|
91
92
|
packet.send_to(self.connection)
|
|
92
|
-
return
|
|
93
|
+
return common.Ret.fetch(packet.echo, GetLoginInfoRsp)
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
packet = Comm.Packet("get_version_info")
|
|
95
|
+
async def get_version_info(self) -> common.Ret[GetVerInfoRsp]:
|
|
96
|
+
packet = common.Packet("get_version_info")
|
|
97
97
|
packet.send_to(self.connection)
|
|
98
|
-
return
|
|
98
|
+
return common.Ret.fetch(packet.echo, GetVerInfoRsp)
|
|
99
99
|
|
|
100
|
-
async def send_forward_msg(self, message:
|
|
101
|
-
packet =
|
|
100
|
+
async def send_forward_msg(self, message: common.Message) -> common.Ret[SendForwardRsp]:
|
|
101
|
+
packet = common.Packet(
|
|
102
102
|
"send_forward_msg",
|
|
103
103
|
messages=await message.get()
|
|
104
104
|
)
|
|
105
105
|
packet.send_to(self.connection)
|
|
106
|
-
return
|
|
106
|
+
return common.Ret.fetch(packet.echo, SendForwardRsp)
|
|
107
107
|
|
|
108
|
-
async def send_group_forward_msg(self, group_id: int, message:
|
|
109
|
-
packet =
|
|
108
|
+
async def send_group_forward_msg(self, group_id: int, message: common.Message) -> common.Ret[SendGrpForwardRsp]:
|
|
109
|
+
packet = common.Packet(
|
|
110
110
|
"send_group_forward_msg",
|
|
111
111
|
group_id=group_id,
|
|
112
112
|
messages=await message.get()
|
|
113
113
|
)
|
|
114
114
|
packet.send_to(self.connection)
|
|
115
|
-
return
|
|
115
|
+
return common.Ret.fetch(packet.echo, SendForwardRsp)
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
Comm.Packet(
|
|
117
|
+
async def set_group_add_request(self, flag: str, sub_type: str, approve: bool, reason: str = "Not Mentioned") -> None:
|
|
118
|
+
common.Packet(
|
|
120
119
|
"set_group_add_request",
|
|
121
120
|
flag=flag,
|
|
122
121
|
sub_type=sub_type,
|
|
123
122
|
approve=approve,
|
|
124
123
|
reason=reason
|
|
125
124
|
).send_to(self.connection)
|
|
125
|
+
logger.info(f"由于 {reason},{'通过' if approve else '拒绝'} {flag} 请求")
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
packet = Comm.Packet(
|
|
127
|
+
async def get_stranger_info(self, user_id: int) -> common.Ret[GetStrInfoRsp]:
|
|
128
|
+
packet = common.Packet(
|
|
130
129
|
"get_stranger_info",
|
|
131
130
|
user_id=user_id,
|
|
132
131
|
no_cache=True,
|
|
133
132
|
)
|
|
134
133
|
packet.send_to(self.connection)
|
|
135
|
-
return
|
|
134
|
+
return common.Ret.fetch(packet.echo, GetStrInfoRsp)
|
|
136
135
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
packet = Comm.Packet(
|
|
136
|
+
async def get_group_member_info(self, group_id: int, user_id: int) -> common.Ret[GetGrpMemInfoRsp]:
|
|
137
|
+
packet = common.Packet(
|
|
140
138
|
"get_group_member_info",
|
|
141
139
|
group_id=group_id,
|
|
142
140
|
user_id=user_id,
|
|
143
141
|
no_cache=True
|
|
144
142
|
)
|
|
145
143
|
packet.send_to(self.connection)
|
|
146
|
-
return
|
|
144
|
+
return common.Ret.fetch(packet.echo, GetGrpMemInfoRsp)
|
|
147
145
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
packet = Comm.Packet(
|
|
146
|
+
async def get_group_info(self, group_id: int) -> common.Ret[GetGrpInfoRsp]:
|
|
147
|
+
packet = common.Packet(
|
|
151
148
|
"get_group_info",
|
|
152
149
|
group_id=group_id,
|
|
153
150
|
no_cache=True
|
|
154
151
|
)
|
|
155
152
|
packet.send_to(self.connection)
|
|
156
|
-
return
|
|
153
|
+
return common.Ret.fetch(packet.echo, GetGrpInfoRsp)
|
|
157
154
|
|
|
158
|
-
async def get_status(self) ->
|
|
159
|
-
packet =
|
|
155
|
+
async def get_status(self) -> common.Ret:
|
|
156
|
+
packet = common.Packet("get_status")
|
|
160
157
|
packet.send_to(self.connection)
|
|
161
|
-
return
|
|
158
|
+
return common.Ret.fetch(packet.echo)
|
|
162
159
|
|
|
163
|
-
@Logger.AutoLogAsync.register(Logger.AutoLog.templates().set_ess, logger)
|
|
164
160
|
async def set_essence_msg(self, message_id: int) -> None:
|
|
165
|
-
|
|
161
|
+
common.Packet(
|
|
166
162
|
"set_essence_msg",
|
|
167
163
|
message_id=message_id
|
|
168
164
|
).send_to(self.connection)
|
|
169
165
|
|
|
170
166
|
async def set_group_special_title(self, group_id: int, user_id: int, title: str) -> None:
|
|
171
|
-
|
|
167
|
+
common.Packet(
|
|
172
168
|
"set_group_special_title",
|
|
173
169
|
group_id=group_id,
|
|
174
170
|
user_id=user_id,
|
|
175
171
|
special_title=title,
|
|
176
172
|
).send_to(self.connection)
|
|
177
173
|
|
|
178
|
-
async def get_msg(self, msg_id: int) ->
|
|
179
|
-
packet =
|
|
174
|
+
async def get_msg(self, msg_id: int) -> common.Ret[GetMsgRsp]:
|
|
175
|
+
packet = common.Packet(
|
|
180
176
|
"get_msg",
|
|
181
177
|
message_id=msg_id
|
|
182
178
|
)
|
|
183
179
|
packet.send_to(self.connection)
|
|
184
|
-
return
|
|
180
|
+
return common.Ret.fetch(packet.echo, GetMsgRsp)
|
|
185
181
|
|
|
186
182
|
|
|
187
183
|
async def tester(
|
|
@@ -197,7 +193,7 @@ def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
|
|
|
197
193
|
elif data.get("post_type") == "meta_event" or data.get("user_id") == data.get("self_id"):
|
|
198
194
|
pass
|
|
199
195
|
else:
|
|
200
|
-
asyncio.run(handler(
|
|
196
|
+
asyncio.run(handler(events.em.new(data), actions))
|
|
201
197
|
else:
|
|
202
198
|
asyncio.run(handler(data, actions))
|
|
203
199
|
|
|
@@ -210,7 +206,7 @@ def reg(func: callable) -> None:
|
|
|
210
206
|
handler = func
|
|
211
207
|
|
|
212
208
|
|
|
213
|
-
connection: Union[
|
|
209
|
+
connection: Union[network.WebsocketConnection, network.HTTPConnection]
|
|
214
210
|
|
|
215
211
|
|
|
216
212
|
class LagrangeOneBotService(IServiceBase):
|
|
@@ -218,7 +214,7 @@ class LagrangeOneBotService(IServiceBase):
|
|
|
218
214
|
def handler(self, func: FuncCall) -> Any:
|
|
219
215
|
pass
|
|
220
216
|
|
|
221
|
-
async def server(self, bot_config:
|
|
217
|
+
async def server(self, bot_config: configurator.BotConfig) -> None:
|
|
222
218
|
proc = subprocess.Popen(
|
|
223
219
|
args=config.connection.ob_exec,
|
|
224
220
|
cwd=config.connection.ob_startup_path,
|
|
@@ -234,12 +230,11 @@ def run() -> NoReturn:
|
|
|
234
230
|
listener_ran = True
|
|
235
231
|
try:
|
|
236
232
|
if handler is tester:
|
|
237
|
-
raise
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
connection = Network.HTTPConnection(
|
|
233
|
+
raise errors.ListenerNotRegisteredError("No handler registered")
|
|
234
|
+
if isinstance(config.connection, configurator.BotWSC):
|
|
235
|
+
connection = network.WebsocketConnection(f"ws://{config.connection.host}:{config.connection.port}")
|
|
236
|
+
elif isinstance(config.connection, configurator.BotHTTPC):
|
|
237
|
+
connection = network.HTTPConnection(
|
|
243
238
|
url=f"http://{config.connection.host}:{config.connection.port}",
|
|
244
239
|
listener_url=f"http://{config.connection.listener_host}:{config.connection.listener_port}"
|
|
245
240
|
)
|
|
@@ -252,19 +247,15 @@ def run() -> NoReturn:
|
|
|
252
247
|
connection.connect()
|
|
253
248
|
except ConnectionRefusedError or TimeoutError:
|
|
254
249
|
if retried >= config.connection.retries:
|
|
255
|
-
logger.
|
|
250
|
+
logger.critical(f"重试次数达到最大值({config.connection.retries}),退出")
|
|
256
251
|
break
|
|
257
252
|
|
|
258
|
-
logger.
|
|
259
|
-
level=Logger.levels.WARNING)
|
|
253
|
+
logger.warning(f"连接建立失败,3秒后重试({retried}/{config.connection.retries})")
|
|
260
254
|
retried += 1
|
|
261
255
|
time.sleep(3)
|
|
262
256
|
continue
|
|
263
257
|
retried = 0
|
|
264
|
-
logger.
|
|
265
|
-
f"成功在 {connection.url} 建立连接",
|
|
266
|
-
level=Logger.levels.INFO
|
|
267
|
-
)
|
|
258
|
+
logger.info(f"成功在 {connection.url} 建立连接")
|
|
268
259
|
actions = Actions(connection)
|
|
269
260
|
data = HyperListenerStartNotify(
|
|
270
261
|
time_now=int(time.time()),
|
|
@@ -276,16 +267,14 @@ def run() -> NoReturn:
|
|
|
276
267
|
try:
|
|
277
268
|
data = connection.recv()
|
|
278
269
|
except ConnectionResetError:
|
|
279
|
-
logger.
|
|
270
|
+
logger.error("连接断开")
|
|
280
271
|
break
|
|
281
272
|
except json.decoder.JSONDecodeError:
|
|
282
|
-
logger.
|
|
273
|
+
logger.error("收到错误的JSON内容")
|
|
283
274
|
continue
|
|
284
|
-
# threading.Thread(target=lambda: asyncio.run(__handler(data, actions))).start()
|
|
285
275
|
threading.Thread(target=lambda: __handler(data, actions), daemon=True).start()
|
|
286
|
-
# asyncio.create_task(__handler(data, actions))
|
|
287
276
|
except KeyboardInterrupt:
|
|
288
|
-
logger.
|
|
277
|
+
logger.warning("正在退出(Ctrl+C)")
|
|
289
278
|
try:
|
|
290
279
|
connection.close()
|
|
291
280
|
except:
|
|
@@ -298,4 +287,4 @@ def stop() -> None:
|
|
|
298
287
|
connection.close()
|
|
299
288
|
except:
|
|
300
289
|
pass
|
|
301
|
-
logger.log("停止运行监听器", level=
|
|
290
|
+
logger.log("停止运行监听器", level=hyperogger.levels.WARNING)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from ... import configurator, hyperogger, network
|
|
2
|
+
from ...utils import logic
|
|
3
|
+
from ...utils.hypetyping import OneBotJsonPacket
|
|
4
|
+
|
|
5
|
+
from typing import Union
|
|
6
|
+
import random
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
reports = logic.KeyQueue()
|
|
10
|
+
|
|
11
|
+
config: configurator.BotConfig
|
|
12
|
+
logger: hyperogger.Logger
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def init() -> None:
|
|
16
|
+
global config, logger
|
|
17
|
+
config = configurator.BotConfig.get("hyper-bot")
|
|
18
|
+
logger = hyperogger.Logger()
|
|
19
|
+
logger.set_level(config.log_level)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
servicing = []
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Packet:
|
|
26
|
+
def __init__(self, endpoint: str, **kwargs):
|
|
27
|
+
self.endpoint = endpoint
|
|
28
|
+
self.paras = kwargs
|
|
29
|
+
self.echo = f"{endpoint}_{random.randint(1000, 9999)}"
|
|
30
|
+
|
|
31
|
+
def send_to(self, connection: Union[network.WebsocketConnection, network.HTTPConnection]) -> None:
|
|
32
|
+
if isinstance(connection, network.WebsocketConnection):
|
|
33
|
+
payload: OneBotJsonPacket = {
|
|
34
|
+
"action": self.endpoint,
|
|
35
|
+
"params": self.paras,
|
|
36
|
+
"echo": self.echo,
|
|
37
|
+
}
|
|
38
|
+
connection.send(json.dumps(payload))
|
|
39
|
+
|
|
40
|
+
elif isinstance(connection, network.HTTPConnection):
|
|
41
|
+
payload = self.paras
|
|
42
|
+
connection.send(self.endpoint, payload, self.echo)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|