-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
executable file
·147 lines (145 loc) · 3.85 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import Plugin, { tools, AppClient } from '../../plugin'
class Sign extends Plugin {
constructor() {
super()
}
public name = '自动签到'
public description = '每天自动签到'
public version = '0.0.2'
public author = 'lzghzr'
/**
* 任务表
*
* @private
* @type {Map<string, boolean>}
* @memberof Sign
*/
private _signList: Map<string, boolean> = new Map()
public async load({ defaultOptions, whiteList }: { defaultOptions: options, whiteList: Set<string> }) {
// 自动签到
defaultOptions.newUserData['doSign'] = false
defaultOptions.info['doSign'] = {
description: '自动签到',
tip: '每天自动签到',
type: 'boolean'
}
whiteList.add('doSign')
this.loaded = true
}
public async start({ users }: { users: Map<string, User> }) {
this._getSignInfo(users)
}
public async loop({ cstMin, cstHour, cstString, users }: { cstMin: number, cstHour: number, cstString: string, users: Map<string, User> }) {
// 每天00:10刷新任务
if (cstString === '00:10') this._signList.clear()
// 每天04:30, 12:30, 20:30做任务
if (cstMin === 30 && cstHour % 8 === 4) this._getSignInfo(users)
}
/**
* 获取签到信息
*
* @private
* @param {Map<string, User>} users
* @memberof Sign
*/
private _getSignInfo(users: Map<string, User>) {
users.forEach(async (user, uid) => {
if (this._signList.get(uid) || !user.userData['doSign']) return
const sign: XHRoptions = {
url: `https://api.live.bilibili.com/rc/v2/Sign/getSignInfo?${AppClient.signQueryBase(user.tokenQuery)}`,
responseType: 'json',
headers: user.headers
}
const getSignInfo = await tools.XHR<getSignInfo>(sign, 'Android')
if (getSignInfo !== undefined && getSignInfo.response.statusCode === 200) {
if (getSignInfo.body.code === 0) {
if (getSignInfo.body.data.is_signed) tools.Log(user.nickname, '自动签到', '今日已签到过')
else await this._doSign(user, uid)
}
else tools.Log(user.nickname, '自动签到', getSignInfo.body)
}
else tools.Log(user.nickname, '自动签到', '网络错误')
})
}
/**
* 自动签到
*
* @private
* @param {User} user
* @param {string} uid
* @memberof Sign
*/
private async _doSign(user: User, uid: string) {
const sign: XHRoptions = {
url: `https://api.live.bilibili.com/rc/v1/Sign/doSign?${AppClient.signQueryBase(user.tokenQuery)}`,
responseType: 'json',
headers: user.headers
}
const doSign = await tools.XHR<doSign>(sign, 'Android')
if (doSign !== undefined && doSign.response.statusCode === 200) {
if (doSign.body.code === 0) {
this._signList.set(uid, true)
tools.Log(user.nickname, '自动签到', '已签到')
}
else tools.Log(user.nickname, '自动签到', doSign.body)
}
else tools.Log(user.nickname, '自动签到', '网络错误')
}
}
/**
* 签到信息
*
* @interface getSignInfo
*/
interface getSignInfo {
code: number
message: string
ttl: number
data: getSignInfoData
}
interface getSignInfoData {
is_signed: boolean
days: number
sign_days: number
h5_url: string
days_award: getSignInfoDataDaysAward[]
awards: getSignInfoDataAward[]
}
interface getSignInfoDataAward {
count: number
text: string
award: string
img: getSignInfoDataImg
}
interface getSignInfoDataDaysAward {
id: number
award: string
count: number
day: number
text: string
img: getSignInfoDataImg
}
interface getSignInfoDataImg {
src: string
width: number
height: number
}
/**
* 签到返回
*
* @interface doSign
*/
interface doSign {
code: number
msg: string
ttl: number
data: signInfoData
}
interface signInfoData {
text: string
specialText: string
allDays: number
hadSignDays: number
isBonusDay: number
}
export default new Sign()