sdu-course-bot/src/index.ts

45 行
1.4 KiB
TypeScript

import {JsonCourseList, poll} from "./poll"
import {appConfig} from "./config"
import {acquireProcess, monitProcess, replaceProcess} from "./actions"
import {resetCookie, sleep} from "./includes"
import {health} from "./health"
async function start() {
console.log('开始获取Cookie')
await resetCookie()
console.log('开始启动轮询进程')
poll()
while (true) {
let pollInitComplete = true
for (let channel of appConfig.channels) {
if (JsonCourseList[channel].length == 0) {
pollInitComplete = false
}
}
if (pollInitComplete) {
break
}
await sleep(50)
}
console.log('轮询进程启动完毕')
for (let channel of appConfig.channels) {
console.log('channel: ' + channel + ': ' + JsonCourseList[channel].length)
}
console.log('开始启动用户进程')
for (let course of appConfig.monit?.list || []) {
monitProcess(course)
}
for (let course of appConfig.acquire?.list || []) {
console.log('添加抢课课程:' + course.kch + ' ' + course.kxh)
acquireProcess(course)
}
if (appConfig.replace) {
console.log('添加换课课程:' + appConfig.replace.exit.kch + ' ' + appConfig.replace.exit.kxh)
replaceProcess(appConfig.replace.list, appConfig.replace.exit)
}
console.log('用户进程启动完毕')
health()
}
start()