fix: ai返回增加类型检查

This commit is contained in:
shanmite 2026-06-01 14:07:13 +08:00
parent fe0258a84a
commit 2294ad9f3f
2 changed files with 23 additions and 7 deletions

View File

@ -365,7 +365,7 @@ class Monitor extends Searcher {
log.debug('正在筛选的动态信息', lottery_info);
if (des === '') {
log.info('筛选动态', `获取动态内容为空(https://t.bilibili.com/${dyid})风控`);
log.info('筛选动态', `获取动态内容为空(https://t.bilibili.com/${dyid})风控或是视频动态`);
return false;
}
@ -472,11 +472,27 @@ class Monitor extends Searcher {
);
try {
let msg_json = JSON.parse(msg);
has_key_words = msg_json.has_key_words;
needAt = msg_json.needAt;
needTopic = msg_json.needTopic;
drawtime = msg_json.drawtime;
isLottery = has_key_words;
if (typeof msg_json.has_key_words == 'boolean') {
has_key_words = msg_json.has_key_words;
isLottery = has_key_words;
} else {
log.warn('ai判断抽奖', 'no has_key_words');
}
if (typeof msg_json.needAt == 'boolean') {
needAt = msg_json.needAt;
} else {
log.warn('ai判断抽奖', 'no needAt');
}
if (typeof msg_json.needTopic == 'string') {
needTopic = msg_json.needTopic;
} else {
log.warn('ai判断抽奖', 'no needTopic');
}
if (typeof msg_json.drawtime == 'number') {
drawtime = msg_json.drawtime;
} else {
log.warn('ai判断抽奖', 'no drawtime');
}
log.info('ai判断抽奖', msg_json.more);
} catch (_) {
log.error('ai判断抽奖', `未返回JSON格式${msg}`);

View File

@ -550,7 +550,7 @@ const utils = {
},
success: res => {
const data = utils.strToJson(res.body);
resolve(data?.choices?.[0]?.message?.content || null);
resolve(utils.log.debug_return(content, data?.choices?.[0]?.message?.content) || null);
},
failure: () => {
resolve(null);