Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 前置_基本插件功能库/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import uuid
import threading
from tooldelta import Plugin, constants, utils, Chat, Player, plugin_entry
from tooldelta.constants.netease import PYRPC_OP_SEND

try:
from tooldelta.mc_bytes_packet.py_rpc import PYRPC_OP_SEND
except ImportError:
from tooldelta.constants.netease import PYRPC_OP_SEND # type: ignore

if 0:
from tooldelta.internal.types import Packet_CommandOutput
Expand All @@ -16,7 +20,7 @@ def find_key_from_value(dic, val):


class BasicFunctionLib(Plugin):
version = (0, 0, 12)
version = (0, 0, 13)
name = "基本插件功能库"
author = "SuperScript"
description = "提供额外的方法用于获取游戏数据"
Expand Down
2 changes: 1 addition & 1 deletion 前置_基本插件功能库/datas.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"author": "SuperScript",
"version": "0.0.12",
"version": "0.0.13",
"description": "所有使用基本组件API的插件的前置",
"limit_launcher": null,
"pre-plugins": {},
Expand Down
33 changes: 27 additions & 6 deletions 控制台执行MC指令/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
class ConsoleCommands(Plugin):
name = "控制台执行MC指令"
author = "SuperScript"
version = (0, 0, 5)
version = (0, 0, 6)

def __init__(self, frame: Frame):
self.frame = frame
self.game_ctrl = frame.get_game_control()
self.ListenPreload(self.on_def)
self.ListenActive(self.on_inject)

def on_def(self):
self.funclib = self.GetPluginAPI("基本插件功能库")

def on_inject(self):
self.frame.add_console_cmd_trigger(
["ws/"], "[指令]", "执行WS指令", self.SendWSCmdOnConsole
Expand Down Expand Up @@ -59,7 +55,32 @@ def SendWOCmdOnConsole(self, cmd):
self.game_ctrl.sendwocmd(" ".join(cmd))

def SendAICmdOnConsole(self, cmd):
self.funclib.sendaicmd(" ".join(cmd))
try:
result = self.game_ctrl.sendaicmd_with_resp(" ".join(cmd), 5)
except IndexError:
Print.print_err("缺少指令参数")
return
try:
if (result.OutputMessages[0].Message == "commands.generic.syntax") | (
result.OutputMessages[0].Message == "commands.generic.unknown"
):
Print.print_err("未知的MC指令, 可能是指令格式有误")
else:
jso = json.dumps(
result.as_dict["OutputMessages"], indent=2, ensure_ascii=False
)
if not result.SuccessCount:
Print.print_war(f"指令执行失败:\n{jso}")
else:
Print.print_suc(f"指令执行成功: \n{jso}")
except IndexError:
if result.SuccessCount:
jso = json.dumps(
result.as_dict["OutputMessages"], indent=2, ensure_ascii=False
)
Print.print_suc(f"指令执行成功: \n{jso}")
except TimeoutError:
Print.print_err("[超时] 指令获取结果返回超时")


entry = plugin_entry(ConsoleCommands)
6 changes: 2 additions & 4 deletions 控制台执行MC指令/datas.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"author": "SuperScript",
"version": "0.0.5",
"version": "0.0.6",
"description": "可以在控制台让机器人执行特殊指令等, 还可以发送魔法(AI)指令\n - ws/: 发送 WebSocket 指令\n - ai/ 发送 ai 指令",
"limit_launcher": null,
"pre-plugins": {
"基本插件功能库": "0.0.12"
},
"pre-plugins": {},
"plugin-type": "classic",
"plugin-id": "控制台执行MC指令",
"enabled": true
Expand Down