noticeUwuzu/scripts/timeNotice.ts

44 lines
989 B
TypeScript

import { format } from "date-fns";
import type * as types from "types/types";
import config from "../config.js";
// 停止時間
// 時刻取得
const start = config.time.stopTimes.start;
const stop = config.time.stopTimes.stop;
// 現在の時間を取得
const nowHour = new Date().getHours();
// 停止時刻内かどうかの判定
let inRange: boolean = false;
if (start < stop) {
inRange = nowHour >= start && nowHour < stop;
} else {
inRange = nowHour >= start || nowHour < stop;
}
export default async function timeNotice() {
if (inRange === false) {
// 投稿
const resUeuse = await fetch(
`https://${config.uwuzuServer}/api/ueuse/create`,
{
method: "POST",
body: JSON.stringify({
token: config.apiToken,
text: `${format(new Date(), "HH:mm")}になりました`,
}),
},
);
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
console.log(JSON.stringify(ueuseData));
}
}