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 Feb 6, 2024
1 parent c6cdbbf commit ca0d0a0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/main/java/main/core/events/CancelCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main.core.events;

import main.giveaway.GiveawayRegistry;
import main.model.entity.ActiveGiveaways;
import main.model.entity.Scheduling;
import main.model.repository.ActiveGiveawayRepository;
import main.model.repository.SchedulingRepository;
import net.dv8tion.jda.api.EmbedBuilder;
Expand All @@ -26,19 +28,30 @@ public CancelCommand(SchedulingRepository schedulingRepository, ActiveGiveawayRe
public void cancel(@NotNull SlashCommandInteractionEvent event) {
if (event.getGuild() == null) return;
long guildId = event.getGuild().getIdLong();
long userId = event.getUser().getIdLong();

schedulingRepository.deleteById(guildId);
activeGiveawayRepository.deleteById(guildId);
Scheduling scheduling = schedulingRepository.findByIdUserWhoCreateGiveawayAndGuildLongId(userId, guildId);
ActiveGiveaways activeGiveaways = activeGiveawayRepository.findByIdUserWhoCreateGiveawayAndGuildLongId(userId, guildId);

GiveawayRegistry instance = GiveawayRegistry.getInstance();
instance.removeGiveaway(guildId);

EmbedBuilder cancel = new EmbedBuilder();
cancel.setColor(Color.GREEN);
cancel.setDescription("Успешно отменили Giveaway!");

if (scheduling != null) {
schedulingRepository.deleteById(guildId);
instance.removeGiveaway(guildId);
cancel.setDescription("Успешно отменили запланированный Giveaway!");
} else if (activeGiveaways != null) {
activeGiveawayRepository.deleteById(guildId);
instance.removeGiveaway(guildId);
cancel.setDescription("Успешно отменили Giveaway!");
} else {
cancel.setDescription("Нет доступа или нет активных Giveaway!");
}

event.replyEmbeds(cancel.build())
.setEphemeral(true)
.queue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface ActiveGiveawayRepository extends JpaRepository<ActiveGiveaways,
@NotNull
@EntityGraph(attributePaths = {"participants"})
List<ActiveGiveaways> findAll();

ActiveGiveaways findByIdUserWhoCreateGiveawayAndGuildLongId(Long idUserWhoCreateGiveaway, Long guildLongId);
}
5 changes: 5 additions & 0 deletions src/main/java/main/model/repository/SchedulingRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import main.model.entity.Scheduling;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -13,5 +14,9 @@ public interface SchedulingRepository extends JpaRepository<Scheduling, Long> {
@NotNull
List<Scheduling> findAll();

@Nullable
Scheduling findByIdUserWhoCreateGiveawayAndGuildLongId(Long idUserWhoCreateGiveaway, Long guildLongId);

@Nullable
Scheduling findByGuildLongId(Long guildLongId);
}

0 comments on commit ca0d0a0

Please sign in to comment.