Skip to content

Commit

Permalink
feat(cmd-define): update ephemeral logic for embed
Browse files Browse the repository at this point in the history
  • Loading branch information
christolis committed Aug 18, 2023
1 parent 37d02f9 commit 3b7969d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/bot/cmd/DefineCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
Expand Down Expand Up @@ -54,15 +55,18 @@ public void execute(SlashCommandInteractionEvent event) {
String word = event.getOption("word").getAsString();
WordCacheView wordCacheView = new WordCacheView();
Optional<CachedWord> cachedWord = wordCacheService.getWordFromCacheOrAPI(word);
ChannelType channelType = event.getChannel().getType();

if (cachedWord.isEmpty()) {
event.reply("I am not familiar with that word! :pensive:").setEphemeral(true).queue();
return;
}

boolean ephemeral = !channelType.isGuild();
EmbedBuilder embedBuilder = wordCacheView.getDefinitionEmbed(cachedWord.get());
event.replyEmbeds(embedBuilder.build())
.addActionRow(Button.secondary("save", "Save").withEmoji(Emoji.fromUnicode("💾")))
.setEphemeral(ephemeral)
.queue();
}

Expand Down

0 comments on commit 3b7969d

Please sign in to comment.