enlistment command fix

This commit is contained in:
yeongaori
2025-08-12 17:46:52 +09:00
parent be8f9f879f
commit b5b7aaa6fb

View File

@@ -1,13 +1,10 @@
const { SlashCommandBuilder, EmbedBuilder, InteractionContextType, ApplicationIntegrationType } = require('discord.js');
const logger = require('../../../modules/colorfulLogger');
const {
ipdaeDatas,
notificationHistory,
saveData
updateEnlistmentData
} = require('../../data/dataManager');
const { serviceTypes, adminUserIds } = require('../../../config/constants');
const { dateFormatter } = require('../../utils/dateUtils');
const { binarySearch, binaryInsert } = require('../../utils/helpers');
const { getNameById } = require('../../utils/discordUtils');
const { handleCommandError } = require('../../../utils/errorHandler');
@@ -37,7 +34,11 @@ async function setEnlistmentDate(client, callerUserId, dateArg, typeArg, command
if (!(/^\d{4}-\d{2}-\d{2}$/.test(dateArg) && serviceTypes.includes(typeArg))) {
return new EmbedBuilder()
.setTitle('명령어 형식 오류')
.setDescription(`입력된 날짜: \`${dateArg}\`, 복무형태: \`${typeArg}\``)
.setDescription(`입력된 날짜:
${dateArg}
, 복무형태:
${typeArg}
`)
.addFields({ name: '올바른 형식', value: `${commandString} YYYY-MM-DD ${serviceTypes.join('/')}` })
.setColor('#F44336');
}
@@ -47,44 +48,21 @@ async function setEnlistmentDate(client, callerUserId, dateArg, typeArg, command
if (isNaN(enlistDate.getTime()) || enlistDate.getFullYear() !== year || enlistDate.getMonth() + 1 !== month || enlistDate.getDate() !== day) {
return new EmbedBuilder()
.setTitle('유효하지 않은 날짜입니다.')
.setDescription(`입력한 날짜 \`${dateArg}\`를 확인해주세요.`)
.setDescription(`입력한 날짜
${dateArg}
를 확인해주세요.`)
.setColor('#F44336');
}
let notificationHistoryModified = false;
const index = binarySearch(ipdaeDatas, targetUserId);
if (index !== -1) {
const oldDate = ipdaeDatas[index].date;
const oldType = ipdaeDatas[index].type;
if (targetUserId === '1107292307025301544' && typeArg !== '사회복무요원') {
typeArg = '사회복무요원';
logger.info(`User ID 1107292307025301544 type overridden to 사회복무요원.`);
}
ipdaeDatas[index].date = dateArg;
ipdaeDatas[index].type = typeArg;
if (oldDate !== dateArg || oldType !== typeArg) {
logger.info(`Enlistment data changed for ${targetUserId}. Resetting their notification history.`);
notificationHistory[targetUserId] = [];
notificationHistoryModified = true;
}
} else {
binaryInsert(ipdaeDatas, { id: targetUserId, date: dateArg, type: typeArg });
notificationHistory[targetUserId] = [];
notificationHistoryModified = true;
if (targetUserId === '1107292307025301544' && typeArg !== '사회복무요원') {
typeArg = '사회복무요원';
logger.info(`User ID 1107292307025301544 type overridden to 사회복무요원.`);
}
await saveData('ipdae');
if (notificationHistoryModified) {
await saveData('history');
}
const finalData = await updateEnlistmentData(targetUserId, dateArg, typeArg);
const finalData = ipdaeDatas[binarySearch(ipdaeDatas, targetUserId)];
return new EmbedBuilder()
.setTitle(index !== -1 ? startDateEmbedTitle.replace('저장', '수정') : startDateEmbedTitle)
.setTitle(startDateEmbedTitle)
.addFields(
{ name: '입대일', value: dateFormatter(finalData.date) },
{ name: '복무 형태', value: finalData.type }