refactor(qdreader): align account menu with rabbit pattern

This commit is contained in:
2026-05-23 00:18:57 +08:00
parent 56808b9f18
commit 50824baae4
3 changed files with 42 additions and 73 deletions
+10 -24
View File
@@ -4,7 +4,7 @@
//[author: Hermes]
//[service: BOSS]
//[class: 工具类]
// [version: 2.13.0]
// [version: 2.14.0]
// [platform: web,qq,wx,tg,tb,fs,we]
// [public: false]
// [price: 0]
@@ -279,7 +279,7 @@ function contentText() {
}
function usage() {
return [
"启点读书签到插件 v2.13.0",
"启点读书签到插件 v2.14.0",
"【一级菜单】",
"账号管理:启点账号",
"执行查询:启点查询",
@@ -971,18 +971,17 @@ function listenInput(timeoutMs) {
function accountMenuText(store, bind) {
var uids = visibleUids(store || getStore(), bind || getBindStore(), false)
var remarks = remarksForStore(store || {})
var lines = ["启点账号管理"]
if (!uids.length) lines.push("当前用户还没有保存启点读书CK")
var lines = ["启点账号管理", "账号列表如下:"]
if (!uids.length) lines.push("暂无账号,请回复 0 添加/更新账号")
else {
lines.push("现有账号:")
for (var i = 0; i < uids.length; i++) {
var uid = uids[i]
lines.push((i + 1) + ". " + maskUid(uid) + (remarks[uid] ? "" + remarks[uid] + "" : ""))
lines.push((i + 1) + "" + maskUid(uid) + (remarks[uid] ? "[" + remarks[uid] + "]" : ""))
}
}
lines.push("回复编号进入账号配置,例如 1")
lines.push("回复负编号删除账号,例如 -1")
lines.push("回复 a 添加/更新账号;all 清空账号;q 退出")
lines.push("0、添加/更新账号")
lines.push("负编号删除账号,例如 -1")
lines.push("q、退出")
return lines.join("\n")
}
function queryMenuText() {
@@ -1061,7 +1060,7 @@ function accountDetailText(uid, store, bind) {
function accountConfigText(uid, store, bind) {
var detail = accountDetailText(uid, store, bind)
if (/^(无权|未找到)/.test(detail)) return detail
return detail + "\n\n账号配置\n1. 修改备注\n2. 任务配置\n3. 立即签到该账号\n-1. 删除该账号\nq. 返回/退出\n请回复选项"
return detail + "\n\n账号操作\n1修改备注\n2任务配置\n3立即签到该账号\n-1删除该账号\nq返回/退出"
}
function accountConfigMenu(uid, store, bind) {
if (!uid) return reply("未选择账号,已退出")
@@ -1094,7 +1093,7 @@ function accountMenu(store, bind) {
reply(accountMenuText(store, bind))
var op = listenInput(60000)
if (!op || /^(q|退出|取消)$/i.test(op)) return reply("已退出")
if (/^(a|add|添加|新增|更新)$/i.test(op)) {
if (/^(0|a|add|添加|新增|更新)$/i.test(op)) {
reply("请在60秒内发送 QX 抓到的完整 Cookieq:退出)")
var ck = listenInput(60000)
if (!ck || /^(q|退出|取消)$/i.test(ck)) return reply("已退出")
@@ -1102,7 +1101,6 @@ function accountMenu(store, bind) {
var remarkMsg = (save.ok && save.uids.length === 1) ? maybePromptRemark(save.uids[0], store) : ""
return reply(save.text + remarkMsg)
}
if (/^(all|清空|全部)$/i.test(op)) return reply(handleDelete("删除 all", store, bind))
var n = parseInt(op, 10)
if (!isNaN(n) && String(n) === op.replace(/^\+/, "")) {
if (n > 0) {
@@ -1115,18 +1113,6 @@ function accountMenu(store, bind) {
return reply(handleDelete("删除 " + uids[idx - 1], store, bind))
}
}
if (/^(查看|查询|列表|账号)$/i.test(op)) return reply(accountListText(store, bind))
if (/^(详情|备注|改名|名称)$/i.test(op)) return accountDetailMenu(store, bind)
if (/^(任务|配置|开关)$/i.test(op)) {
var taskUid = chooseUid(store, bind, "请选择要配置任务的账号:")
if (!taskUid) return reply("已退出")
return taskMenuForUid(taskUid)
}
if (/^(删除)$/i.test(op)) {
var uid = chooseUid(store, bind, "请选择要删除的账号:")
if (!uid) return reply("已退出")
return reply(handleDelete("删除 " + uid, store, bind))
}
return reply("未识别选项,已退出")
}
function queryMenu() {
+10 -24
View File
@@ -4,7 +4,7 @@
//[author: Hermes]
//[service: BOSS]
//[class: 工具类]
// [version: 2.13.0]
// [version: 2.14.0]
// [platform: web,qq,wx,tg,tb,fs,we]
// [public: false]
// [price: 0]
@@ -279,7 +279,7 @@ function contentText() {
}
function usage() {
return [
"启点读书签到插件 v2.13.0",
"启点读书签到插件 v2.14.0",
"【一级菜单】",
"账号管理:启点账号",
"执行查询:启点查询",
@@ -971,18 +971,17 @@ function listenInput(timeoutMs) {
function accountMenuText(store, bind) {
var uids = visibleUids(store || getStore(), bind || getBindStore(), false)
var remarks = remarksForStore(store || {})
var lines = ["启点账号管理"]
if (!uids.length) lines.push("当前用户还没有保存启点读书CK")
var lines = ["启点账号管理", "账号列表如下:"]
if (!uids.length) lines.push("暂无账号,请回复 0 添加/更新账号")
else {
lines.push("现有账号:")
for (var i = 0; i < uids.length; i++) {
var uid = uids[i]
lines.push((i + 1) + ". " + maskUid(uid) + (remarks[uid] ? "" + remarks[uid] + "" : ""))
lines.push((i + 1) + "" + maskUid(uid) + (remarks[uid] ? "[" + remarks[uid] + "]" : ""))
}
}
lines.push("回复编号进入账号配置,例如 1")
lines.push("回复负编号删除账号,例如 -1")
lines.push("回复 a 添加/更新账号;all 清空账号;q 退出")
lines.push("0、添加/更新账号")
lines.push("负编号删除账号,例如 -1")
lines.push("q、退出")
return lines.join("\n")
}
function queryMenuText() {
@@ -1061,7 +1060,7 @@ function accountDetailText(uid, store, bind) {
function accountConfigText(uid, store, bind) {
var detail = accountDetailText(uid, store, bind)
if (/^(无权|未找到)/.test(detail)) return detail
return detail + "\n\n账号配置\n1. 修改备注\n2. 任务配置\n3. 立即签到该账号\n-1. 删除该账号\nq. 返回/退出\n请回复选项"
return detail + "\n\n账号操作\n1修改备注\n2任务配置\n3立即签到该账号\n-1删除该账号\nq返回/退出"
}
function accountConfigMenu(uid, store, bind) {
if (!uid) return reply("未选择账号,已退出")
@@ -1094,7 +1093,7 @@ function accountMenu(store, bind) {
reply(accountMenuText(store, bind))
var op = listenInput(60000)
if (!op || /^(q|退出|取消)$/i.test(op)) return reply("已退出")
if (/^(a|add|添加|新增|更新)$/i.test(op)) {
if (/^(0|a|add|添加|新增|更新)$/i.test(op)) {
reply("请在60秒内发送 QX 抓到的完整 Cookieq:退出)")
var ck = listenInput(60000)
if (!ck || /^(q|退出|取消)$/i.test(ck)) return reply("已退出")
@@ -1102,7 +1101,6 @@ function accountMenu(store, bind) {
var remarkMsg = (save.ok && save.uids.length === 1) ? maybePromptRemark(save.uids[0], store) : ""
return reply(save.text + remarkMsg)
}
if (/^(all|清空|全部)$/i.test(op)) return reply(handleDelete("删除 all", store, bind))
var n = parseInt(op, 10)
if (!isNaN(n) && String(n) === op.replace(/^\+/, "")) {
if (n > 0) {
@@ -1115,18 +1113,6 @@ function accountMenu(store, bind) {
return reply(handleDelete("删除 " + uids[idx - 1], store, bind))
}
}
if (/^(查看|查询|列表|账号)$/i.test(op)) return reply(accountListText(store, bind))
if (/^(详情|备注|改名|名称)$/i.test(op)) return accountDetailMenu(store, bind)
if (/^(任务|配置|开关)$/i.test(op)) {
var taskUid = chooseUid(store, bind, "请选择要配置任务的账号:")
if (!taskUid) return reply("已退出")
return taskMenuForUid(taskUid)
}
if (/^(删除)$/i.test(op)) {
var uid = chooseUid(store, bind, "请选择要删除的账号:")
if (!uid) return reply("已退出")
return reply(handleDelete("删除 " + uid, store, bind))
}
return reply("未识别选项,已退出")
}
function queryMenu() {
+22 -25
View File
@@ -165,7 +165,7 @@ test('quick submit can decode QDHeader uid without Buffer or atob', () => {
test('account menu add remark uses saved QDHeader uid instead of ywguid', () => {
const streamQdheader = 'KG51bGwpfChudWxsKXwxMTc5fDI1NTZ8KG51bGwpfDE2LjEwfDB8aU9TL2lQaG9uZS8obnVsbCl8MHwobnVsbCl8KG51bGwpfDQ3NTcwMDk3NXwxNzc5MDA5MTM2MDAwfDB8KG51bGwpfHx8KG51bGwpfChudWxsKXww';
const streamCookie = `QDHeader=${streamQdheader}; ywguid=120098575768; qdh=qdh; sessionyw=s; appId=12`;
const r = runPlugin({ content: '启点账号', userId: 'user-a', listens: ['a', streamCookie, '01'] });
const r = runPlugin({ content: '启点账号', userId: 'user-a', listens: ['0', streamCookie, '01'] });
assert.match(r.replies.join('\n'), /uid: 475700975/);
assert.equal(JSON.parse(r.store.qdreader_remark_json)['475700975'], '01');
assert.equal(JSON.parse(r.store.qdreader_remark_json)['120098575768'], undefined);
@@ -583,8 +583,8 @@ test('account command shows only current user bound accounts without cookies', (
};
const r = runPlugin({ content: '启点账号', store, userId: 'user-a', listens: ['q'] });
assert.match(r.replies[0], /启点账号管理/);
assert.match(r.replies[0], /现有账号/);
assert.match(r.replies[0], /1\. 12\*\*\*45(主号)/);
assert.match(r.replies[0], /账号列表如下/);
assert.match(r.replies[0], /112\*\*\*45\[主号\]/);
assert.doesNotMatch(r.replies[0], /67\*\*\*90/);
assert.doesNotMatch(r.replies[0], /QDHeader=/);
});
@@ -640,12 +640,12 @@ test('account menu prompts remark after add and can edit from detail', () => {
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a' }),
};
const add = runPlugin({ content: '启点账号', store: {}, userId: 'user-a', listens: ['a', cookie, '主号'] });
const add = runPlugin({ content: '启点账号', store: {}, userId: 'user-a', listens: ['0', cookie, '主号'] });
assert.match(add.replies.join('\n'), /是否为该账号添加备注/);
assert.equal(JSON.parse(add.store.qdreader_remark_json)['12345'], '主号');
const clear = runPlugin({ content: '启点账号', store: add.store, userId: 'user-a', listens: ['1', '1', '清空'] });
assert.match(clear.replies.join('\n'), /现有账号/);
assert.match(clear.replies.join('\n'), /账号配置/);
assert.match(clear.replies.join('\n'), /账号列表如下/);
assert.match(clear.replies.join('\n'), /账号操作/);
assert.match(clear.replies.join('\n'), /请回复新备注名/);
assert.equal(JSON.parse(clear.store.qdreader_remark_json)['12345'], undefined);
});
@@ -680,14 +680,13 @@ test('account menu first screen lists accounts and positive number opens config'
};
const r = runPlugin({ content: '启点账号', store, userId: 'user-a', listens: ['2', 'q'] });
assert.match(r.replies[0], /启点账号管理/);
assert.match(r.replies[0], /现有账号/);
assert.match(r.replies[0], /1\. 12\*\*\*45(主号)/);
assert.match(r.replies[0], /2\. 67\*\*\*90(副号)/);
assert.match(r.replies[0], /回复编号进入账号配置/);
assert.match(r.replies[0], /回复负编号删除账号/);
assert.match(r.replies[0], /账号列表如下/);
assert.match(r.replies[0], /112\*\*\*45\[主号\]/);
assert.match(r.replies[0], /267\*\*\*90\[副号\]/);
assert.match(r.replies[0], /负编号删除账号/);
assert.match(r.replies[1], /启点账号详情/);
assert.match(r.replies[1], /67\*\*\*90/);
assert.match(r.replies[1], /账号配置/);
assert.match(r.replies[1], /账号操作/);
assert.match(r.replies[2], /已退出/);
});
@@ -699,8 +698,8 @@ test('account menu negative number deletes matching listed account', () => {
qdreader_task_pref_json: JSON.stringify({ '12345': { adv: true }, '67890': { lottery: true } }),
};
const r = runPlugin({ content: '启点账号', store, userId: 'user-a', listens: ['-2'] });
assert.match(r.replies[0], /1\. 12\*\*\*45(主号)/);
assert.match(r.replies[0], /2\. 67\*\*\*90(副号)/);
assert.match(r.replies[0], /112\*\*\*45\[主号\]/);
assert.match(r.replies[0], /267\*\*\*90\[副号\]/);
assert.match(r.replies[1], /已删除 uid: 67890/);
assert.deepEqual(JSON.parse(r.store.qdreader_cookie_json), { '12345': cookie });
assert.deepEqual(JSON.parse(r.store.qdreader_user_bind_json), { '12345': 'user-a' });
@@ -714,11 +713,9 @@ test('delete account legacy option still uses numbered selection', () => {
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a', '67890': 'user-a' }),
qdreader_remark_json: JSON.stringify({ '12345': '主号', '67890': '副号' }),
};
const r = runPlugin({ content: '启点账号', store, userId: 'user-a', listens: ['删除', '2'] });
assert.match(r.replies[1], /请选择要删除的账号/);
assert.match(r.replies[1], /1\. 12\*\*\*45/);
assert.match(r.replies[1], /2\. 67\*\*\*90/);
assert.match(r.replies[2], /已删除 uid: 67890/);
const r = runPlugin({ content: '启点账号', store, userId: 'user-a', listens: ['-2'] });
assert.match(r.replies[0], /2、67\*\*\*90/);
assert.match(r.replies[1], /已删除 uid: 67890/);
assert.deepEqual(JSON.parse(r.store.qdreader_cookie_json), { '12345': cookie });
});
@@ -728,9 +725,9 @@ test('delete all command clears only current user saved cookies', () => {
qdreader_user_bind_json: JSON.stringify({ '12345': 'user-a', '67890': 'user-b' }),
qdreader_remark_json: JSON.stringify({ '12345': '主号', '67890': '副号' }),
};
const r = runPlugin({ content: '启点账号', store, userId: 'user-a', listens: ['all'] });
assert.match(r.replies[0], /启点账号管理/);
assert.match(r.replies[1], /已删除全部/);
const r = runPlugin({ content: '启点账号', store, userId: 'user-a', listens: ['-1'] });
assert.match(r.replies[0], /1、12\*\*\*45\[主号\]/);
assert.match(r.replies[1], /已删除 uid: 12345/);
assert.deepEqual(JSON.parse(r.store.qdreader_cookie_json), { '67890': cookie.replace(/12345/g, '67890') });
assert.deepEqual(JSON.parse(r.store.qdreader_user_bind_json), { '67890': 'user-b' });
assert.deepEqual(JSON.parse(r.store.qdreader_remark_json), { '67890': '副号' });
@@ -791,8 +788,8 @@ test('manual sign only runs current user accounts while cron runs all accounts',
test('unbound global cookies are not visible or usable by normal users', () => {
const store = { qdreader_cookie_json: JSON.stringify({ '12345': cookie }) };
const account = runPlugin({ content: '启点账号', store: { ...store }, userId: 'user-a', listens: ['1'] });
assert.match(account.replies.join('\n'), /当前用户还没有保存启点读书CK/);
const account = runPlugin({ content: '启点账号', store: { ...store }, userId: 'user-a', listens: ['q'] });
assert.match(account.replies.join('\n'), /暂无账号,请回复 0 添加\/更新账号/);
const manual = runPlugin({ content: '启点签到', store: { ...store }, userId: 'user-a' });
assert.equal(manual.calls.length, 0);
@@ -822,7 +819,7 @@ test('account task menu stores full task switches per account and sign uses sele
};
const menu = runPlugin({ content: '启点账号', store: { ...store }, userId: 'user-a', listens: ['1', '2', '2 on'] });
assert.match(menu.replies[0], /启点账号管理/);
assert.match(menu.replies[1], /账号配置/);
assert.match(menu.replies[1], /账号操作/);
assert.match(menu.replies[2], /激励任务:关闭/);
assert.match(menu.replies[3], /激励任务已开启/);
assert.equal(JSON.parse(menu.store.qdreader_task_pref_json)['12345'].adv, true);