dsh-mc-server-ops 0.6.4 → 0.6.5

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 (2) hide show
  1. package/index.js +46 -20
  2. package/package.json +1 -1
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,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mc-server-ops",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "在 DeepSeek Harness 里托管 Minecraft 服务器的插件:状态/启停/日志/白名单/投票授权,静态命令拦截,本地/Pterodactyl 可插拔适配器,游戏聊天直通 QQ 群(不经过 AI、不耗 token),把人设注入 QQ 会话,并让游戏内玩家用 /ai 和「小铜」对话(配套 Forge mod)。需要先安装 QQ 机器人插件。",
5
5
  "type": "module",
6
6
  "main": "./index.js",