@mcviseron/dsh-qq-bridge 0.2.0 → 0.2.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/lib/client.js +372 -372
- package/lib/index.js +1120 -1120
- package/package.json +1 -2
package/lib/client.js
CHANGED
|
@@ -1,372 +1,372 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-qq-bridge 的浏览器半身:左侧导航栏「QQ 机器人」+ 整页设置/日志。
|
|
3
|
-
* 全部改用内联样式:宿主 main 槽位不在同一个样式作用域,注入 <style> 不可靠。
|
|
4
|
-
*/
|
|
5
|
-
window.__ModuleLoader__.load({
|
|
6
|
-
id: "dsh-qq-bridge",
|
|
7
|
-
factory: (require) => {
|
|
8
|
-
var module = { exports: {} }
|
|
9
|
-
var exports = module.exports
|
|
10
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
|
|
11
|
-
|
|
12
|
-
const React = require("react")
|
|
13
|
-
const h = React.createElement
|
|
14
|
-
const PANEL = "http://127.0.0.1:39062"
|
|
15
|
-
|
|
16
|
-
const T = {
|
|
17
|
-
page: { width: "100%", height: "100%", minHeight: 0, overflow: "auto", boxSizing: "border-box", padding: "24px clamp(16px,4vw,48px) 32px", color: "var(--dsw-alias-label-primary)", fontFamily: "var(--dsw-font-family, inherit)" },
|
|
18
|
-
inner: {
|
|
19
|
-
width: "100%", maxWidth: 720, margin: "0 auto", display: "grid", gap: 14,
|
|
20
|
-
// 磨砂玻璃底:页面浮在背景图之上时保证文字可读
|
|
21
|
-
padding: "20px 22px", borderRadius: 16,
|
|
22
|
-
border: "1px solid var(--dsw-alias-border-l2, rgba(255,255,255,0.14))",
|
|
23
|
-
backgroundColor: "rgba(22, 24, 30, 0.62)",
|
|
24
|
-
background: "color-mix(in srgb, var(--dsw-alias-bg-base, #14161c) 72%, transparent)",
|
|
25
|
-
backdropFilter: "blur(18px) saturate(130%)",
|
|
26
|
-
WebkitBackdropFilter: "blur(18px) saturate(130%)",
|
|
27
|
-
boxShadow: "0 10px 30px rgba(0,0,0,0.24)",
|
|
28
|
-
},
|
|
29
|
-
row: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 24, padding: "9px 0", borderTop: "1px solid var(--dsw-alias-border-l2)" },
|
|
30
|
-
labelBox: { display: "grid", gap: 2, minWidth: 0 },
|
|
31
|
-
title: { fontSize: 13, color: "var(--dsw-alias-label-primary)" },
|
|
32
|
-
hint: { fontSize: 12, color: "var(--dsw-alias-label-tertiary)" },
|
|
33
|
-
sectionTitle: { fontSize: 12, letterSpacing: "0.04em", color: "var(--dsw-alias-label-tertiary)", margin: "10px 0 2px" },
|
|
34
|
-
input: { width: 132, padding: "5px 8px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-primary)", font: "inherit", textAlign: "right" },
|
|
35
|
-
inputWide: { width: 260, textAlign: "left" },
|
|
36
|
-
btn: { padding: "6px 14px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "transparent", color: "var(--dsw-alias-label-primary)", font: "inherit", cursor: "pointer" },
|
|
37
|
-
btnPrimary: { background: "var(--dsw-alias-label-primary)", borderColor: "var(--dsw-alias-label-primary)", color: "var(--dsw-alias-bg-layer-3)" },
|
|
38
|
-
actions: { display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center" },
|
|
39
|
-
badge: { display: "inline-flex", alignItems: "center", gap: 6, padding: "3px 9px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 999, fontSize: 12, color: "var(--dsw-alias-label-secondary)" },
|
|
40
|
-
dot: { width: 7, height: 7, borderRadius: "50%" },
|
|
41
|
-
log: { margin: 0, maxHeight: 300, overflow: "auto", padding: 10, border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-secondary)", font: "12px/1.5 ui-monospace, Consolas, monospace", whiteSpace: "pre-wrap" },
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function Switch(props) {
|
|
45
|
-
return h("button", {
|
|
46
|
-
type: "button", role: "switch", "aria-checked": props.checked ? "true" : "false",
|
|
47
|
-
"aria-label": props.label, disabled: props.disabled,
|
|
48
|
-
onClick: function () { props.onChange(!props.checked) },
|
|
49
|
-
style: {
|
|
50
|
-
position: "relative", flex: "0 0 auto", width: 38, height: 22, padding: 2, border: 0,
|
|
51
|
-
borderRadius: 999, cursor: props.disabled ? "default" : "pointer", boxSizing: "border-box",
|
|
52
|
-
// 用官方语义色:开启=业务主色,关闭=边框 L3(不再用不存在的 brand-primary 导致发白)
|
|
53
|
-
background: props.checked
|
|
54
|
-
? "var(--dsw-alias-state-business-primary, #2f6bff)"
|
|
55
|
-
: "var(--dsw-alias-border-l3, #5a6270)",
|
|
56
|
-
boxShadow: props.checked ? "inset 0 0 0 1px rgba(255,255,255,0.12)" : "none",
|
|
57
|
-
opacity: props.disabled ? 0.5 : 1,
|
|
58
|
-
},
|
|
59
|
-
}, h("span", {
|
|
60
|
-
"aria-hidden": "true",
|
|
61
|
-
style: {
|
|
62
|
-
display: "block", width: 18, height: 18, borderRadius: "50%",
|
|
63
|
-
background: props.checked ? "#fff" : "var(--dsw-alias-switch-thumb, #c9ccd6)",
|
|
64
|
-
transform: props.checked ? "translateX(16px)" : "none", transition: "transform 120ms ease",
|
|
65
|
-
},
|
|
66
|
-
}))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function Row(props) {
|
|
70
|
-
return h("div", { style: T.row },
|
|
71
|
-
h("div", { style: T.labelBox },
|
|
72
|
-
h("span", { style: T.title }, props.title),
|
|
73
|
-
props.hint ? h("span", { style: T.hint }, props.hint) : null),
|
|
74
|
-
props.children)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const LABELS = {
|
|
78
|
-
enabled: ["接收消息(总)", "关掉后私聊与群聊都不响应"],
|
|
79
|
-
c2c_enabled: ["私聊响应", ""],
|
|
80
|
-
group_enabled: ["群聊响应", ""],
|
|
81
|
-
group_full_mode: ["群全量消息", "需在开放平台开启全量接收"],
|
|
82
|
-
group_at_only: ["群聊只处理 @ 我的消息", "开启后群里的普通发言一律丢弃(仅在拿到全量消息时才需要)"],
|
|
83
|
-
md_auto: ["Markdown 自动发送", "回复像 Markdown 时用 msg_type=2"],
|
|
84
|
-
stream_enabled: ["流式输出(仅私聊)", "平台只在单聊支持流式"],
|
|
85
|
-
ack_enabled: ["“还在处理”占位提示", "会打断流式输出,默认关"],
|
|
86
|
-
quote_enabled: ["识别引用消息", "引用时把被引用原文和来源一起带给模型"],
|
|
87
|
-
capture_enabled: ["允许截屏", "/截图、/窗口 是否可用"],
|
|
88
|
-
auto_group: ["自动分组(每个会话独立工作区)", "关闭则所有会话共用同一个工作目录"],
|
|
89
|
-
approval_inline_redraw: ["审批按钮就地重绘为“已允许”", "关闭后退回旧行为:额外发一条结论文字 + “已处理”卡片"],
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const SWITCHES = ["enabled","c2c_enabled","group_enabled","group_full_mode","group_at_only","md_auto","stream_enabled","ack_enabled","quote_enabled","capture_enabled","auto_group","approval_inline_redraw"]
|
|
93
|
-
.map(function (key) { return [key, LABELS[key][0], LABELS[key][1]] })
|
|
94
|
-
|
|
95
|
-
// 静默时段:开始/结束时间 + 最右侧开关,并实时显示"当前是否静默、下次切换"
|
|
96
|
-
function parseQuiet(value) {
|
|
97
|
-
const text = String(value || "23:30-07:00")
|
|
98
|
-
const parts = text.split("-")
|
|
99
|
-
const ok = parts.length === 2 && /^\d{1,2}:\d{2}$/.test(parts[0].trim()) && /^\d{1,2}:\d{2}$/.test(parts[1].trim())
|
|
100
|
-
return ok ? [parts[0].trim(), parts[1].trim()] : ["23:30", "07:00"]
|
|
101
|
-
}
|
|
102
|
-
function minutesOf(text) { const p = text.split(":"); return Number(p[0]) * 60 + Number(p[1]) }
|
|
103
|
-
function quietStatus(value) {
|
|
104
|
-
const pair = parseQuiet(value)
|
|
105
|
-
const start = minutesOf(pair[0])
|
|
106
|
-
const end = minutesOf(pair[1])
|
|
107
|
-
const now = new Date()
|
|
108
|
-
const mins = now.getHours() * 60 + now.getMinutes()
|
|
109
|
-
const inQuiet = start <= end ? (mins >= start && mins < end) : (mins >= start || mins < end)
|
|
110
|
-
const next = inQuiet ? end : start
|
|
111
|
-
const label = String(Math.floor(next / 60)).padStart(2, "0") + ":" + String(next % 60).padStart(2, "0")
|
|
112
|
-
return { inQuiet, label }
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const NUMBERS = [
|
|
116
|
-
["chatter_batch","攒够几条触发判断",1,30], ["chatter_max_s","最长等待(秒)",5,600],
|
|
117
|
-
["chatter_cooldown_s","判断后冷却(秒)",0,1800], ["bot_say_memory_s","「最近说过」记忆(秒)",30,3600],
|
|
118
|
-
["stuck_turn_s","回合卡死判定(秒)",30,1800], ["ack_delay_s","迟到提示延迟(秒)",0,120],
|
|
119
|
-
["debounce_ms","连发合并(毫秒)",0,5000], ["max_chars","单条最大字数",200,4000],
|
|
120
|
-
["image_max_mb","图片上限(MB)",1,20], ["rate_limit_per_hour","每会话每小时上限(0=不限)",0,240],
|
|
121
|
-
["stream_interval_ms","流式节流(毫秒)",50,2000], ["quote_context_chars","引用原文上限(字)",50,2000],
|
|
122
|
-
["pool_ttl_s","消息池保留(秒)",60,86400], ["pool_max","消息池上限(条)",10,1000],
|
|
123
|
-
]
|
|
124
|
-
|
|
125
|
-
const TEXTS = [
|
|
126
|
-
["group_allowlist","群白名单(openid,逗号分隔)"],
|
|
127
|
-
["c2c_allowlist","私聊白名单(同上)"], ["bot_aliases","群内别名(逗号分隔)"],
|
|
128
|
-
["appid","APPID(留空=用 config.json)"],
|
|
129
|
-
["appsecret","APPSECRET(留空=不变,需重启)"],
|
|
130
|
-
["auto_group_root","自动分组根目录(如 D:\\dsh-qqbot-temp)"],
|
|
131
|
-
,
|
|
132
|
-
]
|
|
133
|
-
|
|
134
|
-
function QQBridgePage() {
|
|
135
|
-
const [state, setState] = React.useState(null)
|
|
136
|
-
const [draft, setDraft] = React.useState({})
|
|
137
|
-
const [message, setMessage] = React.useState("")
|
|
138
|
-
const [busy, setBusy] = React.useState(false)
|
|
139
|
-
const [logs, setLogs] = React.useState([])
|
|
140
|
-
const [paused, setPaused] = React.useState(false)
|
|
141
|
-
const [follow, setFollow] = React.useState(true)
|
|
142
|
-
const logRef = React.useRef(null)
|
|
143
|
-
React.useEffect(function () {
|
|
144
|
-
const node = logRef.current
|
|
145
|
-
if (node && follow) node.scrollTop = node.scrollHeight
|
|
146
|
-
}, [logs, follow])
|
|
147
|
-
|
|
148
|
-
const call = React.useCallback(async function (path, options) {
|
|
149
|
-
const response = await fetch(PANEL + path, Object.assign({ headers: { "content-type": "application/json" } }, options || {}))
|
|
150
|
-
return await response.json()
|
|
151
|
-
}, [])
|
|
152
|
-
|
|
153
|
-
const load = React.useCallback(async function () {
|
|
154
|
-
try { setState(await call("/api/state")) } catch (error) { setState({ offline: true }) }
|
|
155
|
-
}, [call])
|
|
156
|
-
|
|
157
|
-
React.useEffect(function () { load() }, [load])
|
|
158
|
-
React.useEffect(function () {
|
|
159
|
-
const timer = setInterval(load, 8000)
|
|
160
|
-
return function () { clearInterval(timer) }
|
|
161
|
-
}, [load])
|
|
162
|
-
React.useEffect(function () {
|
|
163
|
-
if (paused) return undefined
|
|
164
|
-
let stop = false
|
|
165
|
-
const tick = async function () {
|
|
166
|
-
try {
|
|
167
|
-
const data = await call("/api/logs?lines=200")
|
|
168
|
-
if (!stop) setLogs(Array.isArray(data.lines) ? data.lines : [])
|
|
169
|
-
} catch (error) {
|
|
170
|
-
if (!stop) setLogs(["(日志服务不可达)"])
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
tick()
|
|
174
|
-
const timer = setInterval(tick, 3000)
|
|
175
|
-
return function () { stop = true; clearInterval(timer) }
|
|
176
|
-
}, [call, paused])
|
|
177
|
-
|
|
178
|
-
if (state !== null && state.offline) {
|
|
179
|
-
return h("div", { style: T.page }, h("div", { style: T.inner },
|
|
180
|
-
h("div", { style: T.title }, "机器人的设置服务没有运行"),
|
|
181
|
-
h("div", { style: T.hint }, "用 bot\\run-bot.bat 启动一次(或 python -u main.py --supervise),再点重试。"),
|
|
182
|
-
h("div", { style: T.actions }, h("button", { style: T.btn, onClick: load }, "重试"))))
|
|
183
|
-
}
|
|
184
|
-
if (state === null) return h("div", { style: T.page }, h("div", { style: T.inner }, h("div", { style: T.hint }, "读取中…")))
|
|
185
|
-
|
|
186
|
-
const config = state.config || {}
|
|
187
|
-
const bot = state.bot || {}
|
|
188
|
-
const value = function (key) { return key in draft ? draft[key] : config[key] }
|
|
189
|
-
const setValue = function (key, next) { const copy = Object.assign({}, draft); copy[key] = next; setDraft(copy) }
|
|
190
|
-
const save = async function () {
|
|
191
|
-
setBusy(true)
|
|
192
|
-
try {
|
|
193
|
-
const result = await call("/api/config", { method: "POST", body: JSON.stringify(draft) })
|
|
194
|
-
const unknown = Array.isArray(result.unknown) ? result.unknown : []
|
|
195
|
-
setDraft({})
|
|
196
|
-
setMessage(unknown.length === 0 ? "已保存" : "部分未生效(键不在运行进程里):" + unknown.join(", ") + " —— 需要重启机器人进程")
|
|
197
|
-
await load()
|
|
198
|
-
}
|
|
199
|
-
catch (error) { setMessage("保存失败") }
|
|
200
|
-
setBusy(false)
|
|
201
|
-
}
|
|
202
|
-
const manage = async function (action) {
|
|
203
|
-
setBusy(true)
|
|
204
|
-
try { const result = await call("/api/manage", { method: "POST", body: JSON.stringify({ action: action }) }); setMessage(result.message || action); await load() }
|
|
205
|
-
catch (error) { setMessage("操作失败") }
|
|
206
|
-
setBusy(false)
|
|
207
|
-
}
|
|
208
|
-
const dot = function (ok) {
|
|
209
|
-
return h("span", { style: Object.assign({}, T.dot, { background: ok === true ? "var(--dsw-alias-state-success-primary, #35c759)" : ok === false ? "var(--dsw-alias-label-error, #e5534b)" : "var(--dsw-alias-label-tertiary, #888)" }) })
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return h("div", { style: T.page },
|
|
213
|
-
h("div", { style: T.inner },
|
|
214
|
-
h("div", { style: T.actions },
|
|
215
|
-
h("span", { style: T.badge }, dot(!!bot.running), "进程 · " + (bot.running ? "运行中" : "已停止")),
|
|
216
|
-
h("span", { style: T.badge }, dot(!!bot.online), "在线 · " + (bot.online ? "是" : "否")),
|
|
217
|
-
h("span", { style: T.badge }, dot(state.bridge === "ready"), "桥接 · " + (state.bridge || "?")),
|
|
218
|
-
bot.pid ? h("span", { style: T.hint }, "pid " + bot.pid) : null),
|
|
219
|
-
message ? h("div", { style: T.hint }, message) : null,
|
|
220
|
-
h("div", { style: T.actions },
|
|
221
|
-
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: function () { manage("start") } }, "启动"),
|
|
222
|
-
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("restart") } }, "重启"),
|
|
223
|
-
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("stop") } }, "关闭(不拉起)"),
|
|
224
|
-
h("button", { style: T.btn, onClick: function () { window.open("https://q.qq.com/qqbot/", "_blank", "noopener") } }, "QQ 开放平台"),
|
|
225
|
-
h("button", {
|
|
226
|
-
style: T.btn,
|
|
227
|
-
onClick: async function () {
|
|
228
|
-
const target = String(config.auto_group_root || "D:\\dsh-qqbot-temp")
|
|
229
|
-
try {
|
|
230
|
-
const result = await call("/api/open-folder", { method: "POST", body: JSON.stringify({ path: target }) })
|
|
231
|
-
setMessage(result.ok ? "已打开 " + target : "打不开:" + (result.error || target))
|
|
232
|
-
} catch (error) {
|
|
233
|
-
setMessage("打不开:" + target)
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
}, "打开分组文件夹")),
|
|
237
|
-
h("div", { style: T.sectionTitle }, "开关"),
|
|
238
|
-
SWITCHES.map(function (item) {
|
|
239
|
-
return h(Row, { key: item[0], title: item[1], hint: item[2] },
|
|
240
|
-
h(Switch, { checked: !!value(item[0]), label: item[1], disabled: busy, onChange: function (next) { setValue(item[0], next) } }))
|
|
241
|
-
}),
|
|
242
|
-
h("div", { style: T.sectionTitle }, "群聊节奏与发送"),
|
|
243
|
-
h(QuietRow, {
|
|
244
|
-
key: "quiet-hours",
|
|
245
|
-
value: value("quiet_hours"),
|
|
246
|
-
checked: !!value("quiet_enabled"),
|
|
247
|
-
disabled: busy,
|
|
248
|
-
onChange: function (next) { setValue("quiet_hours", next) },
|
|
249
|
-
onChange2: function (next) { setValue("quiet_enabled", next) },
|
|
250
|
-
}),
|
|
251
|
-
NUMBERS.map(function (item) {
|
|
252
|
-
return h(Row, { key: item[0], title: item[1] },
|
|
253
|
-
h("input", {
|
|
254
|
-
type: "number", min: item[2], max: item[3], style: T.input,
|
|
255
|
-
value: value(item[0]) === undefined ? "" : value(item[0]),
|
|
256
|
-
onChange: function (event) { setValue(item[0], Number(event.target.value)) },
|
|
257
|
-
}))
|
|
258
|
-
}),
|
|
259
|
-
h(ModeRow, {
|
|
260
|
-
key: "group-mode",
|
|
261
|
-
value: value("group_mode"),
|
|
262
|
-
disabled: busy,
|
|
263
|
-
onChange: function (next) { setValue("group_mode", next) },
|
|
264
|
-
}), h("div", { style: T.sectionTitle }, "过滤与凭据"),
|
|
265
|
-
TEXTS.map(function (item) {
|
|
266
|
-
return h(Row, { key: item[0], title: item[1] },
|
|
267
|
-
h("input", {
|
|
268
|
-
type: item[0].indexOf("secret") >= 0 ? "password" : "text",
|
|
269
|
-
placeholder: "不改", style: Object.assign({}, T.input, T.inputWide),
|
|
270
|
-
value: value(item[0]) === undefined ? "" : value(item[0]),
|
|
271
|
-
onChange: function (event) { setValue(item[0], event.target.value) },
|
|
272
|
-
}))
|
|
273
|
-
}),
|
|
274
|
-
h("div", { style: T.actions },
|
|
275
|
-
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: save }, "保存设置"),
|
|
276
|
-
h("button", { style: T.btn, disabled: busy, onClick: function () { setDraft({}); load() } }, "重新读取")),
|
|
277
|
-
h("div", { style: T.sectionTitle }, "运行日志(最近 200 行)"),
|
|
278
|
-
h("div", { style: T.actions },
|
|
279
|
-
h("button", { style: T.btn, onClick: function () { setPaused(!paused) } }, paused ? "继续刷新" : "暂停刷新"),
|
|
280
|
-
h("button", {
|
|
281
|
-
style: Object.assign({}, T.btn, follow ? { borderColor: "var(--dsw-alias-state-business-primary, #2f6bff)", color: "var(--dsw-alias-state-business-primary, #2f6bff)" } : {}),
|
|
282
|
-
onClick: function () { setFollow(!follow) },
|
|
283
|
-
}, follow ? "跟随中" : "已暂停跟随"),
|
|
284
|
-
h("button", { style: T.btn, onClick: function () { setLogs([]) } }, "清屏")),
|
|
285
|
-
h("pre", {
|
|
286
|
-
style: T.log,
|
|
287
|
-
ref: logRef,
|
|
288
|
-
onScroll: function (event) {
|
|
289
|
-
const node = event.target
|
|
290
|
-
// 手动往上翻就暂停跟随;回到底部自动恢复
|
|
291
|
-
setFollow(node.scrollHeight - node.scrollTop - node.clientHeight < 24)
|
|
292
|
-
},
|
|
293
|
-
}, logs.join("\n") || "(暂无日志)")
|
|
294
|
-
))
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function QuietRow(props) {
|
|
298
|
-
const value = String(props.value || "23:30-07:00")
|
|
299
|
-
const pair = parseQuiet(value)
|
|
300
|
-
const status = quietStatus(value)
|
|
301
|
-
const setRange = function (index, next) {
|
|
302
|
-
const parts = parseQuiet(value).slice()
|
|
303
|
-
parts[index] = next || parts[index]
|
|
304
|
-
props.onChange(parts[0] + "-" + parts[1])
|
|
305
|
-
}
|
|
306
|
-
const timeInput = function (index, label) {
|
|
307
|
-
return h("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 } },
|
|
308
|
-
h("span", { style: T.hint }, label),
|
|
309
|
-
h("input", {
|
|
310
|
-
type: "time", value: pair[index], style: Object.assign({}, T.input, { width: 108, textAlign: "center" }),
|
|
311
|
-
onChange: function (event) { setRange(index, event.target.value) },
|
|
312
|
-
}))
|
|
313
|
-
}
|
|
314
|
-
return h("div", { style: Object.assign({}, T.row, { alignItems: "flex-start" }) },
|
|
315
|
-
h("div", { style: T.labelBox },
|
|
316
|
-
h("span", { style: T.title }, "静默时段(晚间群聊闲聊不回)"),
|
|
317
|
-
h("span", { style: T.hint }, "按本机时间:静默时段内群里不主动插话,@ 与私聊照常回复"),
|
|
318
|
-
h("span", { style: T.hint }, (status.inQuiet ? "当前为静默" : "当前不在静默") + " · 下次切换 " + status.label),
|
|
319
|
-
h("div", { style: Object.assign({}, T.actions, { marginTop: 8 }) },
|
|
320
|
-
timeInput(0, "开始"), h("span", { style: T.hint }, "至"), timeInput(1, "结束"))),
|
|
321
|
-
h(Switch, { checked: !!props.checked, label: "静默时段生效", disabled: props.disabled, onChange: props.onChange2 }))
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// 群聊主动消息模式:下拉式二选一(方案 A / 方案 B)
|
|
325
|
-
function ModeRow(props) {
|
|
326
|
-
const current = String(props.value || "A").toUpperCase() === "B" ? "B" : "A"
|
|
327
|
-
const options = [
|
|
328
|
-
["A", "方案 A", "群里先攒几条消息,再由主会话判断要不要说话;跟它已有的对话上下文连着,插话会更自然。"],
|
|
329
|
-
["B", "方案 B", "用一个独立的判断会话先决定“说 / 不说”;决定要说时,把群聊记录原样交给主模型。判断与主对话隔离。"],
|
|
330
|
-
]
|
|
331
|
-
const pill = function (key, label, hint) {
|
|
332
|
-
const active = current === key
|
|
333
|
-
return h("button", {
|
|
334
|
-
key: key,
|
|
335
|
-
type: "button",
|
|
336
|
-
disabled: props.disabled,
|
|
337
|
-
onClick: function () { props.onChange(key) },
|
|
338
|
-
style: {
|
|
339
|
-
padding: "6px 16px", borderRadius: 999, cursor: props.disabled ? "default" : "pointer", font: "inherit",
|
|
340
|
-
border: "1px solid " + (active ? "var(--dsw-alias-label-primary, #fff)" : "var(--dsw-alias-border-l2)"),
|
|
341
|
-
background: active ? "var(--dsw-alias-label-primary, #fff)" : "transparent",
|
|
342
|
-
color: active ? "var(--dsw-alias-bg-layer-3, #1b1d23)" : "var(--dsw-alias-label-secondary)",
|
|
343
|
-
},
|
|
344
|
-
}, label)
|
|
345
|
-
}
|
|
346
|
-
const pick = options.filter(function (item) { return item[0] === current })[0]
|
|
347
|
-
return h("div", { style: Object.assign({}, T.row, { alignItems: "flex-start" }) },
|
|
348
|
-
h("div", { style: T.labelBox },
|
|
349
|
-
h("span", { style: T.title }, "群聊主动消息模式"),
|
|
350
|
-
h("span", { style: T.hint }, pick[2])),
|
|
351
|
-
h("div", { style: Object.assign({}, T.actions, { flex: "0 0 auto" }) },
|
|
352
|
-
options.map(function (item) { return pill(item[0], item[1], item[2]) })))
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function SidebarIcon() {
|
|
356
|
-
return h("span", { "aria-hidden": "true", style: { fontSize: 15, lineHeight: 1 } }, "🐟")
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
exports.inject = ["slots"]
|
|
360
|
-
exports.apply = function apply(ctx) {
|
|
361
|
-
ctx.slots.inject("sidebar.panellist", function () {
|
|
362
|
-
const unregister = ctx.slots.register({ name: "sidebar.panellist", id: "qq-bridge", order: 120, label: function () { return "QQ 机器人" } }, SidebarIcon)
|
|
363
|
-
return function () { unregister() }
|
|
364
|
-
})
|
|
365
|
-
ctx.slots.inject("main", function () {
|
|
366
|
-
const unregister = ctx.slots.register({ name: "main", key: "qq-bridge", order: 120, label: function () { return "QQ 机器人" } }, QQBridgePage)
|
|
367
|
-
return function () { unregister() }
|
|
368
|
-
})
|
|
369
|
-
}
|
|
370
|
-
return module.exports
|
|
371
|
-
},
|
|
372
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* dsh-qq-bridge 的浏览器半身:左侧导航栏「QQ 机器人」+ 整页设置/日志。
|
|
3
|
+
* 全部改用内联样式:宿主 main 槽位不在同一个样式作用域,注入 <style> 不可靠。
|
|
4
|
+
*/
|
|
5
|
+
window.__ModuleLoader__.load({
|
|
6
|
+
id: "dsh-qq-bridge",
|
|
7
|
+
factory: (require) => {
|
|
8
|
+
var module = { exports: {} }
|
|
9
|
+
var exports = module.exports
|
|
10
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
|
|
11
|
+
|
|
12
|
+
const React = require("react")
|
|
13
|
+
const h = React.createElement
|
|
14
|
+
const PANEL = "http://127.0.0.1:39062"
|
|
15
|
+
|
|
16
|
+
const T = {
|
|
17
|
+
page: { width: "100%", height: "100%", minHeight: 0, overflow: "auto", boxSizing: "border-box", padding: "24px clamp(16px,4vw,48px) 32px", color: "var(--dsw-alias-label-primary)", fontFamily: "var(--dsw-font-family, inherit)" },
|
|
18
|
+
inner: {
|
|
19
|
+
width: "100%", maxWidth: 720, margin: "0 auto", display: "grid", gap: 14,
|
|
20
|
+
// 磨砂玻璃底:页面浮在背景图之上时保证文字可读
|
|
21
|
+
padding: "20px 22px", borderRadius: 16,
|
|
22
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(255,255,255,0.14))",
|
|
23
|
+
backgroundColor: "rgba(22, 24, 30, 0.62)",
|
|
24
|
+
background: "color-mix(in srgb, var(--dsw-alias-bg-base, #14161c) 72%, transparent)",
|
|
25
|
+
backdropFilter: "blur(18px) saturate(130%)",
|
|
26
|
+
WebkitBackdropFilter: "blur(18px) saturate(130%)",
|
|
27
|
+
boxShadow: "0 10px 30px rgba(0,0,0,0.24)",
|
|
28
|
+
},
|
|
29
|
+
row: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 24, padding: "9px 0", borderTop: "1px solid var(--dsw-alias-border-l2)" },
|
|
30
|
+
labelBox: { display: "grid", gap: 2, minWidth: 0 },
|
|
31
|
+
title: { fontSize: 13, color: "var(--dsw-alias-label-primary)" },
|
|
32
|
+
hint: { fontSize: 12, color: "var(--dsw-alias-label-tertiary)" },
|
|
33
|
+
sectionTitle: { fontSize: 12, letterSpacing: "0.04em", color: "var(--dsw-alias-label-tertiary)", margin: "10px 0 2px" },
|
|
34
|
+
input: { width: 132, padding: "5px 8px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-primary)", font: "inherit", textAlign: "right" },
|
|
35
|
+
inputWide: { width: 260, textAlign: "left" },
|
|
36
|
+
btn: { padding: "6px 14px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "transparent", color: "var(--dsw-alias-label-primary)", font: "inherit", cursor: "pointer" },
|
|
37
|
+
btnPrimary: { background: "var(--dsw-alias-label-primary)", borderColor: "var(--dsw-alias-label-primary)", color: "var(--dsw-alias-bg-layer-3)" },
|
|
38
|
+
actions: { display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center" },
|
|
39
|
+
badge: { display: "inline-flex", alignItems: "center", gap: 6, padding: "3px 9px", border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 999, fontSize: 12, color: "var(--dsw-alias-label-secondary)" },
|
|
40
|
+
dot: { width: 7, height: 7, borderRadius: "50%" },
|
|
41
|
+
log: { margin: 0, maxHeight: 300, overflow: "auto", padding: 10, border: "1px solid var(--dsw-alias-border-l2)", borderRadius: 6, background: "var(--dsw-alias-bg-layer-3)", color: "var(--dsw-alias-label-secondary)", font: "12px/1.5 ui-monospace, Consolas, monospace", whiteSpace: "pre-wrap" },
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Switch(props) {
|
|
45
|
+
return h("button", {
|
|
46
|
+
type: "button", role: "switch", "aria-checked": props.checked ? "true" : "false",
|
|
47
|
+
"aria-label": props.label, disabled: props.disabled,
|
|
48
|
+
onClick: function () { props.onChange(!props.checked) },
|
|
49
|
+
style: {
|
|
50
|
+
position: "relative", flex: "0 0 auto", width: 38, height: 22, padding: 2, border: 0,
|
|
51
|
+
borderRadius: 999, cursor: props.disabled ? "default" : "pointer", boxSizing: "border-box",
|
|
52
|
+
// 用官方语义色:开启=业务主色,关闭=边框 L3(不再用不存在的 brand-primary 导致发白)
|
|
53
|
+
background: props.checked
|
|
54
|
+
? "var(--dsw-alias-state-business-primary, #2f6bff)"
|
|
55
|
+
: "var(--dsw-alias-border-l3, #5a6270)",
|
|
56
|
+
boxShadow: props.checked ? "inset 0 0 0 1px rgba(255,255,255,0.12)" : "none",
|
|
57
|
+
opacity: props.disabled ? 0.5 : 1,
|
|
58
|
+
},
|
|
59
|
+
}, h("span", {
|
|
60
|
+
"aria-hidden": "true",
|
|
61
|
+
style: {
|
|
62
|
+
display: "block", width: 18, height: 18, borderRadius: "50%",
|
|
63
|
+
background: props.checked ? "#fff" : "var(--dsw-alias-switch-thumb, #c9ccd6)",
|
|
64
|
+
transform: props.checked ? "translateX(16px)" : "none", transition: "transform 120ms ease",
|
|
65
|
+
},
|
|
66
|
+
}))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function Row(props) {
|
|
70
|
+
return h("div", { style: T.row },
|
|
71
|
+
h("div", { style: T.labelBox },
|
|
72
|
+
h("span", { style: T.title }, props.title),
|
|
73
|
+
props.hint ? h("span", { style: T.hint }, props.hint) : null),
|
|
74
|
+
props.children)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const LABELS = {
|
|
78
|
+
enabled: ["接收消息(总)", "关掉后私聊与群聊都不响应"],
|
|
79
|
+
c2c_enabled: ["私聊响应", ""],
|
|
80
|
+
group_enabled: ["群聊响应", ""],
|
|
81
|
+
group_full_mode: ["群全量消息", "需在开放平台开启全量接收"],
|
|
82
|
+
group_at_only: ["群聊只处理 @ 我的消息", "开启后群里的普通发言一律丢弃(仅在拿到全量消息时才需要)"],
|
|
83
|
+
md_auto: ["Markdown 自动发送", "回复像 Markdown 时用 msg_type=2"],
|
|
84
|
+
stream_enabled: ["流式输出(仅私聊)", "平台只在单聊支持流式"],
|
|
85
|
+
ack_enabled: ["“还在处理”占位提示", "会打断流式输出,默认关"],
|
|
86
|
+
quote_enabled: ["识别引用消息", "引用时把被引用原文和来源一起带给模型"],
|
|
87
|
+
capture_enabled: ["允许截屏", "/截图、/窗口 是否可用"],
|
|
88
|
+
auto_group: ["自动分组(每个会话独立工作区)", "关闭则所有会话共用同一个工作目录"],
|
|
89
|
+
approval_inline_redraw: ["审批按钮就地重绘为“已允许”", "关闭后退回旧行为:额外发一条结论文字 + “已处理”卡片"],
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const SWITCHES = ["enabled","c2c_enabled","group_enabled","group_full_mode","group_at_only","md_auto","stream_enabled","ack_enabled","quote_enabled","capture_enabled","auto_group","approval_inline_redraw"]
|
|
93
|
+
.map(function (key) { return [key, LABELS[key][0], LABELS[key][1]] })
|
|
94
|
+
|
|
95
|
+
// 静默时段:开始/结束时间 + 最右侧开关,并实时显示"当前是否静默、下次切换"
|
|
96
|
+
function parseQuiet(value) {
|
|
97
|
+
const text = String(value || "23:30-07:00")
|
|
98
|
+
const parts = text.split("-")
|
|
99
|
+
const ok = parts.length === 2 && /^\d{1,2}:\d{2}$/.test(parts[0].trim()) && /^\d{1,2}:\d{2}$/.test(parts[1].trim())
|
|
100
|
+
return ok ? [parts[0].trim(), parts[1].trim()] : ["23:30", "07:00"]
|
|
101
|
+
}
|
|
102
|
+
function minutesOf(text) { const p = text.split(":"); return Number(p[0]) * 60 + Number(p[1]) }
|
|
103
|
+
function quietStatus(value) {
|
|
104
|
+
const pair = parseQuiet(value)
|
|
105
|
+
const start = minutesOf(pair[0])
|
|
106
|
+
const end = minutesOf(pair[1])
|
|
107
|
+
const now = new Date()
|
|
108
|
+
const mins = now.getHours() * 60 + now.getMinutes()
|
|
109
|
+
const inQuiet = start <= end ? (mins >= start && mins < end) : (mins >= start || mins < end)
|
|
110
|
+
const next = inQuiet ? end : start
|
|
111
|
+
const label = String(Math.floor(next / 60)).padStart(2, "0") + ":" + String(next % 60).padStart(2, "0")
|
|
112
|
+
return { inQuiet, label }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const NUMBERS = [
|
|
116
|
+
["chatter_batch","攒够几条触发判断",1,30], ["chatter_max_s","最长等待(秒)",5,600],
|
|
117
|
+
["chatter_cooldown_s","判断后冷却(秒)",0,1800], ["bot_say_memory_s","「最近说过」记忆(秒)",30,3600],
|
|
118
|
+
["stuck_turn_s","回合卡死判定(秒)",30,1800], ["ack_delay_s","迟到提示延迟(秒)",0,120],
|
|
119
|
+
["debounce_ms","连发合并(毫秒)",0,5000], ["max_chars","单条最大字数",200,4000],
|
|
120
|
+
["image_max_mb","图片上限(MB)",1,20], ["rate_limit_per_hour","每会话每小时上限(0=不限)",0,240],
|
|
121
|
+
["stream_interval_ms","流式节流(毫秒)",50,2000], ["quote_context_chars","引用原文上限(字)",50,2000],
|
|
122
|
+
["pool_ttl_s","消息池保留(秒)",60,86400], ["pool_max","消息池上限(条)",10,1000],
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
const TEXTS = [
|
|
126
|
+
["group_allowlist","群白名单(openid,逗号分隔)"],
|
|
127
|
+
["c2c_allowlist","私聊白名单(同上)"], ["bot_aliases","群内别名(逗号分隔)"],
|
|
128
|
+
["appid","APPID(留空=用 config.json)"],
|
|
129
|
+
["appsecret","APPSECRET(留空=不变,需重启)"],
|
|
130
|
+
["auto_group_root","自动分组根目录(如 D:\\dsh-qqbot-temp)"],
|
|
131
|
+
,
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
function QQBridgePage() {
|
|
135
|
+
const [state, setState] = React.useState(null)
|
|
136
|
+
const [draft, setDraft] = React.useState({})
|
|
137
|
+
const [message, setMessage] = React.useState("")
|
|
138
|
+
const [busy, setBusy] = React.useState(false)
|
|
139
|
+
const [logs, setLogs] = React.useState([])
|
|
140
|
+
const [paused, setPaused] = React.useState(false)
|
|
141
|
+
const [follow, setFollow] = React.useState(true)
|
|
142
|
+
const logRef = React.useRef(null)
|
|
143
|
+
React.useEffect(function () {
|
|
144
|
+
const node = logRef.current
|
|
145
|
+
if (node && follow) node.scrollTop = node.scrollHeight
|
|
146
|
+
}, [logs, follow])
|
|
147
|
+
|
|
148
|
+
const call = React.useCallback(async function (path, options) {
|
|
149
|
+
const response = await fetch(PANEL + path, Object.assign({ headers: { "content-type": "application/json" } }, options || {}))
|
|
150
|
+
return await response.json()
|
|
151
|
+
}, [])
|
|
152
|
+
|
|
153
|
+
const load = React.useCallback(async function () {
|
|
154
|
+
try { setState(await call("/api/state")) } catch (error) { setState({ offline: true }) }
|
|
155
|
+
}, [call])
|
|
156
|
+
|
|
157
|
+
React.useEffect(function () { load() }, [load])
|
|
158
|
+
React.useEffect(function () {
|
|
159
|
+
const timer = setInterval(load, 8000)
|
|
160
|
+
return function () { clearInterval(timer) }
|
|
161
|
+
}, [load])
|
|
162
|
+
React.useEffect(function () {
|
|
163
|
+
if (paused) return undefined
|
|
164
|
+
let stop = false
|
|
165
|
+
const tick = async function () {
|
|
166
|
+
try {
|
|
167
|
+
const data = await call("/api/logs?lines=200")
|
|
168
|
+
if (!stop) setLogs(Array.isArray(data.lines) ? data.lines : [])
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (!stop) setLogs(["(日志服务不可达)"])
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
tick()
|
|
174
|
+
const timer = setInterval(tick, 3000)
|
|
175
|
+
return function () { stop = true; clearInterval(timer) }
|
|
176
|
+
}, [call, paused])
|
|
177
|
+
|
|
178
|
+
if (state !== null && state.offline) {
|
|
179
|
+
return h("div", { style: T.page }, h("div", { style: T.inner },
|
|
180
|
+
h("div", { style: T.title }, "机器人的设置服务没有运行"),
|
|
181
|
+
h("div", { style: T.hint }, "用 bot\\run-bot.bat 启动一次(或 python -u main.py --supervise),再点重试。"),
|
|
182
|
+
h("div", { style: T.actions }, h("button", { style: T.btn, onClick: load }, "重试"))))
|
|
183
|
+
}
|
|
184
|
+
if (state === null) return h("div", { style: T.page }, h("div", { style: T.inner }, h("div", { style: T.hint }, "读取中…")))
|
|
185
|
+
|
|
186
|
+
const config = state.config || {}
|
|
187
|
+
const bot = state.bot || {}
|
|
188
|
+
const value = function (key) { return key in draft ? draft[key] : config[key] }
|
|
189
|
+
const setValue = function (key, next) { const copy = Object.assign({}, draft); copy[key] = next; setDraft(copy) }
|
|
190
|
+
const save = async function () {
|
|
191
|
+
setBusy(true)
|
|
192
|
+
try {
|
|
193
|
+
const result = await call("/api/config", { method: "POST", body: JSON.stringify(draft) })
|
|
194
|
+
const unknown = Array.isArray(result.unknown) ? result.unknown : []
|
|
195
|
+
setDraft({})
|
|
196
|
+
setMessage(unknown.length === 0 ? "已保存" : "部分未生效(键不在运行进程里):" + unknown.join(", ") + " —— 需要重启机器人进程")
|
|
197
|
+
await load()
|
|
198
|
+
}
|
|
199
|
+
catch (error) { setMessage("保存失败") }
|
|
200
|
+
setBusy(false)
|
|
201
|
+
}
|
|
202
|
+
const manage = async function (action) {
|
|
203
|
+
setBusy(true)
|
|
204
|
+
try { const result = await call("/api/manage", { method: "POST", body: JSON.stringify({ action: action }) }); setMessage(result.message || action); await load() }
|
|
205
|
+
catch (error) { setMessage("操作失败") }
|
|
206
|
+
setBusy(false)
|
|
207
|
+
}
|
|
208
|
+
const dot = function (ok) {
|
|
209
|
+
return h("span", { style: Object.assign({}, T.dot, { background: ok === true ? "var(--dsw-alias-state-success-primary, #35c759)" : ok === false ? "var(--dsw-alias-label-error, #e5534b)" : "var(--dsw-alias-label-tertiary, #888)" }) })
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return h("div", { style: T.page },
|
|
213
|
+
h("div", { style: T.inner },
|
|
214
|
+
h("div", { style: T.actions },
|
|
215
|
+
h("span", { style: T.badge }, dot(!!bot.running), "进程 · " + (bot.running ? "运行中" : "已停止")),
|
|
216
|
+
h("span", { style: T.badge }, dot(!!bot.online), "在线 · " + (bot.online ? "是" : "否")),
|
|
217
|
+
h("span", { style: T.badge }, dot(state.bridge === "ready"), "桥接 · " + (state.bridge || "?")),
|
|
218
|
+
bot.pid ? h("span", { style: T.hint }, "pid " + bot.pid) : null),
|
|
219
|
+
message ? h("div", { style: T.hint }, message) : null,
|
|
220
|
+
h("div", { style: T.actions },
|
|
221
|
+
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: function () { manage("start") } }, "启动"),
|
|
222
|
+
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("restart") } }, "重启"),
|
|
223
|
+
h("button", { style: T.btn, disabled: busy, onClick: function () { manage("stop") } }, "关闭(不拉起)"),
|
|
224
|
+
h("button", { style: T.btn, onClick: function () { window.open("https://q.qq.com/qqbot/", "_blank", "noopener") } }, "QQ 开放平台"),
|
|
225
|
+
h("button", {
|
|
226
|
+
style: T.btn,
|
|
227
|
+
onClick: async function () {
|
|
228
|
+
const target = String(config.auto_group_root || "D:\\dsh-qqbot-temp")
|
|
229
|
+
try {
|
|
230
|
+
const result = await call("/api/open-folder", { method: "POST", body: JSON.stringify({ path: target }) })
|
|
231
|
+
setMessage(result.ok ? "已打开 " + target : "打不开:" + (result.error || target))
|
|
232
|
+
} catch (error) {
|
|
233
|
+
setMessage("打不开:" + target)
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
}, "打开分组文件夹")),
|
|
237
|
+
h("div", { style: T.sectionTitle }, "开关"),
|
|
238
|
+
SWITCHES.map(function (item) {
|
|
239
|
+
return h(Row, { key: item[0], title: item[1], hint: item[2] },
|
|
240
|
+
h(Switch, { checked: !!value(item[0]), label: item[1], disabled: busy, onChange: function (next) { setValue(item[0], next) } }))
|
|
241
|
+
}),
|
|
242
|
+
h("div", { style: T.sectionTitle }, "群聊节奏与发送"),
|
|
243
|
+
h(QuietRow, {
|
|
244
|
+
key: "quiet-hours",
|
|
245
|
+
value: value("quiet_hours"),
|
|
246
|
+
checked: !!value("quiet_enabled"),
|
|
247
|
+
disabled: busy,
|
|
248
|
+
onChange: function (next) { setValue("quiet_hours", next) },
|
|
249
|
+
onChange2: function (next) { setValue("quiet_enabled", next) },
|
|
250
|
+
}),
|
|
251
|
+
NUMBERS.map(function (item) {
|
|
252
|
+
return h(Row, { key: item[0], title: item[1] },
|
|
253
|
+
h("input", {
|
|
254
|
+
type: "number", min: item[2], max: item[3], style: T.input,
|
|
255
|
+
value: value(item[0]) === undefined ? "" : value(item[0]),
|
|
256
|
+
onChange: function (event) { setValue(item[0], Number(event.target.value)) },
|
|
257
|
+
}))
|
|
258
|
+
}),
|
|
259
|
+
h(ModeRow, {
|
|
260
|
+
key: "group-mode",
|
|
261
|
+
value: value("group_mode"),
|
|
262
|
+
disabled: busy,
|
|
263
|
+
onChange: function (next) { setValue("group_mode", next) },
|
|
264
|
+
}), h("div", { style: T.sectionTitle }, "过滤与凭据"),
|
|
265
|
+
TEXTS.map(function (item) {
|
|
266
|
+
return h(Row, { key: item[0], title: item[1] },
|
|
267
|
+
h("input", {
|
|
268
|
+
type: item[0].indexOf("secret") >= 0 ? "password" : "text",
|
|
269
|
+
placeholder: "不改", style: Object.assign({}, T.input, T.inputWide),
|
|
270
|
+
value: value(item[0]) === undefined ? "" : value(item[0]),
|
|
271
|
+
onChange: function (event) { setValue(item[0], event.target.value) },
|
|
272
|
+
}))
|
|
273
|
+
}),
|
|
274
|
+
h("div", { style: T.actions },
|
|
275
|
+
h("button", { style: Object.assign({}, T.btn, T.btnPrimary), disabled: busy, onClick: save }, "保存设置"),
|
|
276
|
+
h("button", { style: T.btn, disabled: busy, onClick: function () { setDraft({}); load() } }, "重新读取")),
|
|
277
|
+
h("div", { style: T.sectionTitle }, "运行日志(最近 200 行)"),
|
|
278
|
+
h("div", { style: T.actions },
|
|
279
|
+
h("button", { style: T.btn, onClick: function () { setPaused(!paused) } }, paused ? "继续刷新" : "暂停刷新"),
|
|
280
|
+
h("button", {
|
|
281
|
+
style: Object.assign({}, T.btn, follow ? { borderColor: "var(--dsw-alias-state-business-primary, #2f6bff)", color: "var(--dsw-alias-state-business-primary, #2f6bff)" } : {}),
|
|
282
|
+
onClick: function () { setFollow(!follow) },
|
|
283
|
+
}, follow ? "跟随中" : "已暂停跟随"),
|
|
284
|
+
h("button", { style: T.btn, onClick: function () { setLogs([]) } }, "清屏")),
|
|
285
|
+
h("pre", {
|
|
286
|
+
style: T.log,
|
|
287
|
+
ref: logRef,
|
|
288
|
+
onScroll: function (event) {
|
|
289
|
+
const node = event.target
|
|
290
|
+
// 手动往上翻就暂停跟随;回到底部自动恢复
|
|
291
|
+
setFollow(node.scrollHeight - node.scrollTop - node.clientHeight < 24)
|
|
292
|
+
},
|
|
293
|
+
}, logs.join("\n") || "(暂无日志)")
|
|
294
|
+
))
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function QuietRow(props) {
|
|
298
|
+
const value = String(props.value || "23:30-07:00")
|
|
299
|
+
const pair = parseQuiet(value)
|
|
300
|
+
const status = quietStatus(value)
|
|
301
|
+
const setRange = function (index, next) {
|
|
302
|
+
const parts = parseQuiet(value).slice()
|
|
303
|
+
parts[index] = next || parts[index]
|
|
304
|
+
props.onChange(parts[0] + "-" + parts[1])
|
|
305
|
+
}
|
|
306
|
+
const timeInput = function (index, label) {
|
|
307
|
+
return h("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 } },
|
|
308
|
+
h("span", { style: T.hint }, label),
|
|
309
|
+
h("input", {
|
|
310
|
+
type: "time", value: pair[index], style: Object.assign({}, T.input, { width: 108, textAlign: "center" }),
|
|
311
|
+
onChange: function (event) { setRange(index, event.target.value) },
|
|
312
|
+
}))
|
|
313
|
+
}
|
|
314
|
+
return h("div", { style: Object.assign({}, T.row, { alignItems: "flex-start" }) },
|
|
315
|
+
h("div", { style: T.labelBox },
|
|
316
|
+
h("span", { style: T.title }, "静默时段(晚间群聊闲聊不回)"),
|
|
317
|
+
h("span", { style: T.hint }, "按本机时间:静默时段内群里不主动插话,@ 与私聊照常回复"),
|
|
318
|
+
h("span", { style: T.hint }, (status.inQuiet ? "当前为静默" : "当前不在静默") + " · 下次切换 " + status.label),
|
|
319
|
+
h("div", { style: Object.assign({}, T.actions, { marginTop: 8 }) },
|
|
320
|
+
timeInput(0, "开始"), h("span", { style: T.hint }, "至"), timeInput(1, "结束"))),
|
|
321
|
+
h(Switch, { checked: !!props.checked, label: "静默时段生效", disabled: props.disabled, onChange: props.onChange2 }))
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// 群聊主动消息模式:下拉式二选一(方案 A / 方案 B)
|
|
325
|
+
function ModeRow(props) {
|
|
326
|
+
const current = String(props.value || "A").toUpperCase() === "B" ? "B" : "A"
|
|
327
|
+
const options = [
|
|
328
|
+
["A", "方案 A", "群里先攒几条消息,再由主会话判断要不要说话;跟它已有的对话上下文连着,插话会更自然。"],
|
|
329
|
+
["B", "方案 B", "用一个独立的判断会话先决定“说 / 不说”;决定要说时,把群聊记录原样交给主模型。判断与主对话隔离。"],
|
|
330
|
+
]
|
|
331
|
+
const pill = function (key, label, hint) {
|
|
332
|
+
const active = current === key
|
|
333
|
+
return h("button", {
|
|
334
|
+
key: key,
|
|
335
|
+
type: "button",
|
|
336
|
+
disabled: props.disabled,
|
|
337
|
+
onClick: function () { props.onChange(key) },
|
|
338
|
+
style: {
|
|
339
|
+
padding: "6px 16px", borderRadius: 999, cursor: props.disabled ? "default" : "pointer", font: "inherit",
|
|
340
|
+
border: "1px solid " + (active ? "var(--dsw-alias-label-primary, #fff)" : "var(--dsw-alias-border-l2)"),
|
|
341
|
+
background: active ? "var(--dsw-alias-label-primary, #fff)" : "transparent",
|
|
342
|
+
color: active ? "var(--dsw-alias-bg-layer-3, #1b1d23)" : "var(--dsw-alias-label-secondary)",
|
|
343
|
+
},
|
|
344
|
+
}, label)
|
|
345
|
+
}
|
|
346
|
+
const pick = options.filter(function (item) { return item[0] === current })[0]
|
|
347
|
+
return h("div", { style: Object.assign({}, T.row, { alignItems: "flex-start" }) },
|
|
348
|
+
h("div", { style: T.labelBox },
|
|
349
|
+
h("span", { style: T.title }, "群聊主动消息模式"),
|
|
350
|
+
h("span", { style: T.hint }, pick[2])),
|
|
351
|
+
h("div", { style: Object.assign({}, T.actions, { flex: "0 0 auto" }) },
|
|
352
|
+
options.map(function (item) { return pill(item[0], item[1], item[2]) })))
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function SidebarIcon() {
|
|
356
|
+
return h("span", { "aria-hidden": "true", style: { fontSize: 15, lineHeight: 1 } }, "🐟")
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
exports.inject = ["slots"]
|
|
360
|
+
exports.apply = function apply(ctx) {
|
|
361
|
+
ctx.slots.inject("sidebar.panellist", function () {
|
|
362
|
+
const unregister = ctx.slots.register({ name: "sidebar.panellist", id: "qq-bridge", order: 120, label: function () { return "QQ 机器人" } }, SidebarIcon)
|
|
363
|
+
return function () { unregister() }
|
|
364
|
+
})
|
|
365
|
+
ctx.slots.inject("main", function () {
|
|
366
|
+
const unregister = ctx.slots.register({ name: "main", key: "qq-bridge", order: 120, label: function () { return "QQ 机器人" } }, QQBridgePage)
|
|
367
|
+
return function () { unregister() }
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
return module.exports
|
|
371
|
+
},
|
|
372
|
+
})
|