Search in sources :

Example 16 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class TagSystemTest method handleIsUnknownTag.

@Test
void handleIsUnknownTag() {
    insertTagRaw("known", "foo");
    SlashCommandEvent event = jdaTester.createSlashCommandEvent(new TagCommand(system)).build();
    assertFalse(system.handleIsUnknownTag("known", event));
    verify(event, never()).reply(anyString());
    assertTrue(system.handleIsUnknownTag("unknown", event));
    verify(event).reply(anyString());
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test)

Example 17 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class PingCommandTest method triggerSlashCommand.

@NotNull
private SlashCommandEvent triggerSlashCommand() {
    SlashCommandEvent event = jdaTester.createSlashCommandEvent(command).build();
    command.onSlashCommand(event);
    return event;
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TechDiscordBot by TechsCode-Team.

the class TicketModule method onSlashCommand.

@SubscribeEvent
public void onSlashCommand(SlashCommandEvent e) {
    if (e.getMember() == null || e.getMember().getUser().isBot())
        return;
    if (e.getName().equals("ticket") && e.getSubcommandName() != null) {
        if (!isTicketChat(e.getTextChannel())) {
            e.reply("This channel is not a ticket!").setEphemeral(true).queue();
            return;
        }
        boolean isTicketCreator = e.getTextChannel().getTopic() != null && e.getTextChannel().getTopic().contains(e.getMember().getAsMention());
        if (!isTicketCreator && !TechDiscordBot.isStaff(e.getMember())) {
            e.reply("You have to be the ticket creator or a staff member to execute this command!").setEphemeral(true).queue();
            return;
        }
        Member member = e.getOption("member") == null ? null : e.getOption("member").getAsMember();
        if (!e.getSubcommandName().equals("transcript") && !e.getSubcommandName().equals("close") && member == null) {
            e.reply("**Member is invalid!** This probably shouldn't be happening...").setEphemeral(true).queue();
            return;
        }
        switch(e.getSubcommandName()) {
            case "transcript":
                {
                    if (!TechDiscordBot.isStaff(e.getMember())) {
                        e.reply("You cannot force a ticket transcript!").setEphemeral(true).queue();
                        return;
                    }
                    TicketTranscript transcript = TicketTranscript.buildTranscript(e.getTextChannel(), TicketTranscriptOptions.DEFAULT);
                    Member ticketMember = getMemberFromTicket(e.getTextChannel());
                    e.reply("Generating the transcript... please wait.").queue(msg -> {
                        transcript.build(object -> {
                            if (ticketMember != null) {
                                TranscriptLogs.log(new TechEmbedBuilder("Ticket Transcript (Command)").text(ticketMember == null ? "Transcript of #" + e.getChannel().getName() + ": " + transcript.getUrl() : "Transcript of " + ticketMember.getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE));
                            }
                            msg.editOriginalEmbeds(new TechEmbedBuilder("Ticket Transcript").text(ticketMember == null ? "Transcript of #" + e.getChannel().getName() + ": " + transcript.getUrl() : "Transcript of " + ticketMember.getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE).build()).queue();
                            TechDiscordBot.getStorage().saveTranscript(object);
                        });
                    });
                }
            case "add":
                if (e.getMember().equals(member)) {
                    e.reply("You can't be added to a ticket you're already in.").setEphemeral(true).queue();
                    return;
                }
                e.reply("Successfully added " + member.getAsMention() + " to this ticket!").queue();
                Collection<Permission> permissionsAddAllow = new ArrayList<>(Arrays.asList(Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY));
                Collection<Permission> permissionsAddDeny = new ArrayList<>(Arrays.asList(Permission.MANAGE_THREADS, Permission.USE_PRIVATE_THREADS, Permission.USE_PUBLIC_THREADS));
                e.getTextChannel().getManager().putPermissionOverride(member, permissionsAddAllow, permissionsAddDeny).queue();
                break;
            case "remove":
                boolean isTicketCreator2 = e.getTextChannel().getTopic() != null && e.getTextChannel().getTopic().contains(member.getAsMention());
                if (TechDiscordBot.isStaff(member) || isTicketCreator2) {
                    e.reply(member.getAsMention() + " can't be removed from this ticket!").setEphemeral(true).queue();
                    return;
                }
                e.reply("Successfully removed " + member.getAsMention() + " from this ticket!").queue();
                Collection<Permission> permissionsRemoveDeny = new ArrayList<>(Arrays.asList(Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY));
                e.getTextChannel().getManager().putPermissionOverride(member, new ArrayList<>(), permissionsRemoveDeny).queue();
                break;
            case "close":
                TicketTranscript transcript = TicketTranscript.buildTranscript(e.getTextChannel(), TicketTranscriptOptions.DEFAULT);
                String channelId = e.getChannel().getId();
                if (isTicketCreator) {
                    if (CLOSING_CHANNELS.contains(e.getChannel().getId())) {
                        e.reply("This ticket is already closing!").setEphemeral(true).queue();
                        return;
                    }
                    e.replyEmbeds(new TechEmbedBuilder("Ticket").text("Thank you for contacting us " + e.getMember().getAsMention() + ". Consider writing a review if you enjoyed the support!").build()).queue();
                    transcript.build(object -> {
                        new TechEmbedBuilder("Transcript").text("You can view your recently closed ticket's transcript here:\n" + transcript.getUrl()).color(Color.ORANGE).queue(e.getMember());
                        TranscriptLogs.log(new TechEmbedBuilder("Ticket Transcript").text("Transcript of " + e.getMember().getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE));
                        e.getTextChannel().delete().queueAfter(15, TimeUnit.SECONDS, s -> CLOSING_CHANNELS.remove(channelId));
                        TechDiscordBot.getStorage().saveTranscript(object);
                    });
                    TicketLogs.log(new TechEmbedBuilder("Solved Ticket").text("The ticket (" + e.getTextChannel().getName() + ") created by " + e.getMember().getAsMention() + " is now solved. Thanks for contacting us!").success());
                } else {
                    if (!TechDiscordBot.isStaff(e.getMember())) {
                        e.reply("You cannot close this ticket!").setEphemeral(true).queue();
                        return;
                    }
                    if (CLOSING_CHANNELS.contains(e.getChannel().getId())) {
                        e.reply("This ticket is already closing!").setEphemeral(true).queue();
                        return;
                    }
                    String reason = e.getOption("reason") == null ? null : e.getOption("reason").getAsString();
                    boolean hasReason = reason != null;
                    String reasonSend = (hasReason ? " \n\n**Reason**: " + reason : "");
                    Member ticketMember = getMemberFromTicket(e.getTextChannel());
                    e.replyEmbeds(new TechEmbedBuilder("Ticket").text(e.getMember().getAsMention() + " has closed this support ticket." + reasonSend).build()).queue();
                    CLOSING_CHANNELS.add(e.getChannel().getId());
                    if (ticketMember != null) {
                        new TechEmbedBuilder("Ticket Closed").text("The ticket (" + e.getTextChannel().getName() + ") from " + ticketMember.getAsMention() + " has been closed!").success().queueAfter(channel, 15, TimeUnit.SECONDS, (msg) -> reset());
                        if (ticketMember != null) {
                            new TechEmbedBuilder("Ticket Closed").text("Your ticket (" + e.getTextChannel().getName() + ") has been closed!" + reasonSend).success().queue(ticketMember);
                        }
                    } else {
                        new TechEmbedBuilder("Ticket Closed").text("The ticket (" + e.getTextChannel().getName() + ") from *member has left* has been closed!").success().queueAfter(channel, 15, TimeUnit.SECONDS, (msg) -> reset());
                    }
                    transcript.build(object -> {
                        if (ticketMember != null) {
                            TranscriptLogs.log(new TechEmbedBuilder("Ticket Transcript").text(ticketMember == null ? "Transcript of #" + e.getChannel().getName() + ": " + transcript.getUrl() : "Transcript of " + ticketMember.getAsMention() + "'s ticket:\n" + transcript.getUrl()).color(Color.ORANGE));
                            if (ticketMember != null) {
                                new TechEmbedBuilder("Ticket Closed").text("Your ticket (" + e.getTextChannel().getName() + ") has been closed!" + reasonSend + "\n\nYou can view the transcript here:\n" + transcript.getUrl()).success().queue(ticketMember);
                            }
                        }
                        TechDiscordBot.getStorage().saveTranscript(object);
                        e.getTextChannel().delete().queueAfter(15, TimeUnit.SECONDS, s -> CLOSING_CHANNELS.remove(channelId));
                    });
                }
                break;
            default:
                e.reply("Could not recognize this sub command!").setEphemeral(true).queue();
                break;
        }
    }
}
Also used : net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) java.util(java.util) TechDiscordBot(me.TechsCode.TechDiscordBot.TechDiscordBot) Permission(net.dv8tion.jda.api.Permission) Plugin(me.TechsCode.TechDiscordBot.util.Plugin) MessageReactionAddEvent(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent) Collectors(java.util.stream.Collectors) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Requirement(me.TechsCode.TechDiscordBot.objects.Requirement) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent) List(java.util.List) TicketTranscript(me.TechsCode.TechDiscordBot.transcripts.TicketTranscript) Module(me.TechsCode.TechDiscordBot.module.Module) TicketTranscriptOptions(me.TechsCode.TechDiscordBot.transcripts.TicketTranscriptOptions) TranscriptLogs(me.TechsCode.TechDiscordBot.logs.TranscriptLogs) TicketPriority(me.TechsCode.TechDiscordBot.objects.TicketPriority) TicketLogs(me.TechsCode.TechDiscordBot.logs.TicketLogs) DefinedQuery(me.TechsCode.TechDiscordBot.objects.DefinedQuery) Query(me.TechsCode.TechDiscordBot.objects.Query) TicketTranscript(me.TechsCode.TechDiscordBot.transcripts.TicketTranscript) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) Permission(net.dv8tion.jda.api.Permission) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Example 19 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project Robertify-Bot by bombies.

