hyper-bot 0.82.0__tar.gz → 0.82.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.82.0 → hyper_bot-0.82.2}/PKG-INFO +1 -1
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyper_bot.egg-info/PKG-INFO +1 -1
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/LecAdapters/Milky.py +12 -2
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/LecAdapters/OneBot.py +19 -8
- hyper_bot-0.82.2/hyperot/__init__.py +147 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/adapters/listener.py +12 -2
- hyper_bot-0.82.0/hyperot/__init__.py +0 -95
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/LICENSE +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyper_bot.egg-info/SOURCES.txt +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyper_bot.egg-info/dependency_links.txt +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyper_bot.egg-info/requires.txt +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyper_bot.egg-info/top_level.txt +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/LecAdapters/MilkyLib/Manager.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/LecAdapters/MilkyLib/Res.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/LecAdapters/MilkyLib/translator.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/LecAdapters/OneBotLib/Manager.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/LecAdapters/OneBotLib/Res.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/adapters/__init__.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/adapters/builtins.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/adapters/common.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/adapters/obuilder.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/adapters/res.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/common.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/configurator.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/events.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/hyperogger.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/listener.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/network.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/segments.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/service.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/utils/ArkSignHelper.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/utils/apiresponse.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/utils/errors.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/utils/hypetyping.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/utils/logic.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/utils/screens.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/hyperot/utils/typextensions.py +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/setup.cfg +0 -0
- {hyper_bot-0.82.0 → hyper_bot-0.82.2}/setup.py +0 -0
|
@@ -40,7 +40,7 @@ class Actions:
|
|
|
40
40
|
|
|
41
41
|
self.custom = CustomAction(self.connection)
|
|
42
42
|
|
|
43
|
-
async def
|
|
43
|
+
async def send_msg(
|
|
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:
|
|
@@ -65,8 +65,18 @@ class Actions:
|
|
|
65
65
|
ret = common.Ret(res)
|
|
66
66
|
ret.data = MsgSendRsp({"message_id": msg_enid(1, res["message_seq"], group_id)})
|
|
67
67
|
return ret
|
|
68
|
+
|
|
69
|
+
async def send_group_msg(
|
|
70
|
+
self, message: Union[common.Message, str], group_id: int = None
|
|
71
|
+
) -> common.Ret[MsgSendRsp]:
|
|
72
|
+
return await self.send_msg(message, group_id=group_id)
|
|
68
73
|
|
|
69
|
-
async def
|
|
74
|
+
async def send_private_msg(
|
|
75
|
+
self, message: Union[common.Message, str], user_id: int = None
|
|
76
|
+
) -> common.Ret[MsgSendRsp]:
|
|
77
|
+
return await self.send_msg(message, user_id=user_id)
|
|
78
|
+
|
|
79
|
+
async def del_msg(self, message_id: int) -> None:
|
|
70
80
|
...
|
|
71
81
|
|
|
72
82
|
async def set_group_kick(self, group_id: int, user_id: int) -> None:
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import json
|
|
2
|
-
import threading
|
|
3
2
|
import time
|
|
4
3
|
import asyncio
|
|
5
4
|
import sys
|
|
@@ -11,7 +10,7 @@ from ..utils import errors, logic
|
|
|
11
10
|
from ..utils.apiresponse import *
|
|
12
11
|
from ..LecAdapters.OneBotLib.Manager import reports, Packet
|
|
13
12
|
from ..events import *
|
|
14
|
-
from ..utils.hypetyping import Any, Union, NoReturn
|
|
13
|
+
from ..utils.hypetyping import Any, Union, NoReturn, Callable
|
|
15
14
|
|
|
16
15
|
config = configurator.BotConfig.get("hyper-bot")
|
|
17
16
|
logger = hyperogger.Logger()
|
|
@@ -27,7 +26,7 @@ class Actions:
|
|
|
27
26
|
def __init__(self, cnt_i: Union[network.WebsocketConnection, network.HTTPConnection]):
|
|
28
27
|
self.connection = cnt_i
|
|
29
28
|
|
|
30
|
-
def __getattr__(self, item) ->
|
|
29
|
+
def __getattr__(self, item) -> Callable:
|
|
31
30
|
async def wrapper(**kwargs) -> str:
|
|
32
31
|
packet = Packet(
|
|
33
32
|
str(item),
|
|
@@ -40,7 +39,7 @@ class Actions:
|
|
|
40
39
|
|
|
41
40
|
self.custom = CustomAction(self.connection)
|
|
42
41
|
|
|
43
|
-
async def
|
|
42
|
+
async def send_msg(
|
|
44
43
|
self, message: Union[common.Message, str], group_id: int = None, user_id: int = None
|
|
45
44
|
) -> common.Ret[MsgSendRsp]:
|
|
46
45
|
if isinstance(message, str):
|
|
@@ -63,7 +62,17 @@ class Actions:
|
|
|
63
62
|
logger.info(f"向{(('群 ' + str(group_id)) if group_id else ('用户' + str(user_id))) + ' '}发送:{str(message)}")
|
|
64
63
|
return await common.Ret.fetch(packet.echo, MsgSendRsp)
|
|
65
64
|
|
|
66
|
-
async def
|
|
65
|
+
async def send_group_msg(
|
|
66
|
+
self, message: Union[common.Message, str], group_id: int = None
|
|
67
|
+
) -> common.Ret[MsgSendRsp]:
|
|
68
|
+
return await self.send_msg(message, group_id=group_id)
|
|
69
|
+
|
|
70
|
+
async def send_private_msg(
|
|
71
|
+
self, message: Union[common.Message, str], user_id: int = None
|
|
72
|
+
) -> common.Ret[MsgSendRsp]:
|
|
73
|
+
return await self.send_msg(message, user_id=user_id)
|
|
74
|
+
|
|
75
|
+
async def del_msg(self, message_id: int) -> None:
|
|
67
76
|
await Packet(
|
|
68
77
|
"delete_msg",
|
|
69
78
|
message_id=message_id,
|
|
@@ -227,10 +236,10 @@ async def __handler(data: Union[dict, HyperNotify], actions: Actions) -> None:
|
|
|
227
236
|
await handler(data, actions)
|
|
228
237
|
|
|
229
238
|
|
|
230
|
-
handler:
|
|
239
|
+
handler: Callable = tester
|
|
231
240
|
|
|
232
241
|
|
|
233
|
-
def reg(func:
|
|
242
|
+
def reg(func: Callable) -> None:
|
|
234
243
|
global handler
|
|
235
244
|
handler = func
|
|
236
245
|
|
|
@@ -244,6 +253,8 @@ class LagrangeOneBotService(IServiceBase):
|
|
|
244
253
|
pass
|
|
245
254
|
|
|
246
255
|
async def server(self, bot_config: configurator.BotConfig) -> None:
|
|
256
|
+
if isinstance(config.connection, dict):
|
|
257
|
+
raise errors.ListenerNotRegisteredError("未注册接收器")
|
|
247
258
|
proc = subprocess.Popen(
|
|
248
259
|
args=config.connection.ob_exec,
|
|
249
260
|
cwd=config.connection.ob_startup_path,
|
|
@@ -274,7 +285,7 @@ async def run() -> NoReturn:
|
|
|
274
285
|
while True:
|
|
275
286
|
try:
|
|
276
287
|
connection.connect()
|
|
277
|
-
except ConnectionRefusedError
|
|
288
|
+
except (ConnectionRefusedError, TimeoutError):
|
|
278
289
|
if retried >= config.connection.retries:
|
|
279
290
|
logger.critical(f"重试次数达到最大值({config.connection.retries}),退出")
|
|
280
291
|
break
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
from . import configurator
|
|
2
|
+
from .utils import screens
|
|
3
|
+
|
|
4
|
+
from typing import Union, Callable
|
|
5
|
+
import asyncio
|
|
6
|
+
import sys
|
|
7
|
+
import os
|
|
8
|
+
import signal
|
|
9
|
+
|
|
10
|
+
HYPER_BOT_VERSION = "0.82.2"
|
|
11
|
+
|
|
12
|
+
# listener = None
|
|
13
|
+
|
|
14
|
+
screens.play_startup()
|
|
15
|
+
screens.play_info(HYPER_BOT_VERSION)
|
|
16
|
+
|
|
17
|
+
ANY_EVENT = Union[
|
|
18
|
+
"events.GroupMessageEvent",
|
|
19
|
+
"events.PrivateMessageEvent",
|
|
20
|
+
"events.GroupFileUploadEvent",
|
|
21
|
+
"events.GroupAdminEvent",
|
|
22
|
+
"events.GroupMemberDecreaseEvent",
|
|
23
|
+
"events.GroupMemberIncreaseEvent",
|
|
24
|
+
"events.GroupMuteEvent",
|
|
25
|
+
"events.FriendAddEvent",
|
|
26
|
+
"events.GroupRecallEvent",
|
|
27
|
+
"events.FriendRecallEvent",
|
|
28
|
+
"events.NotifyEvent",
|
|
29
|
+
"events.GroupEssenceEvent",
|
|
30
|
+
"events.MessageReactionEvent",
|
|
31
|
+
"events.GroupAddInviteEvent",
|
|
32
|
+
"events.HyperListenerStartNotify",
|
|
33
|
+
"events.HyperListenerStopNotify"
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Client:
|
|
38
|
+
def __init__(self):
|
|
39
|
+
self.records = {}
|
|
40
|
+
self.lis = None
|
|
41
|
+
|
|
42
|
+
def subscribe(
|
|
43
|
+
self,
|
|
44
|
+
func: Callable,
|
|
45
|
+
event: Union[ANY_EVENT, list[ANY_EVENT]]
|
|
46
|
+
) -> None:
|
|
47
|
+
if isinstance(event, list):
|
|
48
|
+
for e in event:
|
|
49
|
+
self._subscribe(func, e)
|
|
50
|
+
else:
|
|
51
|
+
self._subscribe(func, event)
|
|
52
|
+
|
|
53
|
+
def _subscribe(self, func: Callable, event: ANY_EVENT) -> None:
|
|
54
|
+
if not self.records.get(event):
|
|
55
|
+
self.records[event] = [func]
|
|
56
|
+
else:
|
|
57
|
+
self.records[event].append(func)
|
|
58
|
+
|
|
59
|
+
async def distributor(
|
|
60
|
+
self, message_data: Union["events.Event", "events.HyperNotify"], actions: "Listener.Actions"
|
|
61
|
+
) -> None:
|
|
62
|
+
if type(message_data) in list(self.records.keys()):
|
|
63
|
+
tasks = []
|
|
64
|
+
for i in self.records[type(message_data)]:
|
|
65
|
+
tasks.append(asyncio.create_task(i(message_data, actions)))
|
|
66
|
+
await asyncio.gather(*tasks)
|
|
67
|
+
else:
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
async def run(self):
|
|
71
|
+
from . import listener
|
|
72
|
+
self.lis = listener
|
|
73
|
+
self.lis.reg(self.distributor)
|
|
74
|
+
if self.records:
|
|
75
|
+
stop = asyncio.Event()
|
|
76
|
+
loop = asyncio.get_running_loop()
|
|
77
|
+
_wakeup_task = None
|
|
78
|
+
if sys.platform == "win32":
|
|
79
|
+
def _win32_handler(signum, frame):
|
|
80
|
+
stop.set()
|
|
81
|
+
|
|
82
|
+
signal.signal(signal.SIGINT, _win32_handler)
|
|
83
|
+
try:
|
|
84
|
+
signal.signal(signal.SIGBREAK, _win32_handler)
|
|
85
|
+
except AttributeError:
|
|
86
|
+
pass
|
|
87
|
+
|
|
88
|
+
async def _win32_wakeup():
|
|
89
|
+
while 1:
|
|
90
|
+
await asyncio.sleep(0.1)
|
|
91
|
+
|
|
92
|
+
_wakeup_task = asyncio.create_task(_win32_wakeup())
|
|
93
|
+
else:
|
|
94
|
+
for i in (signal.SIGINT, signal.SIGTERM):
|
|
95
|
+
loop.add_signal_handler(i, stop.set)
|
|
96
|
+
task = asyncio.create_task(self.lis.run())
|
|
97
|
+
await stop.wait()
|
|
98
|
+
if _wakeup_task:
|
|
99
|
+
_wakeup_task.cancel()
|
|
100
|
+
task.cancel()
|
|
101
|
+
try:
|
|
102
|
+
await task
|
|
103
|
+
except asyncio.CancelledError:
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
def restart(self) -> None:
|
|
107
|
+
self.lis.stop()
|
|
108
|
+
os.execv(sys.executable, [sys.executable] + sys.argv)
|
|
109
|
+
# os._exit(1)
|
|
110
|
+
|
|
111
|
+
def __enter__(self):
|
|
112
|
+
return self
|
|
113
|
+
|
|
114
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
async def __aenter__(self):
|
|
118
|
+
return self
|
|
119
|
+
|
|
120
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
121
|
+
pass
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def init(cfg_file: str = "config.json") -> "hyperogger.Logger":
|
|
125
|
+
from cfgr.manager import Serializers
|
|
126
|
+
try:
|
|
127
|
+
configurator.BotConfig.load_from(cfg_file, Serializers.JSON, "hyper-bot")
|
|
128
|
+
except FileNotFoundError:
|
|
129
|
+
configurator.BotConfig.create_and_write(cfg_file, Serializers.JSON)
|
|
130
|
+
print("没有找到配置文件,已自动创建,请填写后重启")
|
|
131
|
+
exit(-1)
|
|
132
|
+
|
|
133
|
+
if True:
|
|
134
|
+
from hyperot import hyperogger
|
|
135
|
+
from hyperot.adapters import builtins as adp
|
|
136
|
+
|
|
137
|
+
config = configurator.BotConfig.get("hyper-bot")
|
|
138
|
+
logger = hyperogger.Logger()
|
|
139
|
+
logger.set_level(config.log_level)
|
|
140
|
+
|
|
141
|
+
match config.protocol:
|
|
142
|
+
case "OneBot":
|
|
143
|
+
adp.load_onebot()
|
|
144
|
+
case _:
|
|
145
|
+
raise NotImplementedError
|
|
146
|
+
|
|
147
|
+
return logger
|
|
@@ -12,12 +12,22 @@ class Actions:
|
|
|
12
12
|
def __init__(self):
|
|
13
13
|
self.custom: type
|
|
14
14
|
|
|
15
|
-
async def
|
|
15
|
+
async def send_msg(
|
|
16
16
|
self, message: Union[common.Message, str], group_id: int = None, user_id: int = None
|
|
17
17
|
) -> common.Ret[MsgSendRsp]:
|
|
18
18
|
...
|
|
19
19
|
|
|
20
|
-
async def
|
|
20
|
+
async def send_group_msg(
|
|
21
|
+
self, message: Union[common.Message, str], group_id: int = None
|
|
22
|
+
) -> common.Ret[MsgSendRsp]:
|
|
23
|
+
...
|
|
24
|
+
|
|
25
|
+
async def send_private_msg(
|
|
26
|
+
self, message: Union[common.Message, str], user_id: int = None
|
|
27
|
+
) -> common.Ret[MsgSendRsp]:
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
async def del_msg(self, message_id: int) -> None:
|
|
21
31
|
...
|
|
22
32
|
|
|
23
33
|
async def set_group_kick(self, group_id: int, user_id: int) -> None:
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import signal
|
|
2
|
-
from asyncio import tasks
|
|
3
|
-
|
|
4
|
-
from . import configurator
|
|
5
|
-
from .utils import screens
|
|
6
|
-
|
|
7
|
-
from typing import Union
|
|
8
|
-
import asyncio
|
|
9
|
-
import sys
|
|
10
|
-
import os
|
|
11
|
-
|
|
12
|
-
HYPER_BOT_VERSION = "0.82.0"
|
|
13
|
-
|
|
14
|
-
# listener = None
|
|
15
|
-
|
|
16
|
-
screens.play_startup()
|
|
17
|
-
screens.play_info(HYPER_BOT_VERSION)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class Client:
|
|
21
|
-
def __init__(self):
|
|
22
|
-
self.records = {}
|
|
23
|
-
self.lis = None
|
|
24
|
-
|
|
25
|
-
def subscribe(
|
|
26
|
-
self,
|
|
27
|
-
func: callable,
|
|
28
|
-
event: Union[
|
|
29
|
-
"events.GroupMessageEvent",
|
|
30
|
-
"events.PrivateMessageEvent",
|
|
31
|
-
"events.GroupFileUploadEvent",
|
|
32
|
-
"events.GroupAdminEvent",
|
|
33
|
-
"events.GroupMemberDecreaseEvent",
|
|
34
|
-
"events.GroupMemberIncreaseEvent",
|
|
35
|
-
"events.GroupMuteEvent",
|
|
36
|
-
"events.FriendAddEvent",
|
|
37
|
-
"events.GroupRecallEvent",
|
|
38
|
-
"events.FriendRecallEvent",
|
|
39
|
-
"events.NotifyEvent",
|
|
40
|
-
"events.GroupEssenceEvent",
|
|
41
|
-
"events.MessageReactionEvent",
|
|
42
|
-
"events.GroupAddInviteEvent",
|
|
43
|
-
"events.HyperListenerStartNotify",
|
|
44
|
-
"events.HyperListenerStopNotify"
|
|
45
|
-
]
|
|
46
|
-
) -> None:
|
|
47
|
-
if not self.records.get(event):
|
|
48
|
-
self.records[event] = [func]
|
|
49
|
-
else:
|
|
50
|
-
self.records[event].append(func)
|
|
51
|
-
|
|
52
|
-
async def distributor(
|
|
53
|
-
self, message_data: Union["events.Event", "events.HyperNotify"], actions: "Listener.Actions"
|
|
54
|
-
) -> None:
|
|
55
|
-
if type(message_data) in list(self.records.keys()):
|
|
56
|
-
tasks = []
|
|
57
|
-
for i in self.records[type(message_data)]:
|
|
58
|
-
tasks.append(asyncio.create_task(i(message_data, actions)))
|
|
59
|
-
await asyncio.gather(*tasks)
|
|
60
|
-
else:
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
async def run(self):
|
|
64
|
-
from . import listener
|
|
65
|
-
self.lis = listener
|
|
66
|
-
self.lis.reg(self.distributor)
|
|
67
|
-
if self.records:
|
|
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
|
|
79
|
-
|
|
80
|
-
def restart(self) -> None:
|
|
81
|
-
self.lis.stop()
|
|
82
|
-
os.execv(sys.executable, [sys.executable] + sys.argv)
|
|
83
|
-
# os._exit(1)
|
|
84
|
-
|
|
85
|
-
def __enter__(self):
|
|
86
|
-
return self
|
|
87
|
-
|
|
88
|
-
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
89
|
-
pass
|
|
90
|
-
|
|
91
|
-
async def __aenter__(self):
|
|
92
|
-
return self
|
|
93
|
-
|
|
94
|
-
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
95
|
-
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|