Search in sources :

Example 16 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project OrderlyDiscordBot by IceLeiYu.

the class MusicBot method displayQueue.

public void displayQueue(GenericInteractionCreateEvent event, boolean search, Guild guild, SelectMenuInteractionEvent SelectMenuInteractionEvent) {
    List<String> lang = Main.language.getGuildLang(guild.getId());
    GuildMusicManager musicManager = getMusicManager(guild);
    TrackScheduler scheduler = musicManager.scheduler;
    if (scheduler.musicInfo == null) {
        try {
            if (event instanceof SelectMenuInteractionEvent)
                ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_MUSIC), 0xFF0000)).queue();
        } catch (Exception ignored) {
        }
        return;
    }
    scheduler.calculatePauseTime();
    MessageEmbed[] embed = playStatus(event.getMember(), scheduler);
    if (musicManager.guild.getSelfMember().getVoiceState().getChannel() == null) {
        if (search)
            SelectMenuInteractionEvent.replyEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).setEphemeral(true).queue();
        else {
            if (event instanceof SelectMenuInteractionEvent)
                ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
            else if (event instanceof SlashCommandInteractionEvent)
                ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
        }
        return;
    }
    String vcID = musicManager.guild.getSelfMember().getVoiceState().getChannel().getId();
    if (search) {
        SelectMenuInteractionEvent.replyEmbeds(embed[0], embed[1]).setEphemeral(true).addActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
    } else {
        if (event instanceof SelectMenuInteractionEvent)
            ((SelectMenuInteractionEvent) event).getHook().editOriginalComponents().setEmbeds(embed[0], embed[1]).setActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
        else if (event instanceof SlashCommandInteractionEvent)
            ((SlashCommandInteractionEvent) event).getHook().editOriginalComponents().setEmbeds(embed[0], embed[1]).setActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
    }
    if (event.getGuild().getId().equals("882605953382514718"))
        event.getGuild().getTextChannelById("884070398742888478").sendMessageEmbeds(embed[0], embed[1]).setActionRows(controlButtons("", scheduler.musicPause, scheduler.loopStatus, vcID)).content(event.getUser().getAsTag()).queue();
}
Also used : SelectMenuInteractionEvent(net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent) GuildMusicManager(com.ice.multiBot.music.GuildMusicManager) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) TrackScheduler(com.ice.multiBot.music.TrackScheduler)

Example 17 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project OrderlyDiscordBot by IceLeiYu.

the class MusicBot method connectVC.