the class LofiSlashCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    if (!checksWithPremium(event))
        return;
    sendRandomMessage(event);
    Guild guild = event.getGuild();
    if (!premiumCheck(event))
        return;
    event.deferReply().queue();
    if (!musicCommandDJCheck(event)) {
        event.getHook().sendMessageEmbeds(RobertifyEmbedUtils.embedMessage(guild, "You must be a DJ to run this command!").build()).queue();
        return;
    }
    try {
        event.getHook().sendMessageEmbeds(new LofiCommand().handleLofi(guild, event.getMember(), event.getTextChannel())).queue();
    } catch (IllegalArgumentException e) {
        event.getHook().sendMessageEmbeds(RobertifyEmbedUtils.embedMessage(guild, "Enabling Lo-Fi mode...").build()).queue(botMsg -> {
            LofiCommand.getLofiEnabledGuilds().add(guild.getIdLong());
            LofiCommand.getAnnounceLofiMode().add(guild.getIdLong());
            RobertifyAudioManager.getInstance().loadAndPlayFromDedicatedChannel("https://www.youtube.com/watch?v=5qap5aO4i9A&ab_channel=LofiGirl", guild.getSelfMember().getVoiceState(), event.getMember().getVoiceState(), botMsg, event, false);
        });
    }
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Guild(net.dv8tion.jda.api.entities.Guild) RobertifyEmbedUtils(main.utils.RobertifyEmbedUtils) AbstractSlashCommand(main.utils.component.interactions.AbstractSlashCommand) NotNull(org.jetbrains.annotations.NotNull) RobertifyAudioManager(main.audiohandlers.RobertifyAudioManager) Guild(net.dv8tion.jda.api.entities.Guild)

