dsh-cabin-chat 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +69 -2
- package/cordis.patch.yml +13 -0
- package/index.js +414 -0
- package/package.json +54 -5
- package/patcher/README.md +49 -0
- package/patcher/apply.mjs +224 -0
- package/patcher/rules.json +176 -0
- package/patcher/snippets/bridge-chat-tool.js +21 -0
- package/patcher/snippets/bridge-chatarchive.js +16 -0
- package/patcher/snippets/bridge-emotion.js +86 -0
- package/patcher/snippets/bridge-follow.js +8 -0
- package/patcher/snippets/bridge-gift.js +52 -0
- package/patcher/snippets/bridge-route.js +8 -0
- package/patcher/snippets/bridge-timer.js +14 -0
- package/patcher/snippets/bridge-tools.js +21 -0
- package/patcher/snippets/resident-mood-line.js +1 -0
- package/patcher/snippets/start-bridge-silent.vbs.txt +9 -0
- package/sticker-names.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-cabin-chat contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-cabin-chat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
把 **小屋世界(Cabin World)** 里的聊天气泡,接到 DSH 上的伙伴(Aurabot)身上。
|
|
4
|
+
|
|
5
|
+
装好之后,你在游戏里打字说话,她会在同一个聊天窗口里接话;她能发表情、能收下或拒绝你送的礼物,头顶还会显示心情和情绪值。游戏更新把我们的改动冲掉时,插件会自己认出版本变了、自动补回去。
|
|
6
|
+
|
|
7
|
+
## 装之前
|
|
8
|
+
|
|
9
|
+
- 小屋世界 1.2(`CabinWorld.exe` + `bridge/bridge.mjs`)
|
|
10
|
+
- DSH 桌面版,已装 Aurabot(伙伴能正常说话)
|
|
11
|
+
- Node 18+(游戏自带的 `runtime/node.exe` 也算)
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
dsh plugin add dsh-cabin-chat
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
装完重启 DSH。插件会在启动时:
|
|
20
|
+
|
|
21
|
+
1. 找小屋世界装在哪(配置留空就自己扫盘,不用手填路径)
|
|
22
|
+
2. 检查游戏里的补丁是否还在,缺的按规则补回、重新打包,然后自检
|
|
23
|
+
3. 打开聊天通道:游戏里的消息 → 她 → 回到游戏群聊
|
|
24
|
+
|
|
25
|
+
## 功能
|
|
26
|
+
|
|
27
|
+
| 功能 | 说明 |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| 群聊 / 私聊 | 游戏里按 **E** 开关聊天窗口,可切「群聊 / 私聊」 |
|
|
30
|
+
| 她接话 | 文字、纯表情、纯图片都会当消息处理 |
|
|
31
|
+
| 表情 | 游戏自带 50 张图配了中文描述(`sticker-names.json`),她认得出是哪张;她也能发表情 |
|
|
32
|
+
| 发图 | 游戏里点「图片」选本地图,或直接把图拖进游戏窗口,或 Ctrl+V 粘剪贴板(从微信抓的图最快) |
|
|
33
|
+
| 送礼 | 靠近按 **F** 送礼;她按心情决定收不收,收到会写进背包,也会在聊天里回应 |
|
|
34
|
+
| 心情 | 头顶显示「心情 + 情绪值」 |
|
|
35
|
+
| 情绪值 | 聊天 +3、送礼 +8、玩游乐设施 +12(同场景双倍);长期不互动会衰减:15 分钟不动 → 缓慢降到 75%,1–3 小时 → 45%,3–8 小时 → 10%;离线按 35% 速率结算、最多算 12 小时、最低停在 28%。低于 28% 时她会不高兴、拒收礼物,得先聊聊或带她玩 |
|
|
36
|
+
| 自愈 | 游戏更新后自动检测 + 按锚点补丁 + 失败回滚 |
|
|
37
|
+
|
|
38
|
+
## 配置
|
|
39
|
+
|
|
40
|
+
`cordis.patch.yml` 里的 `config`:
|
|
41
|
+
|
|
42
|
+
| 键 | 默认 | 说明 |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| `enabled` | true | 总开关 |
|
|
45
|
+
| `cabinRoot` | 空 | 小屋世界目录;留空自动找 |
|
|
46
|
+
| `actor` | xiaojingyu | 她在游戏里的住户 key |
|
|
47
|
+
| `nick` | 小鲸鱼 | 显示名 |
|
|
48
|
+
| `cooldownSec` | 2 | 两次回话最短间隔(秒) |
|
|
49
|
+
| `maxReplyChars` | 120 | 回话最长字数 |
|
|
50
|
+
| `mirrorQQ` | false | 把 QQ 私聊也镜像进游戏群聊 |
|
|
51
|
+
| `stickerChance` | 0.25 | 回完话顺手补一个表情的概率 |
|
|
52
|
+
|
|
53
|
+
## 它改游戏什么
|
|
54
|
+
|
|
55
|
+
插件不改游戏本体,用补丁器往 `editable/resources` 里的几个脚本插代码(`patcher/rules.json`,共 17 条规则),然后用游戏自带的 `tools/resource-kit.mjs` 重新打包。
|
|
56
|
+
|
|
57
|
+
- 每次动手前备份到 `patcher/snapshots/`
|
|
58
|
+
- 锚点找不到就跳过并记一笔,不硬塞
|
|
59
|
+
- 打包自检不过 → 整批回滚,正式文件保持原样
|
|
60
|
+
- 上游把关键行重写了 → 写进 `patcher/needs-agent.json`,等人工适配
|
|
61
|
+
|
|
62
|
+
## 数据在哪
|
|
63
|
+
|
|
64
|
+
- 聊天记录:`%APPDATA%\Godot\app_userdata\<游戏项目名>\qingxi-chat.json`(插件会自己找最新的那份)
|
|
65
|
+
- 情绪值:`<游戏目录>\data\emotion.json`
|
|
66
|
+
- 礼物事件:`<游戏目录>\data\gift-events.jsonl`
|
|
67
|
+
|
|
68
|
+
## 许可
|
|
69
|
+
|
|
70
|
+
MIT
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# dsh-cabin-chat bundle patch:把小屋世界的群聊通道挂进 profile
|
|
2
|
+
- insert:
|
|
3
|
+
- id: cabin-chat
|
|
4
|
+
name: 'dsh-cabin-chat'
|
|
5
|
+
config:
|
|
6
|
+
enabled: true
|
|
7
|
+
cabinRoot: '' # 留空就自动找(也可以填自己机器上的目录)
|
|
8
|
+
actor: xiaojingyu
|
|
9
|
+
nick: 小鲸鱼
|
|
10
|
+
cooldownSec: 2
|
|
11
|
+
maxReplyChars: 120
|
|
12
|
+
mirrorQQ: false
|
|
13
|
+
stickerChance: 0.25
|
package/index.js
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// dsh-cabin-chat —— 小屋世界的群聊通道
|
|
2
|
+
// 作用:主人(或玩家)在小屋世界的群聊里说话 → 交给 Aurabot 的大肥鱼用她的人格想一句 →
|
|
3
|
+
// 再发回小屋世界的群聊。回话只落在游戏里,不往 QQ 刷。
|
|
4
|
+
// 小世界没安装时整体不启用(检测不到安装目录就不注册任何东西)。
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs'
|
|
7
|
+
import { spawnSync } from 'node:child_process'
|
|
8
|
+
import os from 'node:os'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
|
|
11
|
+
export const name = 'cabin-chat'
|
|
12
|
+
export const inject = []
|
|
13
|
+
|
|
14
|
+
const LOG = '[cabin-chat]'
|
|
15
|
+
// 补丁器目录(和插件同级的 patcher/)
|
|
16
|
+
const PATCHER_DIR = path.join(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), 'patcher')
|
|
17
|
+
const DEFAULTS = {
|
|
18
|
+
enabled: true,
|
|
19
|
+
cabinRoot: '', // 留空自动找
|
|
20
|
+
actor: 'xiaojingyu',
|
|
21
|
+
nick: '小鲸鱼',
|
|
22
|
+
cooldownSec: 2,
|
|
23
|
+
maxReplyChars: 120,
|
|
24
|
+
chatFile: '',
|
|
25
|
+
mirrorQQ: false,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const norm = (cfg = {}) => {
|
|
29
|
+
const out = {}
|
|
30
|
+
for (const [k, v] of Object.entries(DEFAULTS)) {
|
|
31
|
+
const given = cfg?.[k]
|
|
32
|
+
out[k] = given === undefined || given === null || given === '' ? v : given
|
|
33
|
+
}
|
|
34
|
+
out.enabled = out.enabled !== false
|
|
35
|
+
out.cooldownSec = Math.max(0, Number(out.cooldownSec) || 0)
|
|
36
|
+
out.maxReplyChars = Math.min(400, Math.max(20, Number(out.maxReplyChars) || 120))
|
|
37
|
+
out.mirrorQQ = out.mirrorQQ === true
|
|
38
|
+
return out
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 装没装小屋世界:看有没有桥的配置和主程序 */
|
|
42
|
+
/** 2026-11-28: 配的路径不对时,自己去常见位置找一遍小屋世界(别人装的目录名可能不同) */
|
|
43
|
+
function findCabinWorld() {
|
|
44
|
+
const looksValid = (dir) => {
|
|
45
|
+
try {
|
|
46
|
+
return fs.existsSync(path.join(dir, 'bridge', 'bridge.config.json'))
|
|
47
|
+
&& (fs.existsSync(path.join(dir, 'CabinWorld.engine.exe')) || fs.existsSync(path.join(dir, 'CabinWorld.exe')))
|
|
48
|
+
} catch { return false }
|
|
49
|
+
}
|
|
50
|
+
const roots = []
|
|
51
|
+
try {
|
|
52
|
+
for (const drive of fs.readdirSync('/')) roots.push(drive) // 非 Windows 兜底
|
|
53
|
+
} catch { /* ignore */ }
|
|
54
|
+
for (const letter of 'CDEFGHIJ'.split('')) roots.push(letter + ':\\')
|
|
55
|
+
const seen = new Set()
|
|
56
|
+
for (const base of roots) {
|
|
57
|
+
let top = []
|
|
58
|
+
try { top = fs.readdirSync(base, { withFileTypes: true }).filter((d) => d.isDirectory()) } catch { continue }
|
|
59
|
+
for (const d of top) {
|
|
60
|
+
const first = path.join(base, d.name)
|
|
61
|
+
if (seen.has(first)) continue
|
|
62
|
+
seen.add(first)
|
|
63
|
+
if (looksValid(first)) return first
|
|
64
|
+
let second = []
|
|
65
|
+
try { second = fs.readdirSync(first, { withFileTypes: true }).filter((x) => x.isDirectory()) } catch { continue }
|
|
66
|
+
for (const e of second) {
|
|
67
|
+
const candidate = path.join(first, e.name)
|
|
68
|
+
if (seen.has(candidate)) continue
|
|
69
|
+
seen.add(candidate)
|
|
70
|
+
if (looksValid(candidate)) return candidate
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return ''
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function detect(cabinRoot) {
|
|
78
|
+
let root = String(cabinRoot || '').trim()
|
|
79
|
+
const bridgeCfgOf = (dir) => path.join(dir, 'bridge', 'bridge.config.json')
|
|
80
|
+
const ok = (dir) => fs.existsSync(dir)
|
|
81
|
+
&& fs.existsSync(bridgeCfgOf(dir))
|
|
82
|
+
&& (fs.existsSync(path.join(dir, 'CabinWorld.engine.exe')) || fs.existsSync(path.join(dir, 'CabinWorld.exe')))
|
|
83
|
+
if (!ok(root)) {
|
|
84
|
+
const found = findCabinWorld()
|
|
85
|
+
if (found) root = found
|
|
86
|
+
}
|
|
87
|
+
if (!root) return { installed: false, reason: '没有填小屋世界目录' }
|
|
88
|
+
const bridgeCfg = bridgeCfgOf(root)
|
|
89
|
+
const exe = path.join(root, 'CabinWorld.engine.exe')
|
|
90
|
+
const exe2 = path.join(root, 'CabinWorld.exe')
|
|
91
|
+
if (!fs.existsSync(root)) return { installed: false, reason: `目录不存在:${root}` }
|
|
92
|
+
if (!fs.existsSync(bridgeCfg)) return { installed: false, reason: '找不到 bridge/bridge.config.json' }
|
|
93
|
+
if (!fs.existsSync(exe) && !fs.existsSync(exe2)) return { installed: false, reason: '找不到 CabinWorld 主程序' }
|
|
94
|
+
let port = 0
|
|
95
|
+
try { port = JSON.parse(fs.readFileSync(bridgeCfg, 'utf8'))?.http?.port || 0 } catch { /* 读不了就用默认 */ }
|
|
96
|
+
return { installed: true, root, httpPort: port || 18790, bridgeConfig: bridgeCfg }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function chatFilePath(cfg) {
|
|
100
|
+
if (cfg.chatFile) return cfg.chatFile
|
|
101
|
+
const appData = process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming')
|
|
102
|
+
// 2026-11-28: 不写死游戏项目名 —— 别人装的小屋世界名字可能不同,扫一遍找最新的那份聊天记录
|
|
103
|
+
const base = path.join(appData, 'Godot', 'app_userdata')
|
|
104
|
+
try {
|
|
105
|
+
let best = null
|
|
106
|
+
for (const name of fs.readdirSync(base)) {
|
|
107
|
+
const candidate = path.join(base, name, 'qingxi-chat.json')
|
|
108
|
+
try {
|
|
109
|
+
const st = fs.statSync(candidate)
|
|
110
|
+
if (!best || st.mtimeMs > best.mtimeMs) best = { file: candidate, mtimeMs: st.mtimeMs }
|
|
111
|
+
} catch { /* 没有这个文件 */ }
|
|
112
|
+
}
|
|
113
|
+
if (best) return best.file
|
|
114
|
+
} catch { /* 没有 Godot 目录就用默认名 */ }
|
|
115
|
+
return path.join(base, 'Cabin World Public', 'qingxi-chat.json')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function dataDir() {
|
|
119
|
+
const dir = path.join(os.homedir(), '.dsh', 'cabin-chat')
|
|
120
|
+
try { fs.mkdirSync(dir, { recursive: true }) } catch { /* 不能建就返回原路径,后面写失败也只影响去重 */ }
|
|
121
|
+
return dir
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function readState() {
|
|
125
|
+
try {
|
|
126
|
+
const raw = JSON.parse(fs.readFileSync(path.join(dataDir(), 'state.json'), 'utf8'))
|
|
127
|
+
return { lastId: Number(raw.lastId) || 0 }
|
|
128
|
+
} catch { return { lastId: 0 } }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function writeState(state) {
|
|
132
|
+
try { fs.writeFileSync(path.join(dataDir(), 'state.json'), JSON.stringify(state), 'utf8') } catch { /* 忽略 */ }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 发一条群聊进游戏(走小世界桥的 HTTP 接口) */
|
|
136
|
+
async function postToGame(cabinRoot, payload) {
|
|
137
|
+
const bridgeFile = path.join(cabinRoot, 'data', 'bridge.json')
|
|
138
|
+
let info = null
|
|
139
|
+
try { info = JSON.parse(fs.readFileSync(bridgeFile, 'utf8')) } catch {
|
|
140
|
+
return { ok: false, error: '还没连上小屋世界(找不到 data/bridge.json,先把游戏和桥开起来)' }
|
|
141
|
+
}
|
|
142
|
+
if (!info?.url || !info?.token) return { ok: false, error: 'bridge.json 里没有 url/token' }
|
|
143
|
+
const body = JSON.stringify(payload)
|
|
144
|
+
const res = await fetch(info.url + '/v1/chat', {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
headers: { authorization: 'Bearer ' + info.token, 'content-type': 'application/json' },
|
|
147
|
+
body,
|
|
148
|
+
signal: AbortSignal.timeout(15000),
|
|
149
|
+
}).catch((error) => ({ ok: false, text: async () => String(error?.message || error) }))
|
|
150
|
+
let text = ''
|
|
151
|
+
try { text = await res.text() } catch { /* ignore */ }
|
|
152
|
+
try { return JSON.parse(text) } catch { return { ok: false, error: text || '游戏没回执' } }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const roomOf = (row) => (String(row?.room || "") === "dm" ? "dm" : "village")
|
|
156
|
+
|
|
157
|
+
/** 2026-11-28: 情绪值 —— 聊天加分,并读回当前值(低情绪时她会不高兴) */
|
|
158
|
+
async function bumpEmotion(cabinRoot, kind) {
|
|
159
|
+
try {
|
|
160
|
+
const info = JSON.parse(fs.readFileSync(path.join(cabinRoot, 'data', 'bridge.json'), 'utf8'))
|
|
161
|
+
const res = await fetch(info.url + '/v1/emotion', {
|
|
162
|
+
method: 'POST',
|
|
163
|
+
headers: { authorization: 'Bearer ' + info.token, 'content-type': 'application/json' },
|
|
164
|
+
body: JSON.stringify({ kind }),
|
|
165
|
+
signal: AbortSignal.timeout(5000),
|
|
166
|
+
})
|
|
167
|
+
return await res.json()
|
|
168
|
+
} catch { return null }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 游戏自带表情的中文描述表(由 sticker-names.json 提供;没有就只说编号)
|
|
172
|
+
let STICKER_NAMES = {}
|
|
173
|
+
try {
|
|
174
|
+
STICKER_NAMES = JSON.parse(fs.readFileSync(new URL('./sticker-names.json', import.meta.url), 'utf8'))
|
|
175
|
+
} catch { STICKER_NAMES = {} }
|
|
176
|
+
// 她说 <sticker:开心> 时,换成游戏里的哪张表情
|
|
177
|
+
const STICKER_BY_TAG = {
|
|
178
|
+
开心: 'sticker-03', 高兴: 'sticker-37', 笑: 'sticker-37',
|
|
179
|
+
委屈: 'sticker-44', 难过: 'sticker-29', 哭: 'sticker-29',
|
|
180
|
+
生气: 'sticker-12', 火大: 'sticker-12',
|
|
181
|
+
无语: 'sticker-07', 敷衍: 'sticker-18',
|
|
182
|
+
疑惑: 'sticker-38', 问号: 'sticker-38',
|
|
183
|
+
害羞: 'sticker-19', 脸红: 'sticker-40',
|
|
184
|
+
卖萌: 'sticker-17', 可爱: 'sticker-03',
|
|
185
|
+
嘲讽: 'sticker-24', 得意: 'sticker-17',
|
|
186
|
+
困: 'sticker-01', 睡觉: 'sticker-47', 早晚安: 'sticker-27',
|
|
187
|
+
震惊: 'sticker-04', 惊讶: 'sticker-42',
|
|
188
|
+
}
|
|
189
|
+
const describeSticker = (id) => {
|
|
190
|
+
const name = id ? STICKER_NAMES[id] : ''
|
|
191
|
+
if (name) return `(画面是:${name})`
|
|
192
|
+
return id ? `(编号 ${id})` : ''
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const clean = (text, max) => String(text || '')
|
|
196
|
+
.replace(/^["“「『]|["”」』]$/g, '')
|
|
197
|
+
.replace(/^[((][^))]{0,12}[))]\s*/, '')
|
|
198
|
+
.replace(/\s*\n+\s*/g, ' ')
|
|
199
|
+
.trim()
|
|
200
|
+
.slice(0, max)
|
|
201
|
+
|
|
202
|
+
export function apply(ctx, rawConfig) {
|
|
203
|
+
const cfg = norm(rawConfig)
|
|
204
|
+
const found = detect(cfg.cabinRoot)
|
|
205
|
+
if (!found.installed) {
|
|
206
|
+
ctx.logger?.info?.(`${LOG} 没检测到小屋世界(${found.reason}),通道不启用`)
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
if (!cfg.enabled) {
|
|
210
|
+
ctx.logger?.info?.(`${LOG} 检测到小屋世界,但开关是关的(在插件设置里打开)`)
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const file = chatFilePath(cfg)
|
|
215
|
+
let state = readState()
|
|
216
|
+
let timer = null
|
|
217
|
+
let giftTimer = null
|
|
218
|
+
let giftBusy = false
|
|
219
|
+
let busy = false
|
|
220
|
+
let lastReplyAt = 0
|
|
221
|
+
|
|
222
|
+
const aurabot = () => (typeof ctx.get === 'function' ? ctx.get('aurabot') : null)
|
|
223
|
+
|
|
224
|
+
async function handle(rows) {
|
|
225
|
+
const a = aurabot()
|
|
226
|
+
if (!a || typeof a.think !== 'function') {
|
|
227
|
+
ctx.logger?.info?.(`${LOG} Aurabot 不在,跳过`)
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
// 纯表情 / 纯图片也算消息(以前 text 为空就被丢掉了)
|
|
231
|
+
const fresh = rows.filter((r) => Number(r.id) > state.lastId && r.actor === 'owner' && (String(r.text || '').trim() || String(r.sticker || '').trim()))
|
|
232
|
+
if (!fresh.length) return
|
|
233
|
+
const maxId = Math.max(state.lastId, ...fresh.map((r) => Number(r.id) || 0))
|
|
234
|
+
const last = fresh[fresh.length - 1]
|
|
235
|
+
state.lastId = maxId
|
|
236
|
+
writeState(state)
|
|
237
|
+
const wait = cfg.cooldownSec * 1000 - (Date.now() - lastReplyAt)
|
|
238
|
+
if (wait > 0) await new Promise((r) => setTimeout(r, wait))
|
|
239
|
+
let reply = ''
|
|
240
|
+
try {
|
|
241
|
+
const say = String(last.text || '').trim().slice(0, 300)
|
|
242
|
+
const sticker = String(last.sticker || '').trim()
|
|
243
|
+
const said = say
|
|
244
|
+
? `说:「${say}」`
|
|
245
|
+
: `发了一个表情${describeSticker(sticker)}`
|
|
246
|
+
// 聊天也算互动:给她加情绪,顺便看看现在多少
|
|
247
|
+
const emo = await bumpEmotion(found.root, 'chat')
|
|
248
|
+
const emoVal = Number(emo?.value)
|
|
249
|
+
let moodNote = ''
|
|
250
|
+
if (Number.isFinite(emoVal)) {
|
|
251
|
+
if (emoVal < 28) moodNote = `(你现在的情绪只有 ${emoVal}%,不太高兴,可以带一点情绪、顺口提一句想去玩游乐设施或者让他陪你聊会儿)`
|
|
252
|
+
else if (emoVal < 45) moodNote = `(你情绪 ${emoVal}%,有点淡)`
|
|
253
|
+
}
|
|
254
|
+
reply = await a.think({
|
|
255
|
+
prompt: `【来自小屋世界群聊】主人刚在小世界里${said}。你现在也在那个群聊里,用一两句话自然接话:短、口语、有情绪,别用客服腔;不要提 QQ、插件、AI、模型、代码、修复、系统这些东西,也别夸对方''厉害'',就当普通聊天。${moodNote}只写要说的话。`,
|
|
256
|
+
})
|
|
257
|
+
reply = clean(reply?.reply ?? reply, cfg.maxReplyChars)
|
|
258
|
+
} catch (error) {
|
|
259
|
+
ctx.logger?.info?.(`${LOG} 想话失败:${error?.message || error}`)
|
|
260
|
+
return
|
|
261
|
+
}
|
|
262
|
+
if (!reply || reply === '[沉默]') return
|
|
263
|
+
// 她偶尔会带 <sticker:开心> 这类标记:转成游戏里的表情,别让标记露在字里
|
|
264
|
+
let stickerId = ''
|
|
265
|
+
const tagMatch = reply.match(/<sticker:([^>]+)>/)
|
|
266
|
+
if (tagMatch) {
|
|
267
|
+
stickerId = STICKER_BY_TAG[tagMatch[1].trim()] || ''
|
|
268
|
+
reply = reply.replace(/<sticker:[^>]+>/g, '').trim()
|
|
269
|
+
}
|
|
270
|
+
const sent = await postToGame(found.root, {
|
|
271
|
+
actor: cfg.actor, name: cfg.nick, text: reply, room: roomOf(last), transport: `cabin:${last.id}`, sticker: stickerId,
|
|
272
|
+
})
|
|
273
|
+
lastReplyAt = Date.now()
|
|
274
|
+
ctx.logger?.info?.(`${LOG} 回了一句(${reply.length} 字):${sent?.ok ? '已进游戏' : '没发出去 ' + (sent?.error || '')}`)
|
|
275
|
+
// 偶尔顺手回一个游戏自带的表情(表情库/抬杠都由她自己的语气决定)
|
|
276
|
+
if (sent?.ok && Math.random() < Number(cfg.stickerChance ?? 0.25)) {
|
|
277
|
+
const id = 'sticker-' + String(1 + Math.floor(Math.random() * 50)).padStart(2, '0')
|
|
278
|
+
const pic = await postToGame(found.root, {
|
|
279
|
+
actor: cfg.actor, name: cfg.nick, text: '', sticker: id, room: roomOf(last), transport: `cabin-sticker:${last.id}`,
|
|
280
|
+
})
|
|
281
|
+
ctx.logger?.info?.(`${LOG} 回了个表情 ${id}:${pic?.ok ? '已进游戏' : '没发出去 ' + (pic?.error || '')}`)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 礼物事件:她收下/婉拒了主人送的东西,用她自己的人格回一句(心情与想法同步)
|
|
286
|
+
async function scanGifts() {
|
|
287
|
+
if (giftBusy) return
|
|
288
|
+
giftBusy = true
|
|
289
|
+
try {
|
|
290
|
+
const evFile = path.join(found.root, 'data', 'gift-events.jsonl')
|
|
291
|
+
let raw = ''
|
|
292
|
+
try { raw = fs.readFileSync(evFile, 'utf8') } catch { return }
|
|
293
|
+
const lines = raw.split('\n').filter(Boolean)
|
|
294
|
+
if (!lines.length) return
|
|
295
|
+
const items = []
|
|
296
|
+
for (const line of lines) {
|
|
297
|
+
try { items.push(JSON.parse(line)) } catch { /* 坏行忽略 */ }
|
|
298
|
+
}
|
|
299
|
+
const last = Number(state.lastGiftAt || 0)
|
|
300
|
+
const fresh = items.filter((e) => Number(e.at) > last && e.ok !== false)
|
|
301
|
+
if (!fresh.length) {
|
|
302
|
+
// 第一次跑:只记基线,不重播
|
|
303
|
+
if (!state.lastGiftAt) {
|
|
304
|
+
state.lastGiftAt = Math.max(...items.map((e) => Number(e.at) || 0))
|
|
305
|
+
writeState(state)
|
|
306
|
+
}
|
|
307
|
+
return
|
|
308
|
+
}
|
|
309
|
+
state.lastGiftAt = Math.max(...fresh.map((e) => Number(e.at) || 0))
|
|
310
|
+
writeState(state)
|
|
311
|
+
const ev = fresh[fresh.length - 1]
|
|
312
|
+
const a = aurabot()
|
|
313
|
+
if (!a || typeof a.think !== 'function') return
|
|
314
|
+
const prompt = ev.accept
|
|
315
|
+
? `【来自小屋世界】主人刚送了你「${ev.item}」,你收下了(当时心情值 ${ev.joy})。用一两句话自然回应,短、口语、有情绪,别提 AI、插件、系统。只写要说的话。`
|
|
316
|
+
: `【来自小屋世界】主人刚送了你「${ev.item}」,你没要(当时心情值 ${ev.joy})。用一两句话自然回绝或解释,短、口语、有情绪,别提 AI、插件、系统。只写要说的话。`
|
|
317
|
+
const out = await a.think({ prompt })
|
|
318
|
+
const line = clean(out?.reply ?? out, cfg.maxReplyChars)
|
|
319
|
+
if (!line || line === '[沉默]') return
|
|
320
|
+
await postToGame(found.root, {
|
|
321
|
+
actor: cfg.actor, name: cfg.nick, text: line, room: 'village', transport: `cabin-gift:${ev.at}`,
|
|
322
|
+
})
|
|
323
|
+
ctx.logger?.info?.(`${LOG} 礼物回话:${line}`)
|
|
324
|
+
} catch (error) {
|
|
325
|
+
ctx.logger?.info?.(`${LOG} 礼物读取失败:${error?.message || error}`)
|
|
326
|
+
} finally {
|
|
327
|
+
giftBusy = false
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async function scan() {
|
|
332
|
+
if (busy) return
|
|
333
|
+
busy = true
|
|
334
|
+
try {
|
|
335
|
+
let parsed = null
|
|
336
|
+
try { parsed = JSON.parse(fs.readFileSync(file, 'utf8')) } catch { return }
|
|
337
|
+
const rows = Array.isArray(parsed?.messages) ? parsed.messages : []
|
|
338
|
+
if (!rows.length) return
|
|
339
|
+
if (!state.lastId) {
|
|
340
|
+
// 第一次跑:把已有的当历史,不重播
|
|
341
|
+
state = { lastId: Math.max(...rows.map((r) => Number(r.id) || 0)) }
|
|
342
|
+
writeState(state)
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
await handle(rows)
|
|
346
|
+
} catch (error) {
|
|
347
|
+
ctx.logger?.info?.(`${LOG} 扫描出错:${error?.message || error}`)
|
|
348
|
+
} finally {
|
|
349
|
+
busy = false
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const start = () => {
|
|
354
|
+
if (timer) return
|
|
355
|
+
timer = setInterval(scan, 1200)
|
|
356
|
+
giftTimer = setInterval(scanGifts, 3000)
|
|
357
|
+
giftTimer.unref?.()
|
|
358
|
+
timer.unref?.()
|
|
359
|
+
ctx.logger?.info?.(`${LOG} 通道已开:${file} → Aurabot → 小屋世界群聊`)
|
|
360
|
+
void runPatcher()
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// 2026-11-28: 游戏更新后自动把我们的功能补回去(锚点规则;补不上的记下来等人/agent)
|
|
364
|
+
async function runPatcher() {
|
|
365
|
+
try {
|
|
366
|
+
const script = path.join(PATCHER_DIR, 'apply.mjs')
|
|
367
|
+
if (!fs.existsSync(script)) return
|
|
368
|
+
const node = process.execPath
|
|
369
|
+
const r = spawnSync(node, [script, '--cabin', found.root], { encoding: 'utf8', timeout: 180000 })
|
|
370
|
+
const out = String(r.stdout || '')
|
|
371
|
+
let info = null
|
|
372
|
+
try { info = JSON.parse(out) } catch { /* 输出不是 JSON */ }
|
|
373
|
+
if (!info) {
|
|
374
|
+
ctx.logger?.info?.(`${LOG} 补丁器输出异常:${(out + String(r.stderr || '')).slice(0, 300)}`)
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
if (info.ok && !info.applied?.length) ctx.logger?.info?.(`${LOG} 补丁检查通过,当前已是最新`)
|
|
378
|
+
if (info.skipped?.length) ctx.logger?.info?.(`${LOG} 补丁跳过:${info.skipped.map((s) => s.id + '(' + s.reason + ')').join('; ')}`)
|
|
379
|
+
if (info.needsAgent?.length) {
|
|
380
|
+
ctx.logger?.info?.(`${LOG} 这些文件需要人工/agent 适配:${info.needsAgent.map((n) => n.path).join(', ')}`)
|
|
381
|
+
const queue = path.join(PATCHER_DIR, 'needs-agent.json')
|
|
382
|
+
try { fs.writeFileSync(queue, JSON.stringify({ at: Date.now(), items: info.needsAgent, version: info.pckHashBefore }, null, 2)) } catch { /* 写不了就算了 */ }
|
|
383
|
+
}
|
|
384
|
+
if (info.ok === false && info.rolledBack) ctx.logger?.info?.(`${LOG} 补丁失败已回滚:${info.rolledBack.join(', ')}`)
|
|
385
|
+
} catch (error) {
|
|
386
|
+
ctx.logger?.info?.(`${LOG} 补丁器跑不起来:${error?.message || error}`)
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const stop = () => {
|
|
390
|
+
if (timer) { clearInterval(timer); timer = null }
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
start()
|
|
394
|
+
|
|
395
|
+
// QQ 那边收到主人的话,也可以镜像进游戏群聊(默认关,插件设置里开)
|
|
396
|
+
if (cfg.mirrorQQ) {
|
|
397
|
+
try {
|
|
398
|
+
const a = aurabot()
|
|
399
|
+
if (a && typeof a.on === 'function') {
|
|
400
|
+
a.on('message', async (evt) => {
|
|
401
|
+
try {
|
|
402
|
+
if (!evt || evt.from !== 'owner' || !String(evt.text || '').trim()) return
|
|
403
|
+
await postToGame(found.root, {
|
|
404
|
+
actor: 'owner', name: '你', text: String(evt.text).slice(0, 300), transport: `qq:${evt.id || Date.now()}`,
|
|
405
|
+
})
|
|
406
|
+
} catch { /* ignore */ }
|
|
407
|
+
})
|
|
408
|
+
}
|
|
409
|
+
} catch { /* ignore */ }
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
ctx.on?.('dispose', stop)
|
|
413
|
+
ctx.effect?.(() => stop)
|
|
414
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-cabin-chat",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"description": "小屋世界(Cabin World)与 DSH 伙伴的聊天通道:游戏里说话她会接话、能发表情、能收送礼、头顶显示心情与情绪值;游戏更新后自动补回改动",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"dsh",
|
|
9
|
+
"dsh-plugin",
|
|
10
|
+
"cabin-world",
|
|
11
|
+
"小屋世界",
|
|
12
|
+
"chat",
|
|
13
|
+
"aurabot"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/qinghong-hash/dsh-cabin-chat.git"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/qinghong-hash/dsh-cabin-chat#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/qinghong-hash/dsh-cabin-chat/issues"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"index.js",
|
|
27
|
+
"cordis.patch.yml",
|
|
28
|
+
"sticker-names.json",
|
|
29
|
+
"patcher/apply.mjs",
|
|
30
|
+
"patcher/rules.json",
|
|
31
|
+
"patcher/snippets/",
|
|
32
|
+
"patcher/README.md",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": "\u003e=18"
|
|
38
|
+
},
|
|
39
|
+
"dsh": {
|
|
40
|
+
"bundle": {
|
|
41
|
+
"patch": "./cordis.patch.yml"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@deepseek-ai/dsh-tools": "\u003e=0.0.0-0 \u003c0.3.0-0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@deepseek-ai/dsh-tools": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
6
55
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# 小屋世界补丁器(patcher)
|
|
2
|
+
|
|
3
|
+
游戏更新会把 `editable/` 里的脚本还原、把 `CabinWorld.engine.pck` 换掉,我们加的功能就消失。
|
|
4
|
+
这个补丁器负责:**检测游戏版本有没有变 → 变了就把我们的功能按规则补回去 → 自检 → 失败整批回滚。**
|
|
5
|
+
|
|
6
|
+
## 它怎么保证不改坏东西
|
|
7
|
+
|
|
8
|
+
1. **只按锚点插入**:每条规则在一个脚本里找一段特征串(比如 `func _remember() -> void:`),找到才插;
|
|
9
|
+
找不到就跳过并记录原因,**绝不硬塞**。
|
|
10
|
+
2. **动手前先备份**:改动前把涉及的文件复制到 `patcher/snapshots/<时间戳>/`。
|
|
11
|
+
3. **打包后自检**:用游戏自带的 `tools/resource-kit.mjs apply` 重新打包,输出里没有 `Ready:` 就算失败。
|
|
12
|
+
4. **失败整批回滚**:自检不过就把备份原地还原,正式文件保持原样。
|
|
13
|
+
5. **重新打包是原子的**:`resource-kit` 直接写出新的 pck,要么整套换好,要么原样留着。
|
|
14
|
+
|
|
15
|
+
## 怎么用
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 只看状态,不动任何文件
|
|
19
|
+
node patcher/apply.mjs --cabin "E:\小屋世界\CabinWorld" --check
|
|
20
|
+
|
|
21
|
+
# 按状态自动补(插件启动时会自己跑这个)
|
|
22
|
+
node patcher/apply.mjs --cabin "E:\小屋世界\CabinWorld"
|
|
23
|
+
|
|
24
|
+
# 忽略版本指纹,强制重跑规则
|
|
25
|
+
node patcher/apply.mjs --cabin "E:\小屋世界\CabinWorld" --force
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
插件(`dsh-cabin-chat`)每次启动都会调用一次;返回值写进 `patcher/last-run.json`。
|
|
29
|
+
|
|
30
|
+
## 什么时候它自己搞不定
|
|
31
|
+
|
|
32
|
+
有两类情况它会**停手**并把事情记下来,等人/agent 处理:
|
|
33
|
+
|
|
34
|
+
- 锚点找不到(游戏把那几行重写了)
|
|
35
|
+
- `owned_files` 里的文件变了:`qingxi-live/village-center/local_chat.gd` 整个聊天面板是我们重写的,
|
|
36
|
+
游戏一旦更新它,没法安全合并
|
|
37
|
+
|
|
38
|
+
这两种会写进 `patcher/needs-agent.json`,插件日志也会打一行,需要人来重写规则。
|
|
39
|
+
|
|
40
|
+
## 加新规则
|
|
41
|
+
|
|
42
|
+
编辑 `patcher/rules.json`,每条规则四件事:
|
|
43
|
+
|
|
44
|
+
- `file`:`editable/resources/` 下的相对路径
|
|
45
|
+
- `marker`:加过之后文件里应该出现的特征串(用它判断"已经有了,跳过")
|
|
46
|
+
- `anchor` + `insert_before_anchor` / `insert_after_anchor` / `replace_anchor`
|
|
47
|
+
- `snippet`:要插入的代码(GDScript 用 Tab 缩进)
|
|
48
|
+
|
|
49
|
+
加完先跑 `--check`,确认 `missing` 里能看到它,再正式跑一次。
|