mioku-plugin-terraria 2.0.0 → 2.0.1
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.
- package/index.ts +74 -56
- package/package.json +2 -48
- package/utils/command-router.ts +0 -21
package/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { definePlugin, getService, Services, type MiokuContext } from "mioku";
|
|
|
2
2
|
import { handleStatus } from "./handlers/status";
|
|
3
3
|
import { handleSync } from "./handlers/sync";
|
|
4
4
|
import { handleReconnect } from "./handlers/reconnect";
|
|
5
|
-
import { parseTsCommand } from "./utils/command-router";
|
|
6
5
|
import { createConfigHandler } from "./utils/config-handler";
|
|
7
6
|
import {
|
|
8
7
|
formatQqToTerraria,
|
|
@@ -19,8 +18,6 @@ import { PROTOCOL, type TerrariaConfig, type TerrariaEvent } from "./types";
|
|
|
19
18
|
|
|
20
19
|
export default definePlugin({
|
|
21
20
|
name: "terraria",
|
|
22
|
-
version: "1.0.0",
|
|
23
|
-
description: "Terraria 服务器与 QQ 群消息互通插件,基于 TianSuo 协议",
|
|
24
21
|
|
|
25
22
|
async setup(ctx: MiokuContext) {
|
|
26
23
|
const configService = getService(ctx, Services.Config);
|
|
@@ -42,65 +39,86 @@ export default definePlugin({
|
|
|
42
39
|
serverManager.startServers(config);
|
|
43
40
|
ctx.logger.info("Terraria 插件已就绪");
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
const text = ctx.text(event).trim();
|
|
42
|
+
const requireGroup = (event: any): number | undefined => {
|
|
47
43
|
const groupId =
|
|
48
44
|
"group_id" in event && typeof event.group_id === "number"
|
|
49
45
|
? event.group_id
|
|
50
46
|
: undefined;
|
|
47
|
+
return groupId;
|
|
48
|
+
};
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
50
|
+
ctx.command({
|
|
51
|
+
name: "/ts 状态",
|
|
52
|
+
match: /^\/ts\s*状态(?:\s|$)/,
|
|
53
|
+
prefixes: false,
|
|
54
|
+
permission: "master",
|
|
55
|
+
description: "查看所有已配置服务器的 WebSocket 连接状态",
|
|
56
|
+
handler: async ({ event }) => {
|
|
57
|
+
if (!requireGroup(event)) return;
|
|
58
|
+
await handleStatus(serverManager, config, async (msg) => {
|
|
59
|
+
await event.reply(msg);
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
ctx.command({
|
|
64
|
+
name: "/ts 开启同步",
|
|
65
|
+
match: /^\/ts\s*开启同步(?:\s|$)/,
|
|
66
|
+
prefixes: false,
|
|
67
|
+
permission: "master",
|
|
68
|
+
description: "开启指定服务器的群聊消息同步功能",
|
|
69
|
+
usage: "/ts 开启同步 <服务器名称>",
|
|
70
|
+
handler: async ({ event, args }) => {
|
|
71
|
+
if (!requireGroup(event)) return;
|
|
72
|
+
await handleSync(
|
|
73
|
+
args[0],
|
|
74
|
+
true,
|
|
75
|
+
configHandler,
|
|
76
|
+
config,
|
|
77
|
+
async (msg) => {
|
|
78
|
+
await event.reply(msg);
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
ctx.command({
|
|
84
|
+
name: "/ts 关闭同步",
|
|
85
|
+
match: /^\/ts\s*关闭同步(?:\s|$)/,
|
|
86
|
+
prefixes: false,
|
|
87
|
+
permission: "master",
|
|
88
|
+
description: "关闭指定服务器的群聊消息同步功能",
|
|
89
|
+
usage: "/ts 关闭同步 <服务器名称>",
|
|
90
|
+
handler: async ({ event, args }) => {
|
|
91
|
+
if (!requireGroup(event)) return;
|
|
92
|
+
await handleSync(
|
|
93
|
+
args[0],
|
|
94
|
+
false,
|
|
95
|
+
configHandler,
|
|
96
|
+
config,
|
|
97
|
+
async (msg) => {
|
|
98
|
+
await event.reply(msg);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
ctx.command({
|
|
104
|
+
name: "/ts 重连",
|
|
105
|
+
match: /^\/ts\s*重连(?:\s|$)/,
|
|
106
|
+
prefixes: false,
|
|
107
|
+
permission: "master",
|
|
108
|
+
description: "断开并重新建立所有服务器的 WebSocket 连接",
|
|
109
|
+
handler: async ({ event }) => {
|
|
110
|
+
if (!requireGroup(event)) return;
|
|
111
|
+
await handleReconnect(serverManager, async (msg) => {
|
|
112
|
+
await event.reply(msg);
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
});
|
|
102
116
|
|
|
117
|
+
ctx.handle("message", async (event) => {
|
|
118
|
+
const groupId = requireGroup(event);
|
|
103
119
|
if (!groupId) return;
|
|
120
|
+
const text = ctx.text(event)?.trim();
|
|
121
|
+
if (text?.startsWith("/ts")) return;
|
|
104
122
|
await forwardToTerraria(ctx, event, config, configHandler, serverManager);
|
|
105
123
|
});
|
|
106
124
|
|
|
@@ -195,7 +213,7 @@ async function forwardToTerraria(
|
|
|
195
213
|
const isAllowed = isCommandAllowed(
|
|
196
214
|
commandText,
|
|
197
215
|
server,
|
|
198
|
-
ctx.
|
|
216
|
+
ctx.isMaster?.(event) ?? false,
|
|
199
217
|
event.user_id,
|
|
200
218
|
);
|
|
201
219
|
if (!isAllowed) continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mioku-plugin-terraria",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Terraria 服务器与 QQ 群消息互通插件,基于 TianSuo 协议",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -14,53 +14,7 @@
|
|
|
14
14
|
"mioku": {
|
|
15
15
|
"services": [
|
|
16
16
|
"config"
|
|
17
|
-
]
|
|
18
|
-
"accessHooks": [
|
|
19
|
-
{
|
|
20
|
-
"id": "/ts 状态",
|
|
21
|
-
"match": "/^\\/ts\\s*状态/"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"id": "/ts 开启同步",
|
|
25
|
-
"match": "/^\\/ts\\s*开启同步/"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"id": "/ts 关闭同步",
|
|
29
|
-
"match": "/^\\/ts\\s*关闭同步/"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"id": "/ts 重连",
|
|
33
|
-
"match": "/^\\/ts\\s*重连/"
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
"help": {
|
|
37
|
-
"title": "Terraria",
|
|
38
|
-
"description": "Terraria 服务器与 QQ 群消息互通插件,基于 TianSuo 协议",
|
|
39
|
-
"commands": [
|
|
40
|
-
{
|
|
41
|
-
"cmd": "/ts 状态",
|
|
42
|
-
"desc": "查看所有已配置服务器的 WebSocket 连接状态",
|
|
43
|
-
"role": "master"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"cmd": "/ts 开启同步 <服务器名称>",
|
|
47
|
-
"desc": "开启指定服务器的群聊消息同步功能",
|
|
48
|
-
"usage": "/ts 开启同步 <服务器名称>",
|
|
49
|
-
"role": "master"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"cmd": "/ts 关闭同步 <服务器名称>",
|
|
53
|
-
"desc": "关闭指定服务器的群聊消息同步功能",
|
|
54
|
-
"usage": "/ts 关闭同步 <服务器名称>",
|
|
55
|
-
"role": "master"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"cmd": "/ts 重连",
|
|
59
|
-
"desc": "断开并重新建立所有服务器的 WebSocket 连接",
|
|
60
|
-
"role": "master"
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
}
|
|
17
|
+
]
|
|
64
18
|
},
|
|
65
19
|
"dependencies": {
|
|
66
20
|
"ws": "^8.18.0"
|
package/utils/command-router.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface ParsedCommand {
|
|
2
|
-
action: string;
|
|
3
|
-
args: string[];
|
|
4
|
-
raw: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function parseTsCommand(text: string): ParsedCommand | null {
|
|
8
|
-
const trimmed = text.trim();
|
|
9
|
-
if (!trimmed.startsWith("/ts")) return null;
|
|
10
|
-
|
|
11
|
-
const remainder = trimmed.slice(3).trim();
|
|
12
|
-
if (!remainder) {
|
|
13
|
-
return { action: "", args: [], raw: "" };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const parts = remainder.split(/\s+/);
|
|
17
|
-
const action = parts[0] || "";
|
|
18
|
-
const args = parts.slice(1);
|
|
19
|
-
|
|
20
|
-
return { action, args, raw: remainder };
|
|
21
|
-
}
|