Example 20 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class TagCommandTest method canFindTagsAndRepliesToUser.

@Test
@DisplayName("Replies to given users and responds with the tags content if the tag could be found and a user is given")
void canFindTagsAndRepliesToUser() {
    // GIVEN a system with the tag "first" registered and a user to reply to
    system.putTag("first", "foo");
    Member userToReplyTo = jdaTester.createMemberSpy(1);
    // WHEN triggering the slash command '/tag id:first reply-to:...' with that user
    SlashCommandEvent event = triggerSlashCommand("first", userToReplyTo);
    // THEN responds with the tags content and replies to the user
    verify(event).replyEmbeds(any(MessageEmbed.class));
    verify(jdaTester.getReplyActionMock()).setContent(userToReplyTo.getAsMention());
}
Also used : MessageEmbed(net.dv8tion.jda.api.entities.MessageEmbed) Member(net.dv8tion.jda.api.entities.Member) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

SlashCommandEvent (net.dv8tion.jda.api.events.interaction.SlashCommandEvent)35 Test (org.junit.jupiter.api.Test)24 DisplayName (org.junit.jupiter.api.DisplayName)23 NotNull (org.jetbrains.annotations.NotNull)8 Collectors (java.util.stream.Collectors)3 Member (net.dv8tion.jda.api.entities.Member)3 IOException (java.io.IOException)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 TechDiscordBot (me.TechsCode.TechDiscordBot.TechDiscordBot)2 DefinedQuery (me.TechsCode.TechDiscordBot.objects.DefinedQuery)2 Query (me.TechsCode.TechDiscordBot.objects.Query)2 TechEmbedBuilder (me.TechsCode.TechDiscordBot.util.TechEmbedBuilder)2 Permission (net.dv8tion.jda.api.Permission)2 Guild (net.dv8tion.jda.api.entities.Guild)2 MessageEmbed (net.dv8tion.jda.api.entities.MessageEmbed)2 OptionType (net.dv8tion.jda.api.interactions.commands.OptionType)2 OptionData (net.dv8tion.jda.api.interactions.commands.build.OptionData)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2