Skip to content

Commit

Permalink
optimize: get my Bili ck info
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Nov 21, 2024
1 parent 708c257 commit 1ff4af1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
48 changes: 27 additions & 21 deletions models/bilibili/bilibili.mian.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1ff4af1

Please sign in to comment.