-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
58 lines (54 loc) · 2.12 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
import { } from '@hydrooj/vjudge';
import {
Context, db, MessageModel, moment,
} from 'hydrooj';
import { importProblem } from './import';
import LuoguProvider from './provider';
declare module 'hydrooj' {
interface Model {
luogu: {
importProblem: typeof importProblem;
addAccount: typeof addAccount;
};
}
}
async function addAccount(token: string) {
const newProvider = new LuoguProvider({
_id: 'test', type: 'luogu', handle: token.split(':')[0], password: token.split(':')[1],
}, async () => {});
try {
const info = await newProvider.checkStatus(true);
console.log(info);
} catch (e) {
throw new Error('Invalid account');
}
await db.collection('vjudge').insertOne({
_id: String.random(8),
handle: token.split(':')[0],
password: token.split(':')[1],
type: 'luogu',
});
return 'success';
}
global.Hydro.model.luogu = {
importProblem,
addAccount,
};
export async function apply(ctx: Context) {
ctx.inject(['vjudge'], (c) => {
c.vjudge.addProvider('luogu', LuoguProvider);
c.on('task/daily', async () => {
const status = await c.vjudge.checkStatus();
const id = Object.keys(status).find((k) => k.startsWith('luogu/'));
const quota = status[id].status;
const info = `${quota.orgName} 剩余点数: ${quota.availablePoints}
(点数有效期: ${moment(quota.createTime).format('YYYY/MM/DD')}-${moment(quota.expireTime).format('YYYY/MM/DD')})`;
if (moment(quota.expireTime).diff(moment(), 'days') <= 3) {
MessageModel.sendNotification(['Hydro & 洛谷开放平台提醒:', info, '点数有效期已不足3天,请及时联系Hydro开发组或洛谷官方进行充值或续费。'].join('\n'));
}
if (quota.availablePoints > 0 && quota.availablePoints < 1000) {
MessageModel.sendNotification(['Hydro & 洛谷开放平台提醒:', info, '点数已不足1000,请及时联系Hydro开发组或洛谷官方进行充值或续费。'].join('\n'));
}
});
});
}