fix: detect qdreader user id in autman js
This commit is contained in:
@@ -5,22 +5,23 @@ import vm from 'node:vm';
|
||||
const pluginPath = new URL('../plugins/qdreader/qdreader_sign_autman.js', import.meta.url).pathname;
|
||||
const code = fs.readFileSync(pluginPath, 'utf8');
|
||||
|
||||
function runPlugin({ content = '', store = {}, bucketStore = {}, requests = [], userId = 'user-a', listens = [] } = {}) {
|
||||
function runPlugin({ content = '', store = {}, bucketStore = {}, requests = [], userId = 'user-a', listens = [], senderOverrides = {}, globals = {} } = {}) {
|
||||
const replies = [];
|
||||
const calls = [];
|
||||
let requestIndex = 0;
|
||||
let listenIndex = 0;
|
||||
const ctx = {
|
||||
console,
|
||||
Buffer,
|
||||
sender: {
|
||||
const baseSender = {
|
||||
reply: (msg) => replies.push(String(msg)),
|
||||
getMessage: () => content,
|
||||
getContent: () => content,
|
||||
isAdmin: () => true,
|
||||
getUserID: () => userId,
|
||||
listen: () => (listenIndex < listens.length ? listens[listenIndex++] : 'q'),
|
||||
},
|
||||
};
|
||||
const ctx = {
|
||||
console,
|
||||
Buffer,
|
||||
sender: { ...baseSender, ...senderOverrides },
|
||||
GetContent: () => content,
|
||||
getContent: () => content,
|
||||
get: (key) => store[key] || '',
|
||||
@@ -36,6 +37,7 @@ function runPlugin({ content = '', store = {}, bucketStore = {}, requests = [],
|
||||
if (String(req.url).includes('/sign')) return { body: { code: 0, data: { headers: { 'QD-Sign': 'sig' } } } };
|
||||
return { statusCode: 200, body: { code: 0, msg: '签到成功' } };
|
||||
},
|
||||
...globals,
|
||||
};
|
||||
vm.createContext(ctx);
|
||||
vm.runInContext(code, ctx, { filename: pluginPath });
|
||||
@@ -98,6 +100,17 @@ test('quick submit prompts remark after saving cookie', () => {
|
||||
assert.equal(JSON.parse(r.store.qdreader_remark_json)['12345'], '主号');
|
||||
});
|
||||
|
||||
test('quick submit can bind user from alternate Autman sender fields', () => {
|
||||
const r = runPlugin({
|
||||
content: '启点ck ' + cookie,
|
||||
userId: '',
|
||||
senderOverrides: { getUserID: undefined, getSenderID: () => 'sender-42' },
|
||||
listens: ['n'],
|
||||
});
|
||||
assert.match(r.replies.join('\n'), /CK新增成功/);
|
||||
assert.equal(JSON.parse(r.store.qdreader_user_bind_json)['12345'], 'sender-42');
|
||||
});
|
||||
|
||||
test('manual sign and cron sign both call sign gateway then qidian checkin', () => {
|
||||
const store = {
|
||||
qdreader_cookie_json: JSON.stringify({ '12345': cookie }),
|
||||
|
||||
Reference in New Issue
Block a user