2
This commit is contained in:
19
base_plugins/echo.py
Normal file
19
base_plugins/echo.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from core.command_manager import matcher
|
||||
#TODO 把该死的这些给抽象化
|
||||
@matcher.command("echo")
|
||||
async def handle_echo(bot, event, args):
|
||||
if not args:
|
||||
reply_msg = "请在指令后输入要回复的内容,例如:/echo 你好"
|
||||
else:
|
||||
reply_msg = " ".join(args)
|
||||
|
||||
if event.message_type == "group":
|
||||
await bot.call_api("send_group_msg", {
|
||||
"group_id": event.group_id,
|
||||
"message": reply_msg
|
||||
})
|
||||
else:
|
||||
await bot.call_api("send_private_msg", {
|
||||
"user_id": event.user_id,
|
||||
"message": reply_msg
|
||||
})
|
||||
11
core/ws.py
11
core/ws.py
@@ -84,11 +84,14 @@ class WS:
|
||||
print(f" 事件分发失败: {e}")
|
||||
|
||||
async def call_api(self, action: str, params: dict = None):
|
||||
"""公有 API:供插件调用,发送指令并异步等待结果"""
|
||||
if not self.ws or self.ws.closed:
|
||||
return {"status": "failed", "msg": "websocket not connected"}
|
||||
if not self.ws:
|
||||
return {"status": "failed", "msg": "websocket not initialized"}
|
||||
|
||||
# 检查 websockets 13.x+ 的状态属性
|
||||
from websockets.protocol import State
|
||||
if getattr(self.ws, "state", None) is not State.OPEN:
|
||||
return {"status": "failed", "msg": "websocket is not open"}
|
||||
|
||||
# 创建唯一的 echo ID
|
||||
echo_id = str(uuid.uuid4())
|
||||
payload = {
|
||||
"action": action,
|
||||
|
||||
2
main.py
2
main.py
@@ -1,7 +1,7 @@
|
||||
# main.py
|
||||
import asyncio
|
||||
from core import WS
|
||||
|
||||
import base_plugins
|
||||
async def main():
|
||||
bot = WS()
|
||||
await bot.connect()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#TODO 数据类型
|
||||
@@ -1,5 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
#TODO 数据类型
|
||||
@dataclass
|
||||
class Sender:
|
||||
user_id: int
|
||||
|
||||
Reference in New Issue
Block a user