Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
增加加载帐号信息显示
Browse files Browse the repository at this point in the history
  • Loading branch information
catlair committed May 29, 2021
1 parent daa6cc7 commit d128631
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/dailyTask/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import videoTask from './videoTask';
import * as _ from 'lodash';
import { Page } from 'puppeteer-core';
import { DailyTask } from '../config/globalVar';
export * from './user';

async function coinByUID(page: Page) {
if (!DailyTask.CUSTOMIZE_UP?.length) {
Expand Down
32 changes: 32 additions & 0 deletions src/dailyTask/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { DailyTask } from '../config/globalVar';
import { UserInfoNavDto } from '../dto/UserInfo.dto';
import { Logger } from 'log4js';
import { Page } from 'puppeteer-core';

export async function getUser(page: Page, logger: Logger) {
let userNav: UserInfoNavDto['data'];
async function getUserNav() {
const res = await page.waitForResponse(
'https://api.bilibili.com/x/web-interface/nav',
);
userNav = (await res.json()).data;
if (!userNav.isLogin) {
return;
}
DailyTask.money = userNav?.money;
logger.debug(`
当前等级:${userNav.level_info.current_level}
距离升级还需要经验:${
userNav.level_info.next_exp - userNav.level_info.current_exp
}
剩余硬币数:${userNav.money}
`);
return res;
}

try {
return await Promise.all([getUserNav(), page.goto('https://bilibili.com')]);
} catch (error) {
logger.trace('获取用户信息失败', error.message);
}
}
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
coinByFollow,
coinByRecommend,
coinByUID,
getUser,
liveTask,
watchAndShare,
} from './dailyTask';
Expand All @@ -25,9 +26,12 @@ logger.info(`当前版本【 ${getVersion()} 】`);
}

const browser = await createBrowser();
let page = await browser.newPage();
const page = await browser.newPage();
try {
await page.setCookie(...getCookies(OSConfig.COOKIE, '.bilibili.com'));
// 基本信息
await getUser(page, logger);

//给指定uid的up投币
if (FunConfig.coinByUID) {
await coinByUID(page);
Expand Down

0 comments on commit d128631

Please sign in to comment.