Skip to content

Commit

Permalink
Merge pull request #442 from andywang425:dev
Browse files Browse the repository at this point in the history
7.0.7
close #441 close #439
  • Loading branch information
andywang425 authored Aug 11, 2023
2 parents 1f07199 + af97ced commit 25cf757
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 139 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## [7.0.7] - 2023-8-11

## 新增

- 领取年度大会员权益功能

## [7.0.6] - 2023-8-6

## 新增
Expand Down
254 changes: 124 additions & 130 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bilibili-live-tasks-helper",
"private": true,
"version": "7.0.6",
"version": "7.0.7",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
7 changes: 7 additions & 0 deletions src/components/OtherTasks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const status = moduleStore.moduleStatus.DailyTasks.OtherTasks
<TaskStatus :status="status.coinToSilver" />
</el-space>
</el-row>
<el-row>
<el-space wrap>
<el-switch v-model="config.getYearVipPrivilege.enabled" active-text="领取年度大会员权益" />
<Info id="DailyTasks.OtherTasks.getYearVipPrivilege" />
<TaskStatus :status="status.getYearVipPrivilege" />
</el-space>
</el-row>
<el-divider />
<!-- 说明 -->
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/library/bili-api/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ interface IbapiMethods {
ga?: number
) => Promise<Main.CoinAdd>
videoRelation: (aid: string, bvid?: string) => Promise<Main.VideoRelation>
vip: {
myPrivilege: () => Promise<Main.Vip.MyPrivilege>
receivePrivilege: (type: number, platform?: string) => Promise<Main.Vip.ReceivePrivilege>
}
}
vc: {
myGroups: (build?: numeber, mobi_app?: string) => Promise<Vc.MyGroups>
Expand Down
19 changes: 19 additions & 0 deletions src/library/bili-api/data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,25 @@ declare namespace MainData {
coin: number
}
}

namespace Vip {
namespace MyPrivilege {
interface Data {
list: List[]
is_short_vip: boolean
is_freight_open: boolean
}

interface List {
type: number
state: number
expire_time: number
vip_type: number
next_receive_days: number
period_end_unix: number
}
}
}
}

declare namespace VcData {
Expand Down
34 changes: 34 additions & 0 deletions src/library/bili-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,40 @@ const BAPI: IbapiMethods = {
aid,
bvid
})
},
vip: {
myPrivilege: () => {
const bili_jct = (useBiliStore().cookies as IbiliCookies).bili_jct as string
return request.main.get(
'/x/vip/privilege/my',
{
csrf: bili_jct
},
{
headers: {
Referer: 'https://account.bilibili.com/account/big/myPackage',
Origin: 'https://account.bilibili.com/account/big/myPackage'
}
}
)
},
receivePrivilege: (type, platform = 'web') => {
const bili_jct = (useBiliStore().cookies as IbiliCookies).bili_jct as string
return request.main.post(
'/x/vip/privilege/receive',
{
type,
platform,
csrf: bili_jct
},
{
headers: {
Referer: 'https://account.bilibili.com/account/big/myPackage',
Origin: 'https://account.bilibili.com/account/big/myPackage'
}
}
)
}
}
},
vc: {
Expand Down
15 changes: 15 additions & 0 deletions src/library/bili-api/response.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ declare namespace Main {
ttl: number
data: MainData.VideoRelation.Data
}

namespace Vip {
interface MyPrivilege {
code: number
message: string
ttl: number
data: MainData.Vip.MyPrivilege.Data
}

interface ReceivePrivilege {
code: number
message: string
ttl: number
}
}
}

declare namespace Vc {
Expand Down
19 changes: 19 additions & 0 deletions src/library/help-info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ const help_info: IhelpInfo = {
h('div', '把硬币兑换为银瓜子。'),
h('div', '具体兑换规则请点击直播间页面的“立即充值→银瓜子商店”查看。')
])
},
getYearVipPrivilege: {
title: '领取年度大会员权益',
message: h('p', [
h('div', '自动领取年度大会员权益。'),
h('div', [
h('span', '具体权益请前往'),
h(
'a',
{
href: 'https://account.bilibili.com/account/big/myPackage',
rel: 'noreferrer',
target: '_blank'
},
'卡券包'
),
h('span', '查看。')
])
])
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/library/storage/defaultValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const defaultValues: IdefaultValues = {
enabled: false,
num: 1,
_lastCompleteTime: 0
},
getYearVipPrivilege: {
enabled: false,
_nextReceiveTime: 0
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isTimestampToday, delayToNextMoment, tsm, isNowIn } from '../../../libr
import BAPI from '../../../library/bili-api'
import { Istatus } from '../../../types/moduleStatus'

class CoinToSilver extends BaseModule {
class CoinToSilverTask extends BaseModule {
config = this.moduleStore.moduleConfig.DailyTasks.OtherTasks.coinToSilver

set status(s: Istatus) {
Expand Down Expand Up @@ -50,4 +50,4 @@ class CoinToSilver extends BaseModule {
}
}

export default CoinToSilver
export default CoinToSilverTask
114 changes: 114 additions & 0 deletions src/modules/dailyTasks/otherTasks/getYearVipPrivilegeTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import BaseModule from '../../BaseModule'
import { delayToNextMoment, ts } from '../../../library/luxon'
import BAPI from '../../../library/bili-api'
import { Istatus } from '../../../types/moduleStatus'
import { useBiliStore } from '../../../stores/useBiliStore'
import { MainData } from '../../../library/bili-api/data'
import { DateTime } from 'luxon'

class GetYearVipPrivilegeTask extends BaseModule {
config = this.moduleStore.moduleConfig.DailyTasks.OtherTasks.getYearVipPrivilege

set status(s: Istatus) {
this.moduleStore.moduleStatus.DailyTasks.OtherTasks.getYearVipPrivilege = s
}

/**
* 获取会员权益
* @returns 会员权益列表
*/
private async myPrivilege(): Promise<MainData.Vip.MyPrivilege.List[] | undefined> {
try {
const response = await BAPI.main.vip.myPrivilege()
this.logger.log(`BAPI.main.vip.myPrivilege response`, response)
if (response.code === 0) {
return response.data.list
} else {
this.logger.error(`获取年度大会员权益信息失败`, response.message)
this.status = 'error'
}
} catch (error) {
this.logger.error(`获取年度大会员权益信息出错`, error)
this.status = 'error'
}
}

/**
* 领取权益
* @param type 权益种类
*/
private async receivePrivilege(type: number) {
try {
const response = await BAPI.main.vip.receivePrivilege(type)
this.logger.log(`BAPI.main.vip.receivePrivilege(${type}) response`, response)
if (response.code === 0) {
this.logger.log(`领取年度大会员权益(type = ${type})成功`)
} else {
this.logger.error(`领取年度大会员权益(type = ${type})失败`, response.message)
}
} catch (error) {
this.logger.error(`领取年度大会员权益(type = ${type})出错`, error)
}
}

/**
* 判断当前账号是否是年度大会员
*/
private isYearVip(): boolean {
const biliStore = useBiliStore()
const userInfo = biliStore.userInfo
if (userInfo && userInfo.vip.status === 1 && userInfo.vip.type === 2) {
return true
} else {
this.logger.log('当前账号不是年度大会员,不领取权益')
return false
}
}

public async run() {
this.logger.log('领取年度大会员权益模块开始运行')
if (this.config.enabled) {
if (this.isYearVip()) {
if (ts() >= this.config._nextReceiveTime) {
// 当前时间已经超过了上次记录的下次领取时间,领取权益
this.status = 'running'
const list = await this.myPrivilege()
if (list) {
for (const i of list) {
if (i.vip_type === 2) {
if (i.state === 0) {
await this.receivePrivilege(i.type)
} else {
this.logger.log(`该权益(type = ${i.type})已经领取过了`)
}
} else {
this.logger.warn('发现不属于年度大会员的权益', i)
}
}
this.status = 'done'
this.config._nextReceiveTime = Math.max(...list.map((i) => i.period_end_unix))
// 此时刚领完,距离下次领取还有一个月,不用计划下次运行
}
} else {
// 否则等待下次运行或什么都不做
const diff = this.config._nextReceiveTime - ts()
if (diff < 86400) {
this.logger.log(
'领取年度大会员权益模块下次运行时间:',
DateTime.fromSeconds(this.config._nextReceiveTime).toString()
)
setTimeout(() => this.run(), diff)
} else {
this.logger.log('距离下次领取年度大会员权益的时间超过一天,不计划下次运行')
}
}
}
} else {
const diff = delayToNextMoment(0, 0)
setTimeout(() => this.run(), diff.ms)
this.logger.log('领取年度大会员权益模块下次运行时间:', diff.str)
}
}
}

export default GetYearVipPrivilegeTask
5 changes: 3 additions & 2 deletions src/modules/dailyTasks/otherTasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as DailyTask_OtherTask_GroupSignTask } from './groupSignTask'
export { default as DailyTask_OtherTask_SilverToCoin } from './silverToCoin'
export { default as DailyTask_OtherTask_CoinToSilver } from './coinToSilver'
export { default as DailyTask_OtherTask_SilverToCoinTask } from './silverToCoinTask'
export { default as DailyTask_OtherTask_CoinToSilverTask } from './coinToSilverTask'
export { default as DailyTask_OtherTask_GetYearVipPrivilegeTask } from './getYearVipPrivilegeTask'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isTimestampToday, delayToNextMoment, tsm, isNowIn } from '../../../libr
import BAPI from '../../../library/bili-api'
import { Istatus } from '../../../types/moduleStatus'

class SilverToCoin extends BaseModule {
class SilverToCoinTask extends BaseModule {
config = this.moduleStore.moduleConfig.DailyTasks.OtherTasks.silverToCoin

set status(s: Istatus) {
Expand Down Expand Up @@ -55,4 +55,4 @@ class SilverToCoin extends BaseModule {
}
}

export default SilverToCoin
export default SilverToCoinTask
2 changes: 1 addition & 1 deletion src/modules/default/biliInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class BiliInfo extends DefaultBaseModule {
this.logger.log('BAPI.live.fansMedalPanel(1) response', firstPageResponse)
if (firstPageResponse.code === 0) {
total_page = firstPageResponse.data.page_info.total_page
// 第一页的 list 缺少当前佩戴和最卷获得BAPI.main.share的勋章,需通过 special_list 获取
// 第一页的 list 缺少当前佩戴和最近获得的勋章,需通过 special_list 获取
fansMetalList.push(...firstPageResponse.data.special_list, ...firstPageResponse.data.list)
} else {
this.logger.error('获取粉丝勋章列表第1页失败', firstPageResponse.message)
Expand Down
3 changes: 2 additions & 1 deletion src/stores/useModuleStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const defaultModuleStatus: ImoduleStatus = {
OtherTasks: {
groupSign: '',
silverToCoin: '',
coinToSilver: ''
coinToSilver: '',
getYearVipPrivilege: ''
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types/helpInfo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface IhelpInfo {
groupSign: IhelpInfoItem
silverToCoin: IhelpInfoItem
coinToSilver: IhelpInfoItem
getYearVipPrivilege: IhelpInfoItem
}
}
EnhanceExperience: {
Expand Down
1 change: 1 addition & 0 deletions src/types/moduleStatus.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface ImoduleStatus {
groupSign: Istatus
silverToCoin: Istatus
coinToSilver: Istatus
getYearVipPrivilege: Istatus
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ interface ImoduleConfig {
num: number
_lastCompleteTime: number
}
getYearVipPrivilege: {
enabled: boolean
_nextReceiveTime: number
}
}
}
EnhanceExperience: {
Expand Down

0 comments on commit 25cf757

Please sign in to comment.