Update timetable function to add input validation and improve error handling
All checks were successful
/ print-content (push) Successful in 13s
All checks were successful
/ print-content (push) Successful in 13s
This commit is contained in:
parent
ed3b1575b3
commit
601ebca93e
2 changed files with 29 additions and 6 deletions
|
|
@ -9,7 +9,8 @@ async function main() {
|
||||||
const YYYY = now.getFullYear();
|
const YYYY = now.getFullYear();
|
||||||
const MM = String(now.getMonth() + 1).padStart(2, '0');
|
const MM = String(now.getMonth() + 1).padStart(2, '0');
|
||||||
const DD = String(now.getDate()).padStart(2, '0');
|
const DD = String(now.getDate()).padStart(2, '0');
|
||||||
const YYMMDD = `${YYYY}${MM}${DD}`;
|
// const YYMMDD = `${YYYY}${MM}${DD}`;
|
||||||
|
const YYMMDD = `20260403`;
|
||||||
|
|
||||||
// getDay(): 일(0) ~ 토(6)
|
// getDay(): 일(0) ~ 토(6)
|
||||||
// comcigan.ts 라이브러리 기준에 맞춰 weekday 설정 필요
|
// comcigan.ts 라이브러리 기준에 맞춰 weekday 설정 필요
|
||||||
|
|
|
||||||
|
|
@ -40,22 +40,44 @@ export async function Meal({ MLSV_YMD, ATPT_OFCDC_SC_CODE, SD_SCHUL_CODE, userna
|
||||||
|
|
||||||
|
|
||||||
export async function Timetable({ schoolId, grade, classNum, weekday, WEBHOOK_URL }: { schoolId: number, grade: number, classNum: number, weekday: number, WEBHOOK_URL: string }) {
|
export async function Timetable({ schoolId, grade, classNum, weekday, WEBHOOK_URL }: { schoolId: number, grade: number, classNum: number, weekday: number, WEBHOOK_URL: string }) {
|
||||||
const timetableInfo = await getTimetable({ schoolId, grade, classNum, weekday });
|
// 필수 값 검증: undefined/null 이면 전송 안 함
|
||||||
|
if ([schoolId, grade, classNum, weekday, WEBHOOK_URL].some((v) => v === undefined || v === null)) {
|
||||||
|
console.warn("⚠️ | Undefined input detected. Skip sending webhook.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const weekdayText = ["월", "화", "수", "목", "금"][weekday - 1];
|
||||||
|
if (!weekdayText) {
|
||||||
|
console.warn("⚠️ | Invalid weekday. Skip sending webhook.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timetableInfo = await getTimetable({ schoolId, grade, classNum, weekday });
|
||||||
console.log("🏓 | Timetable Info Retrieved", timetableInfo);
|
console.log("🏓 | Timetable Info Retrieved", timetableInfo);
|
||||||
|
|
||||||
|
// 받아온 시간표 값이 없거나(undefined) 항목에 undefined 값이 있으면 전송 안 함
|
||||||
|
if (
|
||||||
|
!timetableInfo ||
|
||||||
|
timetableInfo.length === 0 ||
|
||||||
|
timetableInfo.some((item) => !item || item.subject === undefined || item.teacher === undefined)
|
||||||
|
) {
|
||||||
|
console.warn("⚠️ | Timetable contains undefined/empty data. Skip sending webhook.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
content: `📅 | ${grade}학년 ${classNum}반 시간표 정보`,
|
content: `📅 | ${grade}학년 ${classNum}반 시간표 정보`,
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
title: `🏫 | 학교 : 선린인터넷고등학교`,
|
title: `🏫 | 학교 : 선린인터넷고등학교`,
|
||||||
fields: (timetableInfo ?? []).map((item) => ({
|
fields: timetableInfo.map((item) => ({
|
||||||
name: `${item.subject}${item.changed ? (" *") : ""}`,
|
name: `${item.subject}${item.changed ? " *" : ""}`,
|
||||||
value: `${item.teacher}${item.subject in room ? ` | ${room[item.subject as keyof typeof room]}` : ""}`,
|
value: `${item.teacher}${item.subject in room ? ` | ${room[item.subject as keyof typeof room]}` : ""}`,
|
||||||
inline: false,
|
inline: false,
|
||||||
})),
|
})),
|
||||||
footer: {
|
footer: {
|
||||||
text: `${["월", "화", "수", "목", "금"][weekday - 1]}요일 시간표 정보`
|
text: `${weekdayText}요일 시간표 정보`,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue