dsh-mc-server-ops 0.6.4 → 0.6.6

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.
Files changed (3) hide show
  1. package/README.md +8 -8
  2. package/index.js +46 -20
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -36,8 +36,8 @@
36
36
  - **配方**:`kubejs` 脚本备份 / 重载
37
37
  - **授权**:动受保护区域(world、ops\data、白名单)要 2 位群友投票;**凑满 2 票之前任何人反对就作废**
38
38
  - **人设**:默认「小铜」,名字和语气都能在设置里改
39
- - **游戏内 AI**:装上配套 Forge mod 后,玩家在游戏里 `/ai <内容>` 就能和「小铜」对话(只监听 `127.0.0.1`,按玩家 UUID 复用独立会话);mod 1.1.0 起还能带截图/文件附件
40
- - **天气投票**:配套 mod 1.2.0 起,游戏内玩家可用 `/weather` 改天气;在线 ≤2 人直接生效,3 人及以上要 `/vote yes` 投票(2 票同意通过),门槛都能在设置面板改
39
+ - **游戏内 AI**:装上配套 mc-ai mod 后(1.3.0 起支持 Forge / NeoForge / Fabric / Bukkit),玩家在游戏里 `/ai <内容>` 就能和「小铜」对话(只监听 `127.0.0.1`,按玩家 UUID 复用独立会话);mod 1.1.0 起还能带截图/文件附件
40
+ - **天气投票**:配套 mc-ai mod 1.2.0 起(1.3.0 起所有平台一致),游戏内玩家可用 `/weather` 改天气;在线 ≤2 人直接生效,3 人及以上要 `/vote yes` 投票(2 票同意通过),门槛都能在设置面板改
41
41
 
42
42
  ## 安装
43
43
 
@@ -108,10 +108,10 @@ dsh plugin add /path/to/dsh-mc-server-ops
108
108
  | `bridge.coalesce.fastMs` | `50000` | 相邻两条发言间隔小于这个值算「话密」 |
109
109
  | `bridge.maxPerDay` | `900` | 每群每天发送上限(官方上限 1000) |
110
110
  | `bridge.appId` / `appSecret` | 空 | 留空自动从本机 qqbot 插件配置读取 |
111
- | `ai.enabled` | `true` | 是否开游戏内 `/ai` 对话(需要配套 Forge mod;只监听 `127.0.0.1`) |
111
+ | `ai.enabled` | `true` | 是否开游戏内 `/ai` 对话(需要配套 mc-ai mod,支持 Forge / NeoForge / Fabric / Bukkit;只监听 `127.0.0.1`) |
112
112
  | `ai.port` | `8765` | mod 连接的本地端口 |
113
113
  | `ai.timeoutSeconds` | `60` | 等 AI 回复的超时秒数 |
114
- | `weather.enabled` | `true` | 允许游戏内玩家用 `/weather` 改天气(需要 mcai mod 1.2.0+) |
114
+ | `weather.enabled` | `true` | 允许游戏内玩家用 `/weather` 改天气(需要 mc-ai mod 1.2.0+;1.3.0 起支持全部平台) |
115
115
  | `weather.directThreshold` | `2` | 在线 ≤ 这个数时直接改天气;更多人才发起投票 |
116
116
  | `weather.approveNeed` / `weather.rejectNeed` | `2` / `1` | 通过需要几票同意 / 几票反对作废(发起人自动算 1 票同意) |
117
117
  | `weather.timeoutSeconds` | `60` | 投票有效期(秒) |
@@ -254,7 +254,7 @@ powershell -File <服务器目录>\ops\mcadmin.ps1 -Action owner-add -Arg <openi
254
254
 
255
255
  ## 游戏内 AI 对话(/ai)
256
256
 
