Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

haeyoon1
Copy link
Collaborator

작업 내용

  • 예약 메시지 기능을 구현했습니다.
  • Discord Slash Command 기능을 사용한 채널에 예약메시지가 예약된 시간에 발송되도록 구현하였습니다.

참고 사항

  • 현재 테스트 코드는 포함되지 않으며, 추후 별도 PR에서 추가할 예정입니다.
  • 해당 기능을 사용할 수 있는 멤버들을 특정하지 않았습니다.(메인테이너와 운영진에게만 권한 부여가 필요하다면 수정하겠습니다)

관련 이슈

PR 체크리스트

  • 빌드는 성공했나요?
  • 코드 포맷팅을 진행했나요?
  • 기능이 정상 동작하나요?
  • 테스트 코드가 포함되어 있나요?

@haeyoon1 haeyoon1 linked an issue Feb 27, 2025 that may be closed by this pull request
3 tasks

//1. 시간 형식 검증
try {
time = LocalDateTime.parse(timeString, formatter);
Copy link
Collaborator

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();
Copy link
Collaborator

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);
Copy link
Collaborator

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();
Copy link
Collaborator

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;
Copy link
Collaborator

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() {
Copy link
Collaborator

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);
Copy link
Collaborator

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();
Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 변하지 않는 값들 앞에 final 키워드들을 붙일 수 있을거 같습니다!

final 키워드를 봤을때 제가 생각하는 장점: 제작자의 의도를 더 잘 파악할 수 있다고 생각합니다. (ex: 이 변수는 변하지 않는 값이구나 등등)

@davidolleh
Copy link
Collaborator

수고하셨습니다 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: 예약 메세지 기능 생성
3 participants