Skip to content

Commit

Permalink
New Update
Browse files Browse the repository at this point in the history
1. Fix
  • Loading branch information
megoRU committed May 27, 2024
1 parent aa223c4 commit b5793d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/main/config/BotStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/main/core/events/ChangeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/main/core/events/SchedulingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/main/core/events/StartCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/main/giveaway/GiveawayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b5793d2

Please sign in to comment.