257
- 配套 Forge mod:[mogutofu/dsh-mc-ai-chat](https://github.com/mogutofu/dsh-mc-ai-chat)(服务端 Forge 1.20.1-47.x)。玩家在游戏里输入 `/ai 你好`,mod 会把请求 POST 到本机 `127.0.0.1:8765/mc-ai`,插件开一个 agent 回合,再把回复贴回玩家聊天栏。mod **1.1.0** 起还支持附件:`/ai screenshot` 截游戏画面、`/ai file <路径>` 读玩家本机的文件。
257
+ 配套 mc-ai mod:[mogutofu/dsh-mc-ai-chat](https://github.com/mogutofu/dsh-mc-ai-chat)(1.3.0 起支持 Forge 1.12.2/1.20.1、NeoForge 1.21.1/26.x、Fabric 26.x,以及 Bukkit/Spigot/Paper 通用插件)。玩家在游戏里输入 `/ai 你好`,mod 会把请求 POST 到本机 `127.0.0.1:8765/mc-ai`,插件开一个 agent 回合,再把回复贴回玩家聊天栏。mod **1.1.0** 起还支持附件:`/ai screenshot` 截游戏画面、`/ai file <路径>` 读玩家本机的文件。
258
258
 
259
259
  | 项 | 说明 |
260
260
  | --- | --- |
@@ -282,7 +282,7 @@ powershell -File <服务器目录>\ops\mcadmin.ps1 -Action owner-add -Arg <openi
282
282
 
283
283
  ## 游戏内天气投票(/weather)
284
284
 
285
- 配套 Forge mod **mcai 1.2.0+**:游戏内所有玩家都能用 `/weather clear|rain|thunder [持续秒数]` 改天气(mod 会把原版需要 OP 的 `/weather` 换成对所有人开放)。
285
+ 配套 mc-ai mod **1.2.0+**(1.3.0 起覆盖 Forge / NeoForge / Fabric / Bukkit):游戏内所有玩家都能用 `/weather clear|rain|thunder [持续秒数]` 改天气(mod 会把原版需要 OP 的 `/weather` 换成对所有人开放)。
286
286
 
287
287
  - 在线玩家 **≤ `weather.directThreshold`(默认 2)**:直接生效,全服提示「XX 把天气改成了下雨」
288
288
  - **3 人及以上**:发起投票,发起人自动算 1 票同意;其他人在游戏里用 `/vote yes` 同意、`/vote no` 反对、`/vote status` 查看
@@ -379,10 +379,10 @@ Paper / Spigot / Purpur / Folia / Leaves、Forge / NeoForge / Fabric / Quilt、A
379
379
  不会。桥直接读日志、直接调 QQ 开放平台,不创建 agent 会话、不调模型。只有群友真的问问题时才走 AI。
380
380
 
381
381
  **游戏内 /ai 需要什么?**
382
- 这个插件 + 配套的 Forge mod [dsh-mc-ai-chat](https://github.com/mogutofu/dsh-mc-ai-chat),服务端装 mod 后重启即可。`/ai` 会创建 agent 会话、调用 DSH 的模型,按模型计费;玩家和群友受同一套权限守卫,不能借它绕过服务器管理规则。
382
+ 这个插件 + 配套的 mc-ai mod [dsh-mc-ai-chat](https://github.com/mogutofu/dsh-mc-ai-chat),服务端装 mod 后重启即可。`/ai` 会创建 agent 会话、调用 DSH 的模型,按模型计费;玩家和群友受同一套权限守卫,不能借它绕过服务器管理规则。
383
383
 
384
384
  **游戏内 /ai 能发图片和文件吗?**
385
- 能,需要 mod 1.1.0:`/ai screenshot` 发当前游戏截图,`/ai file <路径>` 发玩家本机文件(1.1.0 一次最多 1 个附件)。图片会直接给模型看,文件落到 DSH 的附件存储后由 agent 自己读取;两条路都按上面的大小/类型限制校验,模型和 agent 因此能看到你发的内容。
385
+ 能,需要 mod 1.1.0:`/ai screenshot` 发当前游戏截图,`/ai file <路径>` 发玩家本机文件(1.1.0 一次最多 1 个附件)。图片会直接给模型看,文件落到 DSH 的附件存储后由 agent 自己读取;两条路都按上面的大小/类型限制校验,模型和 agent 因此能看到你发的内容。Bukkit 版插件只有文字 `/ai`,没有附件。
386
386
 
387
387
  ## License
388
388
 
package/index.js CHANGED
@@ -1168,10 +1168,22 @@ export function apply(ctx, config) {
1168
1168
  timeoutMs: 180000,
1169
1169
  isConcurrencySafe: () => false,
1170
1170
  async execute(args, exec) {
1171
- const action = String((args && args.action) || '')
1171
+ let action = String((args && args.action) || '')
1172
1172
  if (!ACTIONS.includes(action)) throw new Error('mc_server: 不支持的 action: ' + action)
1173
1173
  const actor = String((args && args.actor) || '').trim()
1174
1174
  if (!actor) throw new Error('mc_server: actor 不能为空(必须取自 [昵称 (ID)] 标记)')
1175
+ // 兼容旧习惯:模型可能用 cmd 发「weather rain」。只要整个参数就是天气命令,
1176
+ // 就转成 weather 动作处理(玩家也能走,不再被 cmd 的服主限制拦住)。
1177
+ // 注意:args 对象是只读的(工具层冻结),不要原地改 args.arg,用局部变量覆盖。
1178
+ let weatherArgOverride = null
1179
+ if (action === 'cmd') {
1180
+ const cmdArg = String((args && args.arg) || '').trim()
1181
+ const weatherMatch = /^weather\s+(clear|rain|thunder|sunny|晴天|下雨|雷雨)\s*$/i.exec(cmdArg)
1182
+ if (weatherMatch) {
1183
+ weatherArgOverride = weatherMatch[1]
1184
+ action = 'weather'
1185
+ }
1186
+ }
1175
1187
  const agentIdForGate = exec && exec.agent && exec.agent.id ? String(exec.agent.id) : ''
1176
1188
  if ((action === 'owner-add' || action === 'owner-del') && !isLocalSession(agentIdForGate)) {
1177
1189
  return { ok: false, text: '增删服主只能在设置面板里做,或者到服务器本机执行。' }
@@ -1187,7 +1199,7 @@ export function apply(ctx, config) {
1187
1199
  // Channel 由会话决定,不信模型自己填:本机会话=console,QQ 会话=group,只有私聊且模型声明 c2c 才算 c2c
1188
1200
  const channel = isLocalSession(agentIdForGate) ? 'console' : (String((args && args.channel) || '') === 'c2c' ? 'c2c' : 'group')
1189
1201
  const cli = ['-Action', action, '-Actor', actor, '-Channel', channel]
1190
- const arg = args && args.arg !== undefined && args.arg !== null ? String(args.arg) : ''
1202
+ const arg = weatherArgOverride !== null ? weatherArgOverride : (args && args.arg !== undefined && args.arg !== null ? String(args.arg) : '')
1191
1203
  if (arg !== '') cli.push('-Arg', arg)
1192
1204
  // ── 出网前的三道闸 ──
1193
1205
  // ① 权限校验:上面已经拦掉服主专属动作和设置里关掉的功能
@@ -1249,21 +1261,21 @@ export function apply(ctx, config) {
1249
1261
  return { ok: true, text: '天气已改成「' + typeName + '」(服主直接执行,不投票)。' }
1250
1262
  }
1251
1263
  const mine = readPlayerBindings().filter((b) => b.qq === actor).map((b) => b.name)
1252
- if (!mine.length) {
1253
- return {
1254
- ok: false,
1255
- text: '你还没绑定游戏名,我没法用你的身份改天气。先发「绑定游戏名 你的ID」把 QQ 和游戏名绑上、进服后再试;'
1256
- + '也可以直接在游戏里输入 /weather ' + type + '(在线 3 人以上会自动发起投票)。',
1257
- }
1258
- }
1259
1264
  const playersResult = await runMcAdmin(['-Action', 'players', '-Actor', actor, '-Channel', channel], 30000)
1260
1265
  const online = parseOnlinePlayers(playersResult.ok ? playersResult.text : '')
1261
1266
  const onlineName = mine.find((name) => online.some((p) => p.toLowerCase() === name.toLowerCase()))
1267
+ // 没有绑定或不在线时:在线人少(≤ 免投票阈值)不需要身份也能直接生效。
1262
1268
  if (!onlineName) {
1269
+ const who = !mine.length ? '你还没绑定游戏名' : '你绑定的游戏名(' + mine.join(', ') + ')现在都不在线'
1270
+ if (online.length <= threshold) {
1271
+ const direct = await runMcAdmin(['-Action', 'cmd', '-Arg', 'weather ' + type, '-Actor', 'LOCAL-CONSOLE', '-Channel', 'console'], 60000)
1272
+ if (!direct.ok) return { ok: false, text: '改天气失败:' + direct.text }
1273
+ return { ok: true, text: who + ';不过当前在线 ' + online.length + ' 人(≤' + threshold + ',不用投票),已直接改成「' + typeName + '」。' }
1274
+ }
1263
1275
  return {
1264
1276
  ok: false,
1265
- text: '你绑定的游戏名(' + mine.join(', ') + ')现在都不在线。先进服再让我改;'
1266
- + '或者在游戏里输入 /weather ' + type + '(在线 3 人以上会自动发起投票)。',
1277
+ text: who + ',而当前在线 ' + online.length + ' 人(超过 ' + threshold + '),改天气需要游戏内投票。'
1278
+ + '先发「绑定游戏名 你的ID」并进服,或者直接在游戏里输入 /weather ' + type + ' 发起。',
1267
1279
  }
1268
1280
  }
1269
1281
  const started = await runMcAdmin(['-Action', 'cmd', '-Arg', 'execute as ' + onlineName + ' run weather ' + type, '-Actor', 'LOCAL-CONSOLE', '-Channel', 'console'], 60000)
@@ -1412,18 +1424,21 @@ export function apply(ctx, config) {
1412
1424
  if (typeof ctx.on === 'function') {
1413
1425
  ctx.effect(() => ctx.on('system-prompt/assemble', async (assembly, context, next) => {
1414
1426
  const assembled = await next()
1415
- if (persona.enabled === false) return assembled
1416
- const scope = String(persona.scope || 'qq')
1417
- if (scope === 'none') return assembled
1418
1427
  const agentId = context && context.agent ? String(context.agent.id ?? '') : ''
1419
1428
  if (!agentId) return assembled
1420
- if (scope === 'qq' && isLocalSession(agentId)) return assembled
1421
- const text = renderPersona(persona)
1422
- if (!text) return assembled
1423
- return {
1424
- ...assembled,
1425
- sections: [...(assembled.sections ?? []), { name: 'mc-ops:persona', order: 91, text }],
1429
+ const sections = [...(assembled.sections ?? [])]
1430
+ // QQ 会话一律带上能力清单:明确告诉模型天气对所有玩家开放,别再按旧记忆拒绝
1431
+ if (!isLocalSession(agentId)) {
1432
+ sections.push({ name: 'mc-ops:abilities', order: 90, text: renderAbilities() })
1433
+ }
1434
+ if (persona.enabled !== false) {
1435
+ const scope = String(persona.scope || 'qq')
1436
+ if (scope !== 'none' && !(scope === 'qq' && isLocalSession(agentId))) {
1437
+ const text = renderPersona(persona)
1438
+ if (text) sections.push({ name: 'mc-ops:persona', order: 91, text })
1439
+ }
1426
1440
  }
1441
+ return { ...assembled, sections }
1427
1442
  }))
1428
1443
  }
1429
1444
  }
@@ -1693,6 +1708,17 @@ function checkActionAllowed(action, perms) {
1693
1708
  return ''
1694
1709
  }
1695
1710
 
1711
+ /** 注入给 QQ 会话的能力清单(system prompt)。重点是天气:所有玩家都能用。 */
1712
+ function renderAbilities() {
1713
+ return [
1714
+ '## 服务器操作能力(mc_server 工具,参数 action + actor)',
1715
+ '- 改天气:action=weather,arg 为 clear / rain / thunder(也可写 晴天 / 下雨 / 雷雨)。',
1716
+ ' **所有玩家都能用,不要回复「只有服主能做」**。玩家需要先用 bind-player 绑定游戏名并且当前在游戏里;',
1717
+ ' 服主/控制台直接执行。在线 ≤2 人直接生效,≥3 人时游戏内会广播投票(其他玩家输入 /vote yes)。',
1718
+ '- 其它常用 action:status、players、logs、say、gamemode、my-players、bind-player、vote-start / vote-approve / vote-status。',
1719
+ ].join('\n')
1720
+ }
1721
+
1696
1722
  function renderPersona(persona) {
1697
1723
  const p = persona || {}
1698
1724
  const text = String(p.text || '').trim() || DEFAULT_PERSONA
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-mc-server-ops",
3
- "version": "0.6.4",
4
- "description": "在 DeepSeek Harness 里托管 Minecraft 服务器的插件:状态/启停/日志/白名单/投票授权,静态命令拦截,本地/Pterodactyl 可插拔适配器,游戏聊天直通 QQ 群(不经过 AI、不耗 token),把人设注入 QQ 会话,并让游戏内玩家用 /ai 和「小铜」对话(配套 Forge mod)。需要先安装 QQ 机器人插件。",
3
+ "version": "0.6.6",
4
+ "description": "在 DeepSeek Harness 里托管 Minecraft 服务器的插件:状态/启停/日志/白名单/投票授权,静态命令拦截,本地/Pterodactyl 可插拔适配器,游戏聊天直通 QQ 群(不经过 AI、不耗 token),把人设注入 QQ 会话,并让游戏内玩家用 /ai 和「小铜」对话(配套 mc-ai mod,1.3.0 起支持 Forge/NeoForge/Fabric/Bukkit)。需要先安装 QQ 机器人插件。",
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
7
  "exports": {