From b5793d2f10de2d3264a0730ed4ee9f0367284964 Mon Sep 17 00:00:00 2001 From: megoRU Date: Mon, 27 May 2024 13:28:31 +0300 Subject: [PATCH] New Update 1. Fix --- src/main/java/main/config/BotStart.java | 2 +- src/main/java/main/core/events/ChangeCommand.java | 11 ++++------- src/main/java/main/core/events/SchedulingCommand.java | 8 +++++++- src/main/java/main/core/events/StartCommand.java | 2 +- src/main/java/main/giveaway/GiveawayUtils.java | 6 +++++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/main/config/BotStart.java b/src/main/java/main/config/BotStart.java index 71d43d6..c1727f4 100644 --- a/src/main/java/main/config/BotStart.java +++ b/src/main/java/main/config/BotStart.java @@ -149,7 +149,7 @@ public synchronized void startBot() { System.out.println("IsDevMode: " + Config.isIsDev()); //Обновить команды - updateSlashCommands(); +// updateSlashCommands(); System.out.println("20:22"); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); diff --git a/src/main/java/main/core/events/ChangeCommand.java b/src/main/java/main/core/events/ChangeCommand.java index bdd4784..fbeaa28 100644 --- a/src/main/java/main/core/events/ChangeCommand.java +++ b/src/main/java/main/core/events/ChangeCommand.java @@ -38,13 +38,7 @@ public void change(@NotNull SlashCommandInteractionEvent event, UpdateController } String time = event.getOption("duration", OptionMapping::getAsString); if (time != null) { - if (GiveawayUtils.isTimeCorrect(time)) { - if (GiveawayUtils.isTimeBefore(time)) { - String changeDuration = jsonParsers.getLocale("wrong_date", guildId); - event.reply(changeDuration).setEphemeral(true).queue(); - return; - } - + if (GiveawayUtils.isTimeCorrect(time) || GiveawayUtils.isISOTimeCorrect(time)) { GiveawayData giveawayData = giveaway.getGiveawayData(); long channelId = giveaway.getTextChannelId(); long messageId = giveawayData.getMessageId(); @@ -59,6 +53,9 @@ public void change(@NotNull SlashCommandInteractionEvent event, UpdateController //Редактируем сообщение с Giveaway updateController.setView(embedBuilder.build(), guildIdLong, channelId, messageId); + } else { + String changeDuration = jsonParsers.getLocale("wrong_date", guildId); + event.reply(changeDuration).setEphemeral(true).queue(); } } } diff --git a/src/main/java/main/core/events/SchedulingCommand.java b/src/main/java/main/core/events/SchedulingCommand.java index 7901f67..0c871fb 100644 --- a/src/main/java/main/core/events/SchedulingCommand.java +++ b/src/main/java/main/core/events/SchedulingCommand.java @@ -85,7 +85,13 @@ public void scheduling(@NotNull SlashCommandInteractionEvent event) { return; } - if (GiveawayUtils.isTimeCorrect(startTime) || (endTime != null && GiveawayUtils.isTimeCorrect(endTime))) { + if (!GiveawayUtils.isISOTimeCorrect(startTime)) { + String wrongDate = jsonParsers.getLocale("wrong_date", guildId); + event.getHook().sendMessage(wrongDate).queue(); + return; + } + + if (endTime != null && !GiveawayUtils.isISOTimeCorrect(endTime)) { String wrongDate = jsonParsers.getLocale("wrong_date", guildId); event.getHook().sendMessage(wrongDate).queue(); return; diff --git a/src/main/java/main/core/events/StartCommand.java b/src/main/java/main/core/events/StartCommand.java index e0ff696..0b2bcc2 100644 --- a/src/main/java/main/core/events/StartCommand.java +++ b/src/main/java/main/core/events/StartCommand.java @@ -113,7 +113,7 @@ public void start(@NotNull SlashCommandInteractionEvent event, UpdateController } if (time != null) { - if (!time.matches(GiveawayUtils.ISO_TIME_REGEX) || !GiveawayUtils.isTimeBefore(time)) { + if (!GiveawayUtils.isISOTimeCorrect(time) && !GiveawayUtils.isTimeCorrect(time)) { String wrongDate = jsonParsers.getLocale("wrong_date", guildId); EmbedBuilder builder = new EmbedBuilder(); builder.setColor(Color.RED); diff --git a/src/main/java/main/giveaway/GiveawayUtils.java b/src/main/java/main/giveaway/GiveawayUtils.java index 09d37f6..4eb34f7 100644 --- a/src/main/java/main/giveaway/GiveawayUtils.java +++ b/src/main/java/main/giveaway/GiveawayUtils.java @@ -69,10 +69,14 @@ public static Color getUserColor(long guildId) { } } - public static boolean isTimeCorrect(@NotNull String time) { + public static boolean isISOTimeCorrect(@NotNull String time) { return time.matches(GiveawayUtils.ISO_TIME_REGEX); } + public static boolean isTimeCorrect(@NotNull String time) { + return time.matches(GiveawayUtils.TIME_REGEX); + } + public static boolean isTimeBefore(String time) { LocalDateTime localDateTime = LocalDateTime.parse(time, FORMATTER); LocalDateTime now = Instant.now().atOffset(ZoneOffset.UTC).toLocalDateTime();