Search in sources :

Example 21 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel 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 22 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel 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 23 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel 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)

Example 24 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel 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 25 with TextChannel

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

the class ShardInfoCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    PagedTableBuilder tb = new PagedTableBuilder();
    tb.addColumn("Shard ID");
    tb.addColumn("Status");
    tb.addColumn("Ping");
    tb.addColumn("Guild Count");
    tb.addColumn("Connected VCs");
    List<JDA> shards = new ArrayList<>(Getters.getShards());
    Collections.reverse(shards);
    for (JDA jda : shards) {
        List<String> row = new ArrayList<>();
        row.add(ShardUtils.getDisplayShardId(jda) + (ShardUtils.getShardId(channel.getJDA()) == ShardUtils.getShardId(jda) ? " (You)" : ""));
        row.add(WordUtils.capitalizeFully(jda.getStatus().toString().replace("_", " ")));
        row.add(String.valueOf(jda.getPing()));
        row.add(String.valueOf(jda.getGuilds().size()));
        row.add(String.valueOf(jda.getVoiceChannels().stream().filter(vc -> vc.getMembers().contains(vc.getGuild().getSelfMember())).count()));
        tb.addRow(row);
    }
    PaginationUtil.sendPagedMessage(channel, tb.build(), 0, sender, ButtonGroupConstants.SHARDINFO);
}
Also used : PagedTableBuilder(stream.flarebot.flarebot.util.pagination.PagedTableBuilder) WordUtils(org.apache.commons.lang3.text.WordUtils) PaginationUtil(stream.flarebot.flarebot.util.pagination.PaginationUtil) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) ShardUtils(stream.flarebot.flarebot.util.ShardUtils) PagedTableBuilder(stream.flarebot.flarebot.util.pagination.PagedTableBuilder) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Message(net.dv8tion.jda.core.entities.Message) Getters(stream.flarebot.flarebot.Getters) ButtonGroupConstants(stream.flarebot.flarebot.util.buttons.ButtonGroupConstants) ArrayList(java.util.ArrayList) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) User(net.dv8tion.jda.core.entities.User) Command(stream.flarebot.flarebot.commands.Command) JDA(net.dv8tion.jda.core.JDA) CommandType(stream.flarebot.flarebot.commands.CommandType) Collections(java.util.Collections) JDA(net.dv8tion.jda.core.JDA) ArrayList(java.util.ArrayList)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)91 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)27 Guild (net.dv8tion.jda.core.entities.Guild)22 User (net.dv8tion.jda.core.entities.User)20 Member (net.dv8tion.jda.core.entities.Member)18 List (java.util.List)17 Message (net.dv8tion.jda.core.entities.Message)17 ArrayList (java.util.ArrayList)14 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)13 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)13 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)13 Collectors (java.util.stream.Collectors)11 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Role (net.dv8tion.jda.core.entities.Role)7 FlareBot (stream.flarebot.flarebot.FlareBot)7 Track (com.arsenarsen.lavaplayerbridge.player.Track)6 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)6 MantaroData (net.kodehawa.mantarobot.data.MantaroData)6 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)6 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)6