Search in sources :

Example 16 with VoiceChannel

use of net.dv8tion.jda.core.entities.VoiceChannel in project FlareBot by FlareBot.

the class DebugCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length < 1) {
        MessageUtils.sendUsage(this, channel, sender, args);
        return;
    }
    FlareBot fb = FlareBot.instance();
    EmbedBuilder eb = MessageUtils.getEmbed();
    if (args[0].equalsIgnoreCase("flarebot") || args[0].equalsIgnoreCase("bot")) {
        eb.setTitle("Bot Debug").setDescription(String.format("Debug for FlareBot v" + FlareBot.getVersion() + "\nUptime: %s" + "\nMemory Usage: %s" + "\nMemory Free: %s" + "\nVideo Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\n\nGuilds: %d" + "\nLoaded Guilds: %d" + "\nVoice Channels: %d" + "\nActive Voice Channels: %d" + "\nCommands Executed: %d" + "\nQueued RestActions: %s", fb.getUptime(), getMB(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()), getMB(Runtime.getRuntime().freeMemory()), VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), fb.getShardManager().getGuildCache().size(), FlareBotManager.instance().getGuilds().size(), Getters.getConnectedVoiceChannels(), Getters.getActiveVoiceChannels(), fb.getEvents().getCommandCount(), getQueuedRestActions()));
        StringBuilder sb = new StringBuilder();
        for (DataInterceptor interceptor : DataInterceptor.getInterceptors()) sb.append(WordUtils.capitalize(interceptor.getSender().getName())).append(" - ").append(interceptor.getRequests()).append(" requests").append("\n");
        eb.addField("HTTP Requests", sb.toString(), false);
    } else if (args[0].equalsIgnoreCase("threads")) {
        eb.setTitle("Thread Debug").setDescription(String.format("Video Threads: %d" + "\nCommand Threads: %d" + "\nTotal Threads: %d" + "\nThread list: %s", VideoThread.VIDEO_THREADS.activeCount(), Events.COMMAND_THREADS.activeCount(), Thread.getAllStackTraces().size(), MessageUtils.paste(Thread.getAllStackTraces().keySet().stream().map(th -> th.getName() + " - " + th.getState() + " (" + th.getThreadGroup().getName() + ")").collect(Collectors.joining("\n")))));
    } else if (args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("guild")) {
        GuildWrapper wrapper = guild;
        if (args.length == 2)
            wrapper = FlareBotManager.instance().getGuild(args[1]);
        if (wrapper == null) {
            channel.sendMessage("I can't find that guild!").queue();
            return;
        }
        eb.setTitle("Server Debug").setDescription(String.format("Debug for " + wrapper.getGuildIdLong() + "\nData Ver: %s (%s)" + "\nPrefix: %s" + "\nBlocked: %b" + "\nBeta: %b" + "\nWelcomes: %b/%b" + "\nNINO: %b" + "\nSong nick: %b" + "\nPerms: %s" + "\nMute role: %s" + "\nsettings: %s" + "\n\nFor full guild data do `_guild data " + wrapper.getGuildIdLong() + "`", wrapper.dataVersion, GuildWrapper.DATA_VERSION, MessageUtils.escapeMarkdown(String.valueOf(wrapper.getPrefix())), wrapper.isBlocked(), wrapper.getBetaAccess(), wrapper.getWelcome().isGuildEnabled(), wrapper.getWelcome().isDmEnabled(), wrapper.getNINO().isEnabled(), wrapper.isSongnickEnabled(), MessageUtils.paste(FlareBot.GSON.toJson(wrapper.getPermissions())), wrapper.getMutedRole(), wrapper.getSettings().toString()));
    } else if (args[0].equalsIgnoreCase("player") || args[0].equalsIgnoreCase("music")) {
        GuildWrapper wrapper = guild;
        if (args.length == 2)
            wrapper = FlareBotManager.instance().getGuild(args[1]);
        if (wrapper == null) {
            channel.sendMessage("I can't find that guild!").queue();
            return;
        }
        Player player = FlareBot.instance().getMusicManager().getPlayer(wrapper.getGuildId());
        AudioManager manager = wrapper.getGuild().getAudioManager();
        @Nullable VoiceChannel vc = manager.getConnectedChannel();
        String lastActive = "Not tracked.";
        if (VoiceChannelCleanup.VC_LAST_USED.containsKey(vc != null ? vc.getIdLong() : guild.getGuildIdLong())) {
            long ms = VoiceChannelCleanup.VC_LAST_USED.get(vc != null ? vc.getIdLong() : guild.getGuildIdLong());
            lastActive = String.valueOf(ms) + " (" + (System.currentTimeMillis() - ms) + "ms ago)";
        }
        boolean isPlaying = player.getPlayingTrack() != null;
        Track track = player.getPlayingTrack();
        eb.setTitle("Bot Debug").setDescription(String.format("Player Debug for `" + wrapper.getGuildId() + "`" + "\nCurrent Track: %s" + "\nCurrent Position: %s" + "\nIs Paused: %b" + "\nPlaylist Length: %s" + "\nIs Looping: %b" + "\nConnecting: %b" + "\nVoice Channel: %s" + "\nConnection State: %s" + "\nLast Active: %s", (isPlaying ? track.getTrack().getIdentifier() : "No current track"), (isPlaying ? track.getTrack().getPosition() + "/" + track.getTrack().getDuration() : "N/A"), player.getPaused(), player.getPlaylist().size(), player.getLooping(), manager.isAttemptingToConnect(), (vc == null ? "null" : vc.toString()), manager.getConnectionStatus().toString(), lastActive));
    } else {
        channel.sendMessage("Invalid debug option").queue();
        return;
    }
    channel.sendMessage(eb.build()).queue();
}
Also used : Track(com.arsenarsen.lavaplayerbridge.player.Track) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) WordUtils(org.apache.commons.lang3.text.WordUtils) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) VoiceChannelCleanup(stream.flarebot.flarebot.tasks.VoiceChannelCleanup) Player(com.arsenarsen.lavaplayerbridge.player.Player) FlareBot(stream.flarebot.flarebot.FlareBot) AudioManager(net.dv8tion.jda.core.managers.AudioManager) VideoThread(stream.flarebot.flarebot.music.VideoThread) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Collectors(java.util.stream.Collectors) Message(net.dv8tion.jda.core.entities.Message) Getters(stream.flarebot.flarebot.Getters) InternalCommand(stream.flarebot.flarebot.commands.InternalCommand) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Events(stream.flarebot.flarebot.Events) JDAImpl(net.dv8tion.jda.core.entities.impl.JDAImpl) User(net.dv8tion.jda.core.entities.User) FlareBotManager(stream.flarebot.flarebot.FlareBotManager) DataInterceptor(stream.flarebot.flarebot.web.DataInterceptor) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) CommandType(stream.flarebot.flarebot.commands.CommandType) Nullable(javax.annotation.Nullable) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) AudioManager(net.dv8tion.jda.core.managers.AudioManager) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Player(com.arsenarsen.lavaplayerbridge.player.Player) DataInterceptor(stream.flarebot.flarebot.web.DataInterceptor) FlareBot(stream.flarebot.flarebot.FlareBot) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Example 17 with VoiceChannel

