48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { format } from "date-fns";
|
|
|
|
import type * as types from "types/types";
|
|
import config from "../config.js";
|
|
|
|
export default async function timeNotice() {
|
|
// 停止時間
|
|
// 時刻取得
|
|
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;
|
|
}
|
|
|
|
if (inRange) {
|
|
console.log("----------------");
|
|
console.log("時報休止期間のため投稿されませんでした");
|
|
return;
|
|
} else {
|
|
// 投稿
|
|
const resUeuse = await fetch(
|
|
`https://${config.uwuzu.host}/api/ueuse/create`,
|
|
{
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
token: config.uwuzu.apiToken,
|
|
text: `${format(new Date(), "HH:mm")}になりました`,
|
|
}),
|
|
cache: "no-store",
|
|
},
|
|
);
|
|
|
|
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
|
|
|
|
console.log("----------------");
|
|
console.log(`時報投稿:${JSON.stringify(ueuseData)}`);
|
|
}
|
|
}
|