From 1ff4af16db3c4db8a5b5556f6da993426845688e Mon Sep 17 00:00:00 2001 From: snowtafir Date: Thu, 21 Nov 2024 12:43:10 +0800 Subject: [PATCH] optimize: get my Bili ck info --- models/bilibili/bilibili.mian.models.ts | 48 ++++++++++++++----------- package.json | 6 ++-- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/models/bilibili/bilibili.mian.models.ts b/models/bilibili/bilibili.mian.models.ts index 8438386..fdd3e6b 100644 --- a/models/bilibili/bilibili.mian.models.ts +++ b/models/bilibili/bilibili.mian.models.ts @@ -148,28 +148,34 @@ export async function pollLoginQRCode(e: EventType, qrcodeKey: string) { /**查看app扫码登陆获取的ck的有效状态*/ export async function checkBiliLogin(e: EventType) { const LoginCookie = await readLoginCookie(); - const res = await fetch('https://api.bilibili.com/x/web-interface/nav', { - method: 'GET', - headers: lodash.merge(BiliApi.BIlIBILI_LOGIN_HEADERS, { 'User-agent': BiliApi.BILIBILI_HEADERS['User-Agent'] }, { Cookie: `${LoginCookie}` }), - redirect: 'follow' - }); - const resData: any = await res.json(); - Bot.logger?.debug(`B站验证登录状态:${JSON.stringify(resData)}`); - - if (resData.code === 0) { - let uname = resData.data?.uname; - let mid = resData.data?.mid; - let money = resData.data?.money; - let level_info = resData.data?.level_info; - let current_level = level_info?.current_level; - let current_exp = level_info?.current_exp; - let next_exp = level_info?.next_exp; - e.reply( - `~B站账号已登陆~\n昵称:${uname}\nuid:${mid}\n硬币:${money}\n经验等级:${current_level}\n当前经验值exp:${current_exp}\n下一等级所需exp:${next_exp}` - ); - } else { - // 处理其他情况 + if (String(LoginCookie).trim().length < 10) { + e.reply('啊咧?B站登录CK呢?哦,没 #扫码B站登录# 或失效了啊,那没事了。'); return; + } else { + const res = await fetch('https://api.bilibili.com/x/web-interface/nav', { + method: 'GET', + headers: lodash.merge(BiliApi.BIlIBILI_LOGIN_HEADERS, { 'User-agent': BiliApi.BILIBILI_HEADERS['User-Agent'] }, { Cookie: `${LoginCookie}` }), + redirect: 'follow' + }); + const resData: any = await res.json(); + Bot?.logger?.debug(`B站验证登录状态:${JSON.stringify(resData)}`); + + if (resData.code === 0) { + let uname = resData.data?.uname; + let mid = resData.data?.mid; + let money = resData.data?.money; + let level_info = resData.data?.level_info; + let current_level = level_info?.current_level; + let current_exp = level_info?.current_exp; + let next_exp = level_info?.next_exp; + e.reply( + `~B站账号已登陆~\n昵称:${uname}\nuid:${mid}\n硬币:${money}\n经验等级:${current_level}\n当前经验值exp:${current_exp}\n下一等级所需exp:${next_exp}` + ); + } else { + // 处理其他情况 + e.reply('意外情况,未能成功获取登录ck的有效状态'); + return; + } } } diff --git a/package.json b/package.json index 2cf0569..4188d00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yuki-plugin", - "version": "2.0.5-15", + "version": "2.0.5-16", "author": "snowtafir", "description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件", "main": "./index", @@ -31,7 +31,7 @@ "md5": "^2.3.0", "moment": "^2.30.1", "node-fetch": "^3.3.2", - "puppeteer": "^23.6.0", + "puppeteer": "^23.8.0", "qrcode": "^1.5.4", "react": "^18.3.1", "react-dom": "^18.3.1", @@ -66,7 +66,7 @@ "node-fetch": "^3.3.2", "pm2": "^5.4.2", "prettier": "^3.3.3", - "puppeteer": "^23.6.0", + "puppeteer": "^23.8.0", "qrcode": "^1.5.4", "react": "^18.3.1", "react-dom": "^18.3.1",