mioku-plugin-mc 4.0.1 → 4.0.2

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/core/rcon.ts CHANGED
@@ -24,7 +24,7 @@ export function isCommandAllowed(
24
24
  text: string,
25
25
  serverItem: ServerConfig,
26
26
  isMaster: boolean,
27
- userId: number | string,
27
+ userId: string,
28
28
  ): boolean {
29
29
  if (isMaster) return true;
30
30
 
package/index.ts CHANGED
@@ -63,10 +63,7 @@ export default definePlugin({
63
63
 
64
64
  ctx.handle("message", async (event) => {
65
65
  const text = ctx.text(event).trim();
66
- const groupId =
67
- "group_id" in event && typeof event.group_id === "number"
68
- ? event.group_id
69
- : undefined;
66
+ const groupId = String(event.group_id ?? "").trim() || undefined;
70
67
 
71
68
  if (groupId) {
72
69
  const reply = await handleDebugCommand({
@@ -74,7 +71,7 @@ export default definePlugin({
74
71
  isMaster: ctx.isMaster?.(event) ?? false,
75
72
  debugEnabled: playConfigHandler.getConfig().debug.enabled,
76
73
  playManager,
77
- groupId: Number(groupId),
74
+ groupId,
78
75
  });
79
76
  if (reply !== null) {
80
77
  await event.reply(reply);
@@ -95,8 +92,8 @@ export default definePlugin({
95
92
  ctx.command({
96
93
  id: "mc-status",
97
94
  name: "mc-status",
98
- match: /^\/mc\s+状态\s*$/,
99
- prefixes: ["/"],
95
+ prefixes: ["/", "."],
96
+ match: /^mc\s+状态\s*$/,
100
97
  permission: "master",
101
98
  description: "查看所有已配置服务器的WebSocket连接状态,包括连接中、已断开等",
102
99
  async handler({ event }) {
@@ -107,10 +104,10 @@ export default definePlugin({
107
104
  ctx.command({
108
105
  id: "mc-sync-on",
109
106
  name: "mc-sync-on",
110
- match: /^\/mc\s+开启同步(?:\s+(.+))?$/,
111
- prefixes: ["/"],
107
+ prefixes: ["/", "."],
108
+ match: /^mc\s+开启同步(?:\s+(.+))?$/,
112
109
  description: "开启指定服务器的群聊消息同步功能,开启后该服务器可接收和发送群聊消息",
113
- usage: "/mc 开启同步 <服务器名称>",
110
+ usage: ".mc 开启同步 <服务器名称>",
114
111
  permission: "master",
115
112
  async handler({ event, args }) {
116
113
  await handleSync(args[0], true, serverManager, configHandler, config, replyWithEvent(event));
@@ -120,10 +117,10 @@ export default definePlugin({
120
117
  ctx.command({
121
118
  id: "mc-sync-off",
122
119
  name: "mc-sync-off",
123
- match: /^\/mc\s+关闭同步(?:\s+(.+))?$/,
124
- prefixes: ["/"],
120
+ prefixes: ["/", "."],
121
+ match: /^mc\s+关闭同步(?:\s+(.+))?$/,
125
122
  description: "关闭指定服务器的群聊消息同步功能,关闭后该服务器不再接收和发送群聊消息",
126
- usage: "/mc 关闭同步 <服务器名称>",
123
+ usage: ".mc 关闭同步 <服务器名称>",
127
124
  permission: "master",
128
125
  async handler({ event, args }) {
129
126
  await handleSync(args[0], false, serverManager, configHandler, config, replyWithEvent(event));
@@ -133,8 +130,8 @@ export default definePlugin({
133
130
  ctx.command({
134
131
  id: "mc-reconnect",
135
132
  name: "mc-reconnect",
136
- match: /^\/mc\s+重连\s*$/,
137
- prefixes: ["/"],
133
+ prefixes: ["/", "."],
134
+ match: /^mc\s+重连\s*$/,
138
135
  permission: "master",
139
136
  description: "断开并重新建立所有服务器的WebSocket连接,用于连接异常时手动恢复",
140
137
  async handler({ event }) {
@@ -198,9 +195,10 @@ async function forwardToMc(
198
195
  const text = ctx.text(event);
199
196
  ctx.logger.debug(`[MC] 收到群消息 group=${event.group_id} text=${text}`);
200
197
 
201
- if (!event.group_id) return;
198
+ const groupId = String(event.group_id ?? "").trim();
199
+ if (!groupId) return;
202
200
 
203
- const servers = configHandler.getServersForGroup(event.group_id);
201
+ const servers = configHandler.getServersForGroup(groupId);
204
202
  if (servers.length === 0) return;
205
203
 
206
204
  const msgList = Array.isArray(event.message)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-plugin-mc",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Minecraft与QQ群消息互通插件,支持服务器状态监控与RCON命令",
5
5
  "main": "index.ts",
6
6
  "type": "module",
package/play/ai/prompt.ts CHANGED
@@ -126,7 +126,7 @@ function describeTerminator(t: WorkTerminator): string {
126
126
  export function buildSessionFacts(input: {
127
127
  serverName: string;
128
128
  username: string;
129
- groupId: number;
129
+ groupId: string;
130
130
  maxPlayMs: number;
131
131
  allowedCommands: string[];
132
132
  }): string {
package/play/config.ts CHANGED
@@ -27,10 +27,12 @@ export function createPlayConfigHandler(configService: ConfigService | undefined
27
27
  return currentConfig.servers.find((s) => s.id === id) ?? null;
28
28
  };
29
29
 
30
- const findBinding = (groupId: number | string): GroupBinding | null => {
31
- const gid = Number(groupId);
32
- if (!Number.isFinite(gid) || gid <= 0) return null;
33
- return currentConfig.groups.find((g) => g.groupId === gid) ?? null;
30
+ const findBinding = (groupId: string | number): GroupBinding | null => {
31
+ const gid = String(groupId ?? "").trim();
32
+ if (!gid) return null;
33
+ return (
34
+ currentConfig.groups.find((g) => String(g.groupId) === gid) ?? null
35
+ );
34
36
  };
35
37
 
36
38
  return { register, getConfig, findServer, findBinding };
@@ -5,7 +5,7 @@ export interface DebugCommandContext {
5
5
  isMaster: boolean;
6
6
  debugEnabled: boolean;
7
7
  playManager: PlayManager;
8
- groupId: number;
8
+ groupId: string;
9
9
  }
10
10
 
11
11
  const OVERLAY_NAMES = ["defend", "auto_eat"];
package/play/index.ts CHANGED
@@ -41,7 +41,7 @@ export class PlayManager {
41
41
  private readonly configService: ConfigService | undefined;
42
42
  private readonly playConfigHandler: PlayConfigHandler;
43
43
  private readonly syncConfigHandler: ConfigHandler;
44
- private readonly sessions = new Map<number, PlaySession>();
44
+ private readonly sessions = new Map<string, PlaySession>();
45
45
  private mainInstance?: AIInstance;
46
46
  private workInstance?: AIInstance;
47
47
 
@@ -100,7 +100,7 @@ export class PlayManager {
100
100
  }
101
101
 
102
102
  async enter(
103
- groupId: number,
103
+ groupId: string,
104
104
  serverId: string,
105
105
  opts: { debug?: boolean } = {},
106
106
  ): Promise<PlayEnterResult> {
@@ -180,7 +180,7 @@ export class PlayManager {
180
180
  return { success: true, serverId: server.id, message: `已进入 ${server.name}${mode}` };
181
181
  }
182
182
 
183
- async exit(groupId: number): Promise<PlayExitResult> {
183
+ async exit(groupId: string): Promise<PlayExitResult> {
184
184
  const session = this.sessions.get(groupId);
185
185
  if (!session || session.isStopped) {
186
186
  return { success: false, message: "当前没有进行中的 mc 会话" };
@@ -191,8 +191,8 @@ export class PlayManager {
191
191
  }
192
192
 
193
193
  onQqMessage(event: any): void {
194
- const groupId = Number(event?.group_id);
195
- if (!Number.isFinite(groupId) || groupId <= 0) return;
194
+ const groupId = String(event?.group_id ?? "").trim();
195
+ if (!groupId) return;
196
196
  const session = this.sessions.get(groupId);
197
197
  if (!session || session.isStopped) return;
198
198
  const text = String(event?.raw_message ?? event?.message ?? "").trim();
@@ -206,7 +206,7 @@ export class PlayManager {
206
206
  return [...this.sessions.values()].map((s) => s.getStatus());
207
207
  }
208
208
 
209
- getActiveSession(groupId: number): PlaySession | undefined {
209
+ getActiveSession(groupId: string): PlaySession | undefined {
210
210
  const s = this.sessions.get(groupId);
211
211
  return s && !s.isStopped ? s : undefined;
212
212
  }
@@ -231,7 +231,7 @@ export function createPlayManager(opts: PlayManagerOptions): PlayManager {
231
231
  function detectQqAtBot(
232
232
  event: any,
233
233
  botName: string,
234
- botSelfId: number | undefined,
234
+ botSelfId: string | undefined,
235
235
  ): boolean {
236
236
  const lower = String(event?.raw_message ?? event?.message ?? "").toLowerCase();
237
237
  if (botName && lower.includes(botName.toLowerCase())) return true;
@@ -239,8 +239,8 @@ function detectQqAtBot(
239
239
  for (const segment of event.message) {
240
240
  if (!segment || typeof segment !== "object") continue;
241
241
  if (segment.type !== "at") continue;
242
- const qq = Number(segment.data?.qq ?? 0);
243
- if (qq > 0 && qq === botSelfId) return true;
242
+ const target = String(segment.data?.qq ?? segment.data?.target ?? "").trim();
243
+ if (target && target === botSelfId) return true;
244
244
  }
245
245
  }
246
246
  return false;
package/play/types.ts CHANGED
@@ -12,8 +12,8 @@ export interface PlayServerConfig {
12
12
  }
13
13
 
14
14
  export interface GroupBinding {
15
- groupId: number;
16
- botSelfId: number;
15
+ groupId: string;
16
+ botSelfId: string;
17
17
  allowedServerIds: string[];
18
18
  }
19
19
 
@@ -73,8 +73,8 @@ export type MainLoopTrigger =
73
73
  export interface PlaySessionStatus {
74
74
  serverId: string;
75
75
  serverName: string;
76
- groupId: number;
77
- botSelfId: number;
76
+ groupId: string;
77
+ botSelfId: string;
78
78
  startedAt: number;
79
79
  connected: boolean;
80
80
  currentBehavior: string | null;
@@ -182,6 +182,11 @@ function asStringList(value: unknown): string[] {
182
182
  return [];
183
183
  }
184
184
 
185
+ function asId(value: unknown, fallback = ""): string {
186
+ const text = String(value ?? "").trim();
187
+ return text.length > 0 ? text : fallback;
188
+ }
189
+
185
190
  function asNumber(value: unknown, fallback: number): number {
186
191
  const n = Number(value);
187
192
  return Number.isFinite(n) ? n : fallback;
@@ -212,8 +217,8 @@ function normalizeServer(raw: any): PlayServerConfig {
212
217
 
213
218
  function normalizeBinding(raw: any): GroupBinding {
214
219
  return {
215
- groupId: asNumber(raw?.groupId ?? raw?.group_id, 0),
216
- botSelfId: asNumber(raw?.botSelfId ?? raw?.bot_self_id, 0),
220
+ groupId: asId(raw?.groupId ?? raw?.group_id),
221
+ botSelfId: asId(raw?.botSelfId ?? raw?.bot_self_id),
217
222
  allowedServerIds: asStringList(raw?.allowedServerIds ?? raw?.allowed_server_ids),
218
223
  };
219
224
  }
@@ -225,7 +230,7 @@ export function normalizePlayConfig(raw: any): PlayConfig {
225
230
  const groups = Array.isArray(raw?.groups)
226
231
  ? raw?.groups
227
232
  .map(normalizeBinding)
228
- .filter((g: GroupBinding) => g.groupId > 0 && g.botSelfId > 0)
233
+ .filter((g: GroupBinding) => g.groupId.length > 0 && g.botSelfId.length > 0)
229
234
  : [];
230
235
  const perm: PlayToolPermission =
231
236
  raw?.toolPermission === "owner" ||
package/skills/mc.ts CHANGED
@@ -29,8 +29,8 @@ export function createMcSkill(playManager: PlayManager): AISkill {
29
29
  },
30
30
  handler: async (args: any, runtimeCtx?: any) => {
31
31
  const event = runtimeCtx?.event || runtimeCtx?.rawEvent;
32
- const groupId = Number(event?.group_id);
33
- if (!Number.isFinite(groupId) || groupId <= 0) {
32
+ const groupId = String(event?.group_id ?? "").trim();
33
+ if (!groupId) {
34
34
  return { error: "无法识别当前群,请在群聊中调用" };
35
35
  }
36
36