From f0cc859585197d5fb29c4c7715777d2e9c00f79b Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 27 Jun 2024 21:30:09 +0100 Subject: [PATCH] oops! actually save the AFK status --- .../fascinated/bat/features/afk/AfkReturnListener.java | 10 ++++++++++ .../bat/features/afk/command/AfkCommand.java | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/fascinated/bat/features/afk/AfkReturnListener.java b/src/main/java/cc/fascinated/bat/features/afk/AfkReturnListener.java index c23a3c7..62d8b05 100644 --- a/src/main/java/cc/fascinated/bat/features/afk/AfkReturnListener.java +++ b/src/main/java/cc/fascinated/bat/features/afk/AfkReturnListener.java @@ -4,8 +4,10 @@ import cc.fascinated.bat.event.EventListener; import cc.fascinated.bat.features.afk.profile.AfkProfile; import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; +import cc.fascinated.bat.service.GuildService; import lombok.NonNull; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -13,6 +15,13 @@ import org.springframework.stereotype.Component; */ @Component public class AfkReturnListener implements EventListener { + private final GuildService guildService; + + @Autowired + public AfkReturnListener(@NonNull GuildService guildService) { + this.guildService = guildService; + } + @Override public void onGuildMessageReceive(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull MessageReceivedEvent event) { AfkProfile profile = guild.getProfile(AfkProfile.class); @@ -20,6 +29,7 @@ public class AfkReturnListener implements EventListener { return; } profile.removeAfkUser(guild, user.getId()); + guildService.saveGuild(guild); event.getMessage().reply("Welcome back, %s! You are no longer AFK.".formatted(user.getDiscordUser().getAsMention())).queue(); } } diff --git a/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java b/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java index cd27a09..e99c533 100644 --- a/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java +++ b/src/main/java/cc/fascinated/bat/features/afk/command/AfkCommand.java @@ -6,12 +6,14 @@ import cc.fascinated.bat.common.MemberUtils; import cc.fascinated.bat.features.afk.profile.AfkProfile; import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatUser; +import cc.fascinated.bat.service.GuildService; import lombok.NonNull; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -20,7 +22,11 @@ import org.springframework.stereotype.Component; @Component @CommandInfo(name = "afk", description = "Sets your AFK status") public class AfkCommand extends BatCommand { - public AfkCommand() { + private final GuildService guildService; + + @Autowired + public AfkCommand(@NonNull GuildService guildService) { + this.guildService = guildService; super.addOption(OptionType.STRING, "reason", "The reason for being AFK", false); } @@ -34,6 +40,7 @@ public class AfkCommand extends BatCommand { } profile.addAfkUser(guild, member.getId(), reason); + guildService.saveGuild(guild); interaction.reply("You are now AFK: %s%s".formatted( profile.getAfkReason(member.getId()), MemberUtils.hasPermissionToEdit(guild, user) ? "" :