diff --git a/apps/tools.js b/apps/tools.js index 7b87e55..5fc4f24 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -55,6 +55,7 @@ import TokenBucket from "../utils/token-bucket.js"; import PQueue from 'p-queue'; import { getWbi } from "../utils/biliWbi.js"; import { + BILI_STREAM_INFO, BILI_SUMMARY, DY_COMMENT, DY_INFO, @@ -473,6 +474,21 @@ export class tools extends plugin { if (matched) { url = url.replace(matched[0].replace("\/", ""), av2BV(Number(matched[2]))); } + // 直播间分享 + logger.info(url) + if (url.includes("live")) { + // 提取直播间id + const idPattern = /\/(\d+)$/; + const parsedUrl = new URL(url); + const streamId = parsedUrl.pathname.match(idPattern)?.[1]; + // logger.info(streamId) + // 提取相关信息 + const liveData = await this.getBiliStream(streamId); + // logger.info(liveData); + const { title, user_cover, description, tags } = liveData.data.data; + e.reply([segment.image(user_cover), `直播间:${ title }\n\n简述:${ description }\n标签:${ tags }`]); + return true; + } // 处理专栏 if (e.msg !== undefined && e.msg.includes("read\/cv")) { this.linkShareSummary(e); @@ -700,6 +716,19 @@ export class tools extends plugin { }) } + /** + * 获取直播间信息 + * @param liveId + * @returns {Promise<*>} + */ + async getBiliStream(liveId) { + return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, { + headers: { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36', + } + }); + } + // 例子:https://twitter.com/chonkyanimalx/status/1595834168000204800 async twitter(e) { // 配置参数及解析 diff --git a/constants/tools.js b/constants/tools.js index f6ac169..a2dabf2 100644 --- a/constants/tools.js +++ b/constants/tools.js @@ -54,6 +54,13 @@ export const BILI_SCAN_CODE_GENERATE = "https://passport.bilibili.com/x/passport */ export const BILI_SCAN_CODE_DETECT = "https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key={}"; +/** + * 直播间信息获取 + * https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/live/info.md + * @type {string} + */ +export const BILI_STREAM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info" + /** * 米游社网页端获取文章 * https://github.com/UIGF-org/mihoyo-api-collect/blob/main/hoyolab/article/article.md#%E8%8E%B7%E5%8F%96%E5%AE%8C%E6%95%B4%E6%96%87%E7%AB%A0%E4%BF%A1%E6%81%AF