use of net.dv8tion.jda.core.entities.VoiceChannel in project TheLighterBot by PhotonBursted.

the class FileController method retrieveLinkedChannels.

private void retrieveLinkedChannels() throws SQLException {
    retrieveData("SELECT *\n" + "FROM \"LinkedChannels\"", result -> {
        try {
            TextChannel tc = l.getBot().getTextChannelById(result.getLong("tc_id"));
            VoiceChannel vc = l.getBot().getVoiceChannelById(result.getLong("vc_id"));
            if (tc != null && vc != null) {
                l.getChannelController().getLinkedChannels().putStoring(tc, vc);
            }
        } catch (SQLException ex) {
            log.error("Something went wrong retrieving the linked channels", ex);
        }
    });
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Example 18 with VoiceChannel

use of net.dv8tion.jda.core.entities.VoiceChannel in project TheLighterBot by PhotonBursted.

the class LinkChannelCommand method execute.

@Override
protected void execute() {
    if (!ev.getMember().getVoiceState().inVoiceChannel()) {
        handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
    }
    VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
    if (l.getChannelController().isLinked(vc)) {
        handleError(MessageContent.CHANNEL_ALREADY_LINKED);
    }
    TextChannel tc = ev.getChannel();
    l.getChannelController().getLinkedChannels().putStoring(tc, vc);
    l.getChannelController().getPermChannels().putStoring(tc, vc);
    LoggerUtils.logAndDelete(log, String.format("A new link has been established:\n" + " - VC: %s (%s)\n" + " - TC: %s (%s)", vc.getName(), vc.getId(), tc.getName(), tc.getId()));
    l.getDiscordController().sendMessage(tc, String.format("Successfully linked **%s** to **%s**!", vc.getName(), tc.getAsMention()), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Example 19 with VoiceChannel

use of net.dv8tion.jda.core.entities.VoiceChannel in project TheLighterBot by PhotonBursted.

the class TemporaryChannelSizeCommand method execute.

@Override
protected void execute() {
    // Get the channels targeted by the issuer
    VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
    TextChannel tc = l.getChannelController().getLinkedChannels().getForVoiceChannel(vc);
    // If the voice channel wasn't found the user wasn't in one to start with
    if (vc == null) {
        handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
        return;
    }
    // The target should not be the default channel
    if (vc == ev.getGuild().getAfkChannel()) {
        handleError(MessageContent.AFK_CHANNEL_ACTION_NOT_PERMITTED);
        return;
    }
    // If the target voice channel is permanent, the user requires MANAGE_CHANNEL permissions
    if (l.getChannelController().isPermanent(vc) && (!l.getChannelController().isPermanent(vc) || !ev.getMember().hasPermission(Permission.MANAGE_CHANNEL))) {
        handleError(MessageContent.PERMISSIONS_REQUIRED, Permission.MANAGE_CHANNEL.name(), "change the size of permanent voice channels");
        return;
    }
    if (input.size() == 0) {
        handleError("No new size for the channel was specified!");
        return;
    }
    // If all of this is the case, getInstance the limit to be applied
    String limit = input.poll();
    assert limit != null;
    if (limit.equals("remove")) {
        limit = "0";
    }
    // If the input is an integer and within the limits, update the channel
    if (!Utils.isInteger(limit) || Integer.parseInt(limit) < 0 || Integer.parseInt(limit) > 99) {
        handleError(MessageContent.INVALID_INPUT, "Only integers between 0 (inclusive) and 99 (inclusive) are allowed!");
        return;
    }
    int intLimit = Integer.parseInt(limit);
    if (intLimit == vc.getUserLimit()) {
        handleError("No action was taken as the new limit was the same as currently set.");
        return;
    }
    // Get the user limit and set the new value
    vc.getManager().setUserLimit(intLimit).reason("A command was issued from a temporary channel").queue();
    // If a channel is linked, update its permissions
    if (tc != null) {
        // Send feedback to the logs and issuer
        LoggerUtils.logAndDelete(log, String.format("Changed user limit of channel \"%s\" to %s.", vc.getName(), intLimit));
        l.getDiscordController().sendMessage(ev, String.format("**%s** changed the user limit %sto **%s**.", ev.getMember().getEffectiveName(), tc.equals(ev.getChannel()) ? ("of **" + vc.getName() + "** ") : "", intLimit), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
        // If the limit is 0, this means the limit was removed
        if (intLimit == 0) {
            l.getChannelPermissionController().changeToPublicFromPrivate(tc, vc);
        } else {
            l.getChannelPermissionController().changeToPrivateFromPublic(tc, vc);
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Example 20 with VoiceChannel

use of net.dv8tion.jda.core.entities.VoiceChannel in project TheLighterBot by PhotonBursted.

the class TemporaryChannelTopicCommand method execute.

@Override
protected void execute() {
    // Get the channels targeted by the issuer
    VoiceChannel vc = ev.getMember().getVoiceState().getChannel();
    TextChannel tc = l.getChannelController().getLinkedChannels().getForVoiceChannel(vc);
    // If the voice channel wasn't found the user wasn't in one to start with
    if (vc == null) {
        handleError(MessageContent.NOT_IN_VOICE_CHANNEL);
        return;
    }
    // The target should not be the default channel
    if (vc == ev.getGuild().getAfkChannel()) {
        handleError(MessageContent.AFK_CHANNEL_ACTION_NOT_PERMITTED);
        return;
    }
    // If the target voice channel is permanent, the user requires MANAGE_CHANNEL permissions
    if (l.getChannelController().isPermanent(vc) && (!l.getChannelController().isPermanent(vc) || !ev.getMember().hasPermission(Permission.MANAGE_CHANNEL))) {
        handleError(MessageContent.PERMISSIONS_REQUIRED, Permission.MANAGE_CHANNEL.name(), "change the topic of permanent voice channels");
        return;
    }
    String description = Utils.drainQueueToString(input);
    if (tc != null) {
        // Send feedback to the logs and issuer
        LoggerUtils.logAndDelete(log, String.format("Changed description of channel \"%s\" to \"%s\".", tc.getName(), description));
        l.getDiscordController().sendMessage(ev, String.format("**%s** changed the topic%s.", ev.getAuthor().getName(), !tc.equals(ev.getChannel()) ? ("of **" + tc.getAsMention() + "**") : ""), DiscordController.AUTOMATIC_REMOVAL_INTERVAL);
        tc.getManager().setTopic(description).reason(Utils.userAsString(ev.getAuthor()) + " requested a change of topic for this channel.").queue();
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel)

Aggregations

VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)38 TextChannel (net.dv8tion.jda.core.entities.TextChannel)13 Guild (net.dv8tion.jda.core.entities.Guild)8 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)7 Message (net.dv8tion.jda.core.entities.Message)7 AudioManager (net.dv8tion.jda.core.managers.AudioManager)6 GuildPlayer (fredboat.audio.player.GuildPlayer)5 ArrayList (java.util.ArrayList)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Collectors (java.util.stream.Collectors)3 Member (net.dv8tion.jda.core.entities.Member)3 Player (com.arsenarsen.lavaplayerbridge.player.Player)2 Track (com.arsenarsen.lavaplayerbridge.player.Track)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2 AudioTrackContext (fredboat.audio.queue.AudioTrackContext)2 SplitAudioTrackContext (fredboat.audio.queue.SplitAudioTrackContext)2 Consumer (java.util.function.Consumer)2 Nullable (javax.annotation.Nullable)2 User (net.dv8tion.jda.core.entities.User)2 JDAImpl (net.dv8tion.jda.core.entities.impl.JDAImpl)2