Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction;
import org.jetbrains.annotations.NotNull;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.commands.SlashCommandVisibility;
Expand All @@ -21,6 +23,7 @@ public final class TagCommand extends SlashCommandAdapter {
private final TagSystem tagSystem;

private static final String ID_OPTION = "id";
private static final String REPLY_TO_USER_OPTION = "reply-to";

/**
* Creates a new instance, using the given tag system as base.
Expand All @@ -32,24 +35,32 @@ public TagCommand(TagSystem tagSystem) {

this.tagSystem = tagSystem;

// TODO Thing about adding an ephemeral selection menu with pagination support
// TODO Think about adding an ephemeral selection menu with pagination support
// if the user calls this without id or similar
getData().addOption(OptionType.STRING, ID_OPTION, "the id of the tag to display", true);
getData().addOption(OptionType.STRING, ID_OPTION, "The id of the tag to display", true)
.addOption(OptionType.USER, REPLY_TO_USER_OPTION,
"Optionally, the user who you want to reply to", false);
}

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
String id = Objects.requireNonNull(event.getOption(ID_OPTION)).getAsString();
OptionMapping replyToUserOption = event.getOption(REPLY_TO_USER_OPTION);

if (tagSystem.handleIsUnknownTag(id, event)) {
return;
}

event
ReplyAction message = event
.replyEmbeds(new EmbedBuilder().setDescription(tagSystem.getTag(id).orElseThrow())
.setFooter(event.getUser().getName() + " • used " + event.getCommandString())
.setTimestamp(Instant.now())
.setColor(TagSystem.AMBIENT_COLOR)
.build())
.queue();
.build());

if (replyToUserOption != null) {
message = message.setContent(replyToUserOption.getAsUser().getAsMention());
}
message.queue();
}
}