@SuppressWarnings("ALL")
private void connectVC(Guild guild, VoiceChannel vc, GenericInteractionCreateEvent event, Consumer consumer) {
    if (!guild.getAudioManager().isConnected()) {
        try {
            guild.getAudioManager().openAudioConnection(vc);
        } catch (Exception e) {
            List<String> lang = Main.language.getGuildLang(event.getGuild().getId());
            if (event instanceof SelectMenuInteractionEvent)
                ((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
            else if (event instanceof SlashCommandInteractionEvent)
                ((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
            return;
        }
        final MusicBot bot = this;
        guild.getAudioManager().setConnectionListener(new ConnectionListener() {

            @Override
            public void onStatusChange(ConnectionStatus connectionStatus) {
                if (connectionStatus == ConnectionStatus.CONNECTED) {
                    consumer.accept(null);
                    if (workCount == 0) {
                        jda.getPresence().setStatus(OnlineStatus.DO_NOT_DISTURB);
                        jda.getPresence().setActivity(Activity.of(Activity.ActivityType.COMPETING, "來點歌吧!"));
                    }
                    workCount++;
                    jda.getPresence().setActivity(Activity.of(Activity.ActivityType.LISTENING, workCount + " 個頻道"));
                    guild.getAudioManager().setConnectionListener(null);
                    // 新增bot到頻道
                    musicBotManager.setBotToChannel(guild.getId(), vc.getId(), bot);
                    if (guild.getSelfMember().getPermissions().contains(Permission.VOICE_DEAF_OTHERS))
                        guild.getSelfMember().deafen(true).queue();
                }
            }

            @Override
            public void onPing(long l) {
            }

            @Override
            public void onUserSpeaking(User user, boolean b) {
            }
        });
    } else
        consumer.accept(null);
}
Also used : SelectMenuInteractionEvent(net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) List(java.util.List) ConnectionListener(net.dv8tion.jda.api.audio.hooks.ConnectionListener) ConnectionStatus(net.dv8tion.jda.api.audio.hooks.ConnectionStatus) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 18 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project JavaBot by Java-Discord.

the class HelpChannelManager method unreserveChannelByOwner.

private void unreserveChannelByOwner(TextChannel channel, User owner, Interaction interaction) {
    var optionalReservation = getReservationForChannel(channel.getIdLong());
    if (optionalReservation.isEmpty()) {
        log.warn("Could not find current reservation data for channel {}. Unreserving the channel without thanks.", channel.getAsMention());
        unreserveChannel(channel);
        return;
    }
    var reservation = optionalReservation.get();
    // Ask the user for some feedback about the help channel, if possible.
    getParticipantsSinceReserved(channel).thenAcceptAsync(participants -> {
        List<Member> potentialHelpers = new ArrayList<>(participants.size());
        for (var entry : participants.entrySet()) {
            if (!entry.getKey().getUser().equals(owner))
                potentialHelpers.add(entry.getKey());
        }
        if (potentialHelpers.isEmpty()) {
            InteractionHook hook;
            if (interaction.getType() == InteractionType.COMPONENT) {
                hook = ((ButtonInteractionEvent) interaction).getHook();
            } else if (interaction.getType() == InteractionType.COMMAND) {
                hook = ((SlashCommandInteractionEvent) interaction).getHook();
            } else {
                throw new IllegalStateException("Unable to obtain Interaction Hook!");
            }
            Responses.info(hook, "Channel Unreserved", "Your channel has been unreserved.").queue();
            unreserveChannel(channel).queue();
            return;
        }
        potentialHelpers.sort((o1, o2) -> {
            int c = Integer.compare(participants.get(o1).size(), participants.get(o2).size());
            if (c == 0)
                return o1.getEffectiveName().compareTo(o2.getEffectiveName());
            return c;
        });
        sendThanksButtonsMessage(potentialHelpers, reservation, interaction, channel);
        try {
            setTimeout(channel, 5);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    });
}
Also used : InteractionHook(net.dv8tion.jda.api.interactions.InteractionHook) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) SQLException(java.sql.SQLException)

Example 19 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project triumph-cmds by TriumphTeam.

the class SlashCommandListener method onSlashCommandInteraction.

/**
 * Handler for the slash commands.
 * Needs to map the given result to the correct arguments to be used.
 *
 * @param event The slash command event.
 */
@Override
public void onSlashCommandInteraction(@NotNull final SlashCommandInteractionEvent event) {
    final String name = event.getName();
    SlashCommand<S> command = commandManager.getCommand(name);
    if (command == null) {
        final Guild guild = event.getGuild();
        if (guild == null)
            return;
        command = commandManager.getCommand(guild, name);
    }
    if (command == null)
        return;
    final S sender = senderMapper.map(new SlashCommandSender(event));
    final String subCommandName = event.getSubcommandName();
    final Map<String, String> args = event.getOptions().stream().map(it -> Maps.immutableEntry(it.getName(), it.getAsString())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    command.execute(sender, subCommandName != null ? subCommandName : Default.DEFAULT_CMD_NAME, args);
}
Also used : Default(dev.triumphteam.cmd.core.annotation.Default) Guild(net.dv8tion.jda.api.entities.Guild) Map(java.util.Map) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) SlashSender(dev.triumphteam.cmd.slash.sender.SlashSender) SenderMapper(dev.triumphteam.cmd.core.sender.SenderMapper) NotNull(org.jetbrains.annotations.NotNull) Maps(com.google.common.collect.Maps) ReadyEvent(net.dv8tion.jda.api.events.ReadyEvent) Collectors(java.util.stream.Collectors) Guild(net.dv8tion.jda.api.entities.Guild) Map(java.util.Map)

Example 20 with SlashCommandInteractionEvent

use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Bean by Xirado.

the class QueueCommand method executeCommand.

@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
    ButtonPaginator.Builder builder = new ButtonPaginator.Builder(event.getJDA()).setEventWaiter(Bean.getInstance().getEventWaiter()).setItemsPerPage(10).setTimeout(1, TimeUnit.MINUTES);
    int page = 1;
    if (event.getOption("page") != null)
        page = (int) event.getOption("page").getAsLong();
    GuildAudioPlayer guildAudioPlayer = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
    Queue<AudioTrack> queue = guildAudioPlayer.getScheduler().getQueue();
    if (queue.isEmpty()) {
        if (guildAudioPlayer.getPlayer().getPlayingTrack() != null) {
            if (guildAudioPlayer.getScheduler().isRepeat())
                ctx.sendSimpleEmbed("\uD83D\uDD01 **Currently playing** " + Util.titleMarkdown(guildAudioPlayer.getPlayer().getPlayingTrack()));
            else
                ctx.sendSimpleEmbed("**Currently playing** " + Util.titleMarkdown(guildAudioPlayer.getPlayer().getPlayingTrack()));
        } else
            ctx.replyError("There is no music playing!").queue();
        return;
    }
    String[] tracks = queue.stream().map(x -> Util.titleMarkdown(x, false) + " (<@" + x.getUserData(TrackInfo.class).getRequesterIdLong() + ">)").toArray(String[]::new);
    builder.setTitle(getQueueTitle(guildAudioPlayer)).setItems(tracks).addAllowedUsers(event.getUser().getIdLong()).setColor(Color.decode("#452350"));
    int finalPage = page;
    event.deferReply().queue(hook -> builder.build().paginate(hook.sendMessage(""), finalPage));
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) Util(at.xirado.bean.misc.Util) FormatUtil(at.xirado.bean.misc.FormatUtil) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Commands(net.dv8tion.jda.api.interactions.commands.build.Commands) SlashCommandContext(at.xirado.bean.command.SlashCommandContext) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer) SlashCommand(at.xirado.bean.command.SlashCommand) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) TrackInfo(at.xirado.bean.misc.objects.TrackInfo) Queue(java.util.Queue) Bean(at.xirado.bean.Bean) NotNull(org.jetbrains.annotations.NotNull) ButtonPaginator(at.xirado.bean.interactions.ButtonPaginator) TrackInfo(at.xirado.bean.misc.objects.TrackInfo) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildAudioPlayer(at.xirado.bean.music.GuildAudioPlayer) ButtonPaginator(at.xirado.bean.interactions.ButtonPaginator)

Aggregations

SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)24 Commands (net.dv8tion.jda.api.interactions.commands.build.Commands)11 NotNull (org.jetbrains.annotations.NotNull)11 SlashCommand (at.xirado.bean.command.SlashCommand)10 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)10 OptionType (net.dv8tion.jda.api.interactions.commands.OptionType)10 Permission (net.dv8tion.jda.api.Permission)9 EmbedUtil (at.xirado.bean.misc.EmbedUtil)7 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)7 Bean (at.xirado.bean.Bean)6 Guild (net.dv8tion.jda.api.entities.Guild)6 Member (net.dv8tion.jda.api.entities.Member)6 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)5 OptionData (net.dv8tion.jda.api.interactions.commands.build.OptionData)5 ReplyCallbackAction (net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction)5 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Util (at.xirado.bean.misc.Util)3 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)3 SQLException (java.sql.SQLException)3