-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·85 lines (82 loc) · 2.49 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
import Plugin, { tools, AppClient } from '../../plugin'
class Coin extends Plugin {
constructor() {
super()
}
public name = '兑换硬币'
public description = '将银瓜子兑换成硬币'
public version = '0.0.2'
public author = 'lzghzr'
/**
* 任务表
*
* @private
* @type {Map<string, boolean>}
* @memberof Coin
*/
private _silver2coinList: Map<string, boolean> = new Map()
public async load({ defaultOptions, whiteList }: { defaultOptions: options, whiteList: Set<string> }) {
// 兑换硬币
defaultOptions.newUserData['silver2coin'] = false
defaultOptions.info['silver2coin'] = {
description: '兑换硬币',
tip: '将银瓜子兑换成硬币',
type: 'boolean'
}
whiteList.add('silver2coin')
this.loaded = true
}
public async start({ users }: { users: Map<string, User> }) {
this._silver2coin(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._silver2coinList.clear()
// 每天04:30, 12:30, 20:30做任务
if (cstMin === 30 && cstHour % 8 === 4) this._silver2coin(users)
}
/**
* 兑换硬币
*
* @private
* @memberof Coin
*/
private _silver2coin(users: Map<string, User>) {
users.forEach(async (user, uid) => {
if (this._silver2coinList.get(uid) || !user.userData['silver2coin']) return
const exchange: XHRoptions = {
method: 'POST',
url: `https://api.live.bilibili.com/AppExchange/silver2coin?${AppClient.signQueryBase(user.tokenQuery)}`,
responseType:'json',
headers: user.headers
}
const silver2coin = await tools.XHR<silver2coin>(exchange, 'Android')
if (silver2coin !== undefined && silver2coin.response.statusCode === 200) {
if (silver2coin.body.code === 0 || silver2coin.body.code === 403) {
this._silver2coinList.set(uid, true)
tools.Log(user.nickname, '兑换硬币', '已成功兑换硬币')
}
else tools.Log(user.nickname, '兑换硬币', silver2coin.body)
}
else tools.Log(user.nickname, '兑换硬币', '网络错误')
})
}
}
/**
* 银瓜子兑换硬币返回
*
* @interface silver2coin
*/
interface silver2coin {
code: number
msg: string
message: string
data: silver2coinData
}
interface silver2coinData {
silver: string
gold: string
tid: string
coin: number
}
export default new Coin()