-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from andywang425:dev
- Loading branch information
Showing
19 changed files
with
363 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
## 新增 | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/modules/dailyTasks/otherTasks/getYearVipPrivilegeTask.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters