-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 예약 메세지 기능 생성 #19
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "16-feat-\uC608\uC57D-\uBA54\uC138\uC9C0-\uAE30\uB2A5-\uC0DD\uC131"
Conversation
|
||
//1. 시간 형식 검증 | ||
try { | ||
time = LocalDateTime.parse(timeString, formatter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
검증하는 로직을 함수로 뺄 수 있을거 같습니다!
time = LocalDateTime.parse(timeString, formatter); | ||
} catch (DateTimeParseException e) { | ||
log.error("❌ 잘못된 시간 형식: {}", timeString); | ||
event.reply("❌ 잘못된 시간 형식입니다! yyyy-MM-dd HH:mm 형식으로 입력해주세요.").setEphemeral(true).queue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수로 만드실 때 event 따로 처리 안하시고
throw GreedyBotException("❌ 잘못된 시간 형식입니다! yyyy-MM-dd HH:mm 형식으로 입력해주세요.")
해주시면 상위 코드에서 catch해서 event관련 코드가 실행될거 같습니다!
String timeString = event.getOption("time").getAsString(); | ||
String channelId = event.getChannelId(); | ||
|
||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm", Locale.ENGLISH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"yyyy-MM-dd HH:mm"
이부분을 상수화 시켜서 사용할 수 있을거 같습니다!
} | ||
|
||
//2. 과거 시간 입력 여부 확인 | ||
LocalDateTime now = LocalDateTime.now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분 또한 함수로 따로 뺄 수 있을거 같습니다!
public class ScheduledMessageService { | ||
|
||
private final ScheduledMessageRepository repository; | ||
private final ScheduledMessageScheduler scheduler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scheduler 해당 변수 이름을 혹시 scheduledMessageScheduler로, repository를 scheduledMessageRepository바꿔주실 수 있으실까요?
함수만 보게 된다면 어떤 class인지 구체적으로 와닿지 않아서 제안 드려봅니다!
Long delay = scheduledMessage.getScheduledTime().atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli() - System.currentTimeMillis(); | ||
|
||
Timer timer = new Timer(); | ||
timer.schedule(new TimerTask() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분을 TimerTask를 상속 받는 객체를 하나 만들어서 분리 시킬 수 있다는 생각이 듭니다!
public class ScheduledMessageTask extends TimerTask {
}
요런식으로요!
log.info("예약된 메시지: {}", message); | ||
log.info("예약된 시간: {}", time); | ||
|
||
ScheduledMessage scheduledMessage = new ScheduledMessage(message, time, event.getUser().getId(), channelId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 변수 앞에 final 키워드를 붙일 수 있을거 같습니다!
} | ||
|
||
//2. 과거 시간 입력 여부 확인 | ||
LocalDateTime now = LocalDateTime.now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기다 final 키워드 붙일 수 있을거 같습니다!
public void onAction(@NotNull SlashCommandInteractionEvent event) { | ||
String message = event.getOption("message").getAsString(); | ||
String timeString = event.getOption("time").getAsString(); | ||
String channelId = event.getChannelId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전체적으로 변하지 않는 값들 앞에 final 키워드들을 붙일 수 있을거 같습니다!
final 키워드를 봤을때 제가 생각하는 장점: 제작자의 의도를 더 잘 파악할 수 있다고 생각합니다. (ex: 이 변수는 변하지 않는 값이구나 등등)
수고하셨습니다 👍 |
작업 내용
참고 사항
관련 이슈
PR 체크리스트