Search in sources :

Example 1 with ReplyAction

use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction in project cds by iamysko.

the class SlashCommandListener method onSlashCommand.

@Override
public void onSlashCommand(SlashCommandEvent event) {
    boolean perm = false;
    if (RoleUtils.findRole(event.getMember(), RoleUtils.ROLE_SERVER_MANAGER) != null) {
        perm = true;
    } else if (RoleUtils.findRole(event.getMember(), RoleUtils.ROLE_SENIOR_MODERATOR) != null) {
        perm = true;
    } else if (RoleUtils.findRole(event.getMember(), RoleUtils.ROLE_MODERATOR) != null) {
        perm = true;
    } else if (RoleUtils.findRole(event.getMember(), RoleUtils.ROLE_TRIAL_MODERATOR) != null) {
        perm = true;
    } else {
        perm = false;
    }
    if (perm) {
        final TextChannel commandChannel = event.getGuild().getTextChannelById(Properties.CHANNEL_COMMANDS_ID);
        final Member author = event.getMember();
        final String authorMention = author.getAsMention();
        if (event.getName().equals(SlashCommandConstants.COMMAND_HELP)) {
            event.reply(StringBuilds.getHelpMessage(authorMention)).queue();
        } else if (event.getName().equals(SlashCommandConstants.COMMAND_ABOUT)) {
            event.reply(StringBuilds.getAboutMessage(authorMention)).queue();
        } else if (event.getName().equals(SlashCommandConstants.COMMAND_USER_INFO)) {
            Member theMember = event.getGuild().getMemberById(event.getOption("user").getAsString());
            RestAction<User> userData = event.getJDA().retrieveUserById(event.getOption("user").getAsString());
            User theUser = userData.complete();
            EmbedBuilder embed = EmbedBuilds.getUserInfoEmbed(theMember, theUser);
            ReplyAction reply = event.replyEmbeds(embed.build());
            if (theMember != null && theMember.getNickname() != null && RoleUtils.findRole(theMember, RoleUtils.ROLE_VERIFIED) != null) {
                reply.addActionRow(Button.danger("RobloxInformation/" + theMember.getNickname() + "/" + theMember.getId(), "Roblox Information"));
            }
            reply.queue();
        } else if (event.getName().equals(SlashCommandConstants.COMMAND_ROBLOX_USER_INFO)) {
            try {
                EmbedBuilder embed = EmbedBuilds.getRobloxUserInfoEmbed(event.getOption("username").getAsString(), null);
                event.replyEmbeds(embed.build()).queue();
            } catch (Exception e) {
                event.reply("It appears the Roblox API is currently not responding! Please Try again later! :(" + e).queue();
            }
        } else if (event.getName().equals(SlashCommandConstants.COMMAND_SCAN_URL)) {
            event.deferReply().queue();
            InteractionHook hook = event.getHook();
            new Thread(() -> {
                EmbedBuilder embed = null;
                try {
                    embed = EmbedBuilds.scanUrl(event.getOption("url").getAsString(), event.getJDA().getSelfUser().getEffectiveAvatarUrl());
                } catch (InterruptedException e) {
                    embed = EmbedBuilds.ApiError();
                }
                hook.editOriginalEmbeds(embed.build()).queue();
            }).start();
        } else {
            event.reply("The Command you tried to execute does not exist!").queue();
        }
    } else {
        event.reply("Missing permissions!").setEphemeral(true).queue();
    }
}
Also used : ReplyAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction) TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) User(net.dv8tion.jda.api.entities.User) InteractionHook(net.dv8tion.jda.api.interactions.InteractionHook) Member(net.dv8tion.jda.api.entities.Member)

Example 2 with ReplyAction

use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction in project Emolga by TecToast.

the class GenericCommandEvent method reply.

public void reply(MessageEmbed msg, @Nullable Consumer<MessageAction> ma, @Nullable Consumer<ReplyAction> ra, @Nullable Consumer<Message> m, @Nullable Consumer<InteractionHook> ih) {
    if (slashCommandEvent != null) {
        ReplyAction reply = slashCommandEvent.replyEmbeds(msg);
        if (ra != null)
            ra.accept(reply);
        reply.queue(ih);
    } else {
        MessageAction ac = getChannel().sendMessageEmbeds(msg);
        if (ma != null)
            ma.accept(ac);
        ac.queue(m);
    }
    logger.info("QUEUED! " + System.currentTimeMillis());
}
Also used : ReplyAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction)

Example 3 with ReplyAction

use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction in project Emolga by TecToast.

the class GenericCommandEvent method reply.

public void reply(String msg, @Nullable Consumer<MessageAction> ma, @Nullable Consumer<ReplyAction> ra, @Nullable Consumer<Message> m, @Nullable Consumer<InteractionHook> ih) {
    if (slashCommandEvent != null) {
        ReplyAction reply = slashCommandEvent.reply(msg);
        if (ra != null)
            ra.accept(reply);
        reply.queue(ih);
    } else {
        MessageAction ac = getChannel().sendMessage(msg);
        if (ma != null)
            ma.accept(ac);
        ac.queue(m);
    }
}
Also used : ReplyAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction)

Example 4 with ReplyAction

use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction 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();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) ReplyAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

Aggregations

ReplyAction (net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction)4 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 MessageAction (net.dv8tion.jda.api.requests.restaction.MessageAction)2 Member (net.dv8tion.jda.api.entities.Member)1 TextChannel (net.dv8tion.jda.api.entities.TextChannel)1 User (net.dv8tion.jda.api.entities.User)1 InteractionHook (net.dv8tion.jda.api.interactions.InteractionHook)1 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)1