use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.
the class ListQuestionsSubcommand method handleCommand.
@Override
protected ReplyCallbackAction handleCommand(SlashCommandInteractionEvent event, Connection con, long guildId) throws SQLException {
var repository = new QuestionQueueRepository(con);
OptionMapping pageOption = event.getOption("page");
int page = 0;
if (pageOption != null) {
int userPage = (int) pageOption.getAsLong();
if (userPage < 0) {
return Responses.warning(event, "Invalid page.");
}
page = userPage;
}
var questions = repository.getQuestions(guildId, page, 10);
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("QOTW Questions Queue");
if (questions.isEmpty()) {
embedBuilder.setDescription("There are no questions in the queue.");
return event.replyEmbeds(embedBuilder.build());
}
Bot.asyncPool.submit(() -> {
for (var question : questions) {
embedBuilder.addField(String.valueOf(question.getId()), String.format("> %s\nPriority: **%d**\nCreated by: %s\nCreated at: %s", question.getText(), question.getPriority(), event.getJDA().retrieveUserById(question.getCreatedBy()).complete().getAsTag(), question.getCreatedAt().format(DateTimeFormatter.ofPattern("d MMMM yyyy"))), false);
}
event.getHook().sendMessageEmbeds(embedBuilder.build()).queue();
});
return event.deferReply();
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.
the class AuditCommand method onSlashCommand.
@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
OptionMapping targetOption = Objects.requireNonNull(event.getOption(TARGET_OPTION), "The target is null");
User target = targetOption.getAsUser();
Member author = Objects.requireNonNull(event.getMember(), "The author is null");
Guild guild = Objects.requireNonNull(event.getGuild());
Member bot = guild.getSelfMember();
if (!handleChecks(bot, author, targetOption.getAsMember(), guild, event)) {
return;
}
auditUser(target, guild, event);
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.
the class RoleSelectCommand method onSlashCommand.
@Override
public void onSlashCommand(@NotNull final SlashCommandEvent event) {
Member member = Objects.requireNonNull(event.getMember(), "Member is null");
if (!member.hasPermission(Permission.MANAGE_ROLES)) {
event.reply("You dont have the right permissions to use this command").setEphemeral(true).queue();
return;
}
Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember();
if (!selfMember.hasPermission(Permission.MANAGE_ROLES)) {
event.reply("The bot needs the manage role permissions").setEphemeral(true).queue();
logger.error("The bot needs the manage role permissions");
return;
}
SelectionMenu.Builder menu = SelectionMenu.create(generateComponentId(Lifespan.PERMANENT, member.getId()));
addMenuOptions(event, menu, "Select the roles to display", 1);
// Handle Optional arguments
OptionMapping titleOption = event.getOption(TITLE_OPTION);
OptionMapping descriptionOption = event.getOption(DESCRIPTION_OPTION);
String title = handleOption(titleOption);
String description = handleOption(descriptionOption);
MessageBuilder messageBuilder = new MessageBuilder(makeEmbed(title, description)).setActionRows(ActionRow.of(menu.build()));
event.reply(messageBuilder.build()).setEphemeral(true).queue();
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.
the class NoteCommand method onSlashCommand.
@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
OptionMapping targetOption = event.getOption(USER_OPTION);
Member author = event.getMember();
Guild guild = event.getGuild();
String content = event.getOption(CONTENT_OPTION).getAsString();
if (!handleChecks(guild.getSelfMember(), author, targetOption.getAsMember(), content, event)) {
return;
}
sendNote(targetOption.getAsUser(), author, content, guild, event);
}
use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.
the class TagCommand method onSlashCommand.
@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;
}
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());
if (replyToUserOption != null) {
message = message.setContent(replyToUserOption.getAsUser().getAsMention());
}
message.queue();
}
Aggregations