discord_allnight/config/cronJobs.js

31 lines
1.0 KiB
JavaScript

import { CronJob } from 'cron';
import { isDaylightSavingTime } from '../feature/utility.js';
export function initializeCronJobs(client) {
const channel = client.channels.cache.get(process.env.CH_FINANCE);
// 미국 주식 시장 개장 시간
const openTime = isDaylightSavingTime() ? '30 22 * * *' : '30 23 * * *';
const openJob = new CronJob(openTime, async () => {
if (channel) {
const isDST = isDaylightSavingTime();
const dstMessage = isDST
? '현재 서머타임이 적용 중입니다.'
: '현재 서머타임이 적용되지 않았습니다.';
await channel.send(`미국 주식 시장이 열렸습니다.\n${dstMessage}`);
}
}, null, true, 'Asia/Seoul');
// 미국 주식 시장 폐장 시간
const closeTime = isDaylightSavingTime() ? '0 5 * * *' : '0 6 * * *';
const closeJob = new CronJob(closeTime, async () => {
if (channel) {
await channel.send('미국 주식 시장이 닫혔습니다.');
}
}, null, true, 'Asia/Seoul');
// 작업 시작
openJob.start();
closeJob.start();
}