Search in sources :

Example 1 with FlareBot

use of stream.flarebot.flarebot.FlareBot 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")) {
    } 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());
        VoiceChannel vc = (wrapper.getGuild().getSelfMember().getVoiceState() != null && wrapper.getGuild().getSelfMember().getVoiceState().getChannel() != null ? wrapper.getGuild().getSelfMember().getVoiceState().getChannel() : null);
        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" + "\nVoice Channel: %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(), (vc == null ? "null" : vc.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) 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) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) 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 2 with FlareBot

use of stream.flarebot.flarebot.FlareBot in project FlareBot by FlareBot.

the class ModlogHandler method handleAction.

/**
 * Handle a ModAction, this will do a bunch of checks and if they pass it will handle said action. For example if
 * you want to ban someone it will do checks like if you can ban that user, ig they're the owner, if you're trying
 * to ban yourself etc. After those pass it will then do the actual banning, post to the modlog and handle any tmp
 * stuff if needed.<br />
 * See also {@link #handleAction(GuildWrapper, TextChannel, User, User, ModAction, String)}
 *
 * @param wrapper   The GuildWrapper of the guild this is being done in.
 * @param channel   The channel this was executed, this is used for failire messages in the checks.
 * @param sender    The person who sent that said action, the user responsible.
 * @param target    The target user to have the action taken against.
 * @param modAction The ModAction to be performed.
 * @param reason    The reason this was done, if this is null it will default to "No Reason Given".
 * @param duration  The duration of said action, this only applies to temp actions, -1 should be passed otherwise.
 */
public void handleAction(GuildWrapper wrapper, TextChannel channel, User sender, User target, ModAction modAction, String reason, long duration) {
    String rsn = (reason == null ? "No reason given!" : "(`" + reason.replaceAll("`", "'") + "`)");
    Member member = null;
    if (target != null) {
        member = wrapper.getGuild().getMember(target);
    }
    if (channel == null)
        return;
    if (member == null && modAction != ModAction.FORCE_BAN && modAction != ModAction.UNBAN) {
        MessageUtils.sendErrorMessage("That user isn't in this server!" + (modAction == ModAction.KICK ? " You can forceban with `{%}forceban <id>` to keep them from coming back." : ""), channel);
        return;
    }
    // Make sure the target user isn't the guild owner
    if (member != null && member.isOwner()) {
        MessageUtils.sendErrorMessage(String.format("Cannot %s **%s** because they're the guild owner!", modAction.getLowercaseName(), MessageUtils.getTag(target)), channel);
        return;
    }
    // Make sure the target user isn't themselves
    if (target != null && sender != null && target.getIdLong() == sender.getIdLong()) {
        MessageUtils.sendErrorMessage(String.format("You cannot %s yourself you daft person!", modAction.getLowercaseName()), channel);
        return;
    }
    if (target != null && target.getIdLong() == FlareBot.instance().getClient().getSelfUser().getIdLong()) {
        if (modAction == ModAction.UNBAN || modAction == ModAction.UNMUTE)
            MessageUtils.sendWarningMessage("W-why would you want to do that in the first place. Meanie :(", channel);
        else
            MessageUtils.sendWarningMessage(String.format("T-that's meannnnnnn :( I can't %s myself and I hope you don't want to either :(", modAction.getLowercaseName()), channel);
        return;
    }
    // Check if the person is below the target in role hierarchy
    if (member != null && sender != null && !canInteract(wrapper.getGuild().getMember(sender), member, wrapper)) {
        MessageUtils.sendErrorMessage(String.format("You cannot %s a user who is higher than you in the role hierarchy!", modAction.getLowercaseName()), channel);
        return;
    }
    // not just kick, ban etc.
    if (member != null && !wrapper.getGuild().getSelfMember().canInteract(member)) {
        MessageUtils.sendErrorMessage(String.format("Cannot " + modAction.getLowercaseName() + " %s! " + "Their highest role is higher than my highest role or they're the guild owner.", MessageUtils.getTag(target)), channel);
        return;
    }
    try {
        // BAN
        switch(modAction) {
            case BAN:
                channel.getGuild().getController().ban(target, 7, reason).queue(aVoid -> channel.sendMessage(new EmbedBuilder().setColor(Color.GREEN).setDescription("The ban hammer has been struck on " + target.getName() + " <:banhammer:368861419602575364>\nReason: " + rsn).setImage(channel.getGuild().getIdLong() == Constants.OFFICIAL_GUILD ? "https://flarebot.stream/img/banhammer.png" : null).build()).queue());
                break;
            case FORCE_BAN:
                channel.getGuild().getController().ban(target.getId(), 7, reason).queue(aVoid -> channel.sendMessage(new EmbedBuilder().setColor(Color.GREEN).setDescription("The ban hammer has been forcefully struck on " + target.getName() + " <:banhammer:368861419602575364>\nReason: " + rsn).setImage(channel.getGuild().getIdLong() == Constants.OFFICIAL_GUILD ? "https://flarebot.stream/img/banhammer.png" : null).build()).queue());
                break;
            case TEMP_BAN:
                {
                    Period period = new Period(duration);
                    channel.getGuild().getController().ban(channel.getGuild().getMember(target), 7, reason).queue(aVoid -> {
                        channel.sendMessage(new EmbedBuilder().setDescription("The ban hammer has been struck on " + target.getName() + " for " + FormatUtils.formatJodaTime(period) + "\nReason: " + rsn).setImage(channel.getGuild().getIdLong() == Constants.OFFICIAL_GUILD ? "https://flarebot.stream/img/banhammer.png" : null).setColor(Color.WHITE).build()).queue();
                        Scheduler.queueFutureAction(channel.getGuild().getIdLong(), channel.getIdLong(), sender.getIdLong(), target.getIdLong(), reason, period, FutureAction.Action.TEMP_BAN);
                    });
                    break;
                }
            case UNBAN:
                wrapper.getGuild().getController().unban(target).queue();
                MessageUtils.sendSuccessMessage("Unbanned " + target.getAsMention() + "!", channel, sender);
                // MUTE
                break;
            case MUTE:
                try {
                    wrapper.getModeration().muteUser(wrapper, wrapper.getGuild().getMember(target));
                } catch (HierarchyException e) {
                    MessageUtils.sendErrorMessage("Cannot apply the mute role, make sure it is below FlareBot in the " + "role hierarchy.", channel);
                    return;
                }
                MessageUtils.sendSuccessMessage("Muted " + target.getAsMention() + "\nReason: " + rsn, channel, sender);
                break;
            case TEMP_MUTE:
                {
                    try {
                        wrapper.getModeration().muteUser(wrapper, wrapper.getGuild().getMember(target));
                    } catch (HierarchyException e) {
                        MessageUtils.sendErrorMessage("Cannot apply the mute role, make sure it is below FlareBot in the " + "role hierarchy.", channel);
                        return;
                    }
                    Period period = new Period(duration);
                    Scheduler.queueFutureAction(channel.getGuild().getIdLong(), channel.getIdLong(), sender.getIdLong(), target.getIdLong(), reason, period, FutureAction.Action.TEMP_MUTE);
                    MessageUtils.sendSuccessMessage("Temporarily Muted " + target.getAsMention() + " for " + FormatUtils.formatJodaTime(period) + "\nReason: " + rsn, channel, sender);
                    break;
                }
            case UNMUTE:
                if (wrapper.getMutedRole() != null && wrapper.getGuild().getMember(target).getRoles().contains(wrapper.getMutedRole())) {
                    wrapper.getModeration().unmuteUser(wrapper, member);
                    MessageUtils.sendSuccessMessage("Unmuted " + target.getAsMention(), channel, sender);
                } else {
                    MessageUtils.sendErrorMessage("That user isn't muted!!", channel);
                }
                // KICK and WARN
                break;
            case KICK:
                channel.getGuild().getController().kick(member, reason).queue(aVoid -> MessageUtils.sendSuccessMessage(target.getName() + " has been kicked from the server!\nReason: " + rsn, channel, sender));
                break;
            case WARN:
                wrapper.addWarning(target, (reason != null ? reason : "No reason provided - action done by " + sender.getName()));
                EmbedBuilder eb = new EmbedBuilder();
                eb.appendDescription("\u26A0 Warned " + MessageUtils.getTag(target) + "\nReason: " + rsn).setColor(Color.WHITE);
                channel.sendMessage(eb.build()).queue();
                break;
            default:
                throw new IllegalArgumentException("An illegal ModAction was attempted to be handled - " + modAction.toString());
        }
    } catch (PermissionException e) {
        MessageUtils.sendErrorMessage(String.format("Cannot " + modAction.getLowercaseName() + " %s! " + "I do not have the `" + e.getPermission().getName() + "` permission!", MessageUtils.getTag(target)), channel);
        return;
    }
    // TODO: Infraction
    postToModlog(wrapper, modAction.getEvent(), target, sender, rsn);
}
Also used : Color(java.awt.Color) Period(org.joda.time.Period) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) FlareBot(stream.flarebot.flarebot.FlareBot) HierarchyException(net.dv8tion.jda.core.exceptions.HierarchyException) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) FormatUtils(stream.flarebot.flarebot.util.general.FormatUtils) Permission(net.dv8tion.jda.core.Permission) Scheduler(stream.flarebot.flarebot.scheduler.Scheduler) FutureAction(stream.flarebot.flarebot.scheduler.FutureAction) Constants(stream.flarebot.flarebot.util.Constants) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) HierarchyException(net.dv8tion.jda.core.exceptions.HierarchyException) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Period(org.joda.time.Period)

Aggregations

EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 FlareBot (stream.flarebot.flarebot.FlareBot)2 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)2 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)2 Player (com.arsenarsen.lavaplayerbridge.player.Player)1 Track (com.arsenarsen.lavaplayerbridge.player.Track)1 Color (java.awt.Color)1 Collectors (java.util.stream.Collectors)1 Permission (net.dv8tion.jda.core.Permission)1 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)1 Member (net.dv8tion.jda.core.entities.Member)1 Message (net.dv8tion.jda.core.entities.Message)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 User (net.dv8tion.jda.core.entities.User)1 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)1 JDAImpl (net.dv8tion.jda.core.entities.impl.JDAImpl)1 HierarchyException (net.dv8tion.jda.core.exceptions.HierarchyException)1 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)1 WordUtils (org.apache.commons.lang3.text.WordUtils)1 Period (org.joda.time.Period)1