Skip to content

Commit

Permalink
feat: 哔哩哔哩解析被删除的动态或视频时增加回复提示
Browse files Browse the repository at this point in the history
resolve #336
  • Loading branch information
Tsuk1ko committed Jul 11, 2022
1 parent b9fbc0a commit 65b6fd4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## 2022

### 07-11 v2.37.2

- 哔哩哔哩解析被删除的动态或视频时增加回复提示 [#336](../../issues/336)
- 更改部分功能使用到的 jsdelivr 域名防止国内部分地区无法访问 cdn.jsdelivr.net => fastly.jsdelivr.net

### 07-10 v2.37.1

- 修复哔哩哔哩动态解析问题 [#339](../../issues/339)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cq-picsearcher-bot",
"version": "2.37.1",
"version": "2.37.2",
"description": "二次元搜图机器人",
"main": "index.js",
"private": true,
Expand Down
9 changes: 9 additions & 0 deletions src/plugin/bilibili/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ const parseDynamicCard = ({
};

const dynamicCard2msg = async (card, forPush = false) => {
if (!card) {
if (forPush) return null;
return {
type: -1,
text: '该动态已被删除',
reply: true,
};
}

const parsedCard = parseDynamicCard(card);
const {
dyid,
Expand Down
10 changes: 5 additions & 5 deletions src/plugin/bilibili/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ async function bilibiliHandler(context) {
if (gid && getCacheKeys(gid, Object.values(param)).some(key => cache.has(key))) return;

if (setting.getVideoInfo && (aid || bvid)) {
const { reply, ids } = await getVideoInfo({ aid, bvid });
if (reply) {
global.replyMsg(context, reply);
markSended(gid, ...ids);
const { text, ids, reply } = await getVideoInfo({ aid, bvid });
if (text) {
global.replyMsg(context, text, false, !!reply);
if (ids && ids.length) markSended(gid, ...ids);
}
return true;
}

if (setting.getDynamicInfo && dyid) {
const reply = await getDynamicInfo(dyid);
if (reply) {
global.replyMsg(context, reply.text);
global.replyMsg(context, reply.text, false, !!reply.reply);
markSended(gid, dyid);
}
return true;
Expand Down
52 changes: 28 additions & 24 deletions src/plugin/bilibili/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,41 @@ import logError from '../../logError';
import humanNum from '../../utils/humanNum';
import { retryGet } from '../../utils/retry';

export const getVideoInfo = param => {
return retryGet(`https://api.bilibili.com/x/web-interface/view?${stringify(param)}`, { timeout: 10000 })
.then(
({
data: {
data: {
bvid,
aid,
pic,
title,
owner: { name },
stat: { view, danmaku },
},
},
}) => ({
ids: [aid, bvid],
reply: `${CQ.img(pic)}
export const getVideoInfo = async param => {
try {
const { data } = await retryGet(`https://api.bilibili.com/x/web-interface/view?${stringify(param)}`, {
timeout: 10000,
});
if (data.code === -404) return { text: '该视频已被删除', reply: true };
if (data.code !== 0) return { text: data.message, reply: true };

const {
data: {
bvid,
aid,
pic,
title,
owner: { name },
stat: { view, danmaku },
},
} = data;
return {
ids: [aid, bvid],
text: `${CQ.img(pic)}
av${aid}
${CQ.escape(title)}
UP:${CQ.escape(name)}
${humanNum(view)}播放 ${humanNum(danmaku)}弹幕
https://www.bilibili.com/video/${bvid}`,
})
)
.catch(e => {
logError(`${global.getTime()} [error] bilibili get video info ${param}`);
logError(e);
return {};
});
};
} catch (e) {
logError(`${global.getTime()} [error] bilibili get video info ${param}`);
logError(e);
return {};
}
};

/** @deprecated */
export const getSearchVideoInfo = keyword =>
retryGet(`https://api.bilibili.com/x/web-interface/search/all/v2?${stringify({ keyword })}`, { timeout: 10000 })
.then(
Expand Down

0 comments on commit 65b6fd4

Please sign in to comment.