Search in sources :

Example 56 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder 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 57 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.

the class WarningsCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("stats")) {
            Map.Entry<String, List<String>> highestEntry = Collections.max(guild.getWarningsMap().entrySet(), Comparator.comparingInt(entry -> entry.getValue().size()));
            User mostWarned = GuildUtils.getUser(highestEntry.getKey(), guild.getGuildId(), true);
            channel.sendMessage(new EmbedBuilder().setTitle("Warning stats", null).addField("Total Warnings", String.valueOf(guild.getWarningsMap().values().stream().mapToLong(List::size).sum()), true).addField("Users warned", String.valueOf(guild.getWarningsMap().size()), true).addField("Most warned user", MessageUtils.getTag(mostWarned) + " - " + highestEntry.getValue().size() + " warnings", true).setColor(Color.CYAN).build()).queue();
        } else {
            User user = GuildUtils.getUser(args[0]);
            if (user == null) {
                MessageUtils.sendErrorMessage("That user could not be found!!", channel);
                return;
            }
            StringBuilder sb = new StringBuilder();
            List<String> tmp = guild.getUserWarnings(user);
            List<String> warnings = tmp.subList(Math.max(tmp.size() - 5, 0), tmp.size());
            int i = 1;
            for (String warning : warnings) {
                sb.append(i).append(". ").append(warning.substring(0, Math.min(725, warning.length()))).append(warning.length() > 725 ? "..." : "").append("\n");
                i++;
            }
            EmbedBuilder eb = new EmbedBuilder().setTitle("Warnings for " + user.getName()).addField("Warning count", String.valueOf(tmp.size()), true).addField("Last 5 warnings", "```md\n" + sb.toString().trim() + "\n```", false).setColor(Color.CYAN);
            channel.sendMessage(eb.build()).queue();
        }
    } else {
        MessageUtils.sendUsage(this, channel, sender, args);
    }
}
Also used : Color(java.awt.Color) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) User(net.dv8tion.jda.core.entities.User) Command(stream.flarebot.flarebot.commands.Command) Map(java.util.Map) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) Comparator(java.util.Comparator) CommandType(stream.flarebot.flarebot.commands.CommandType) Collections(java.util.Collections) GuildUtils(stream.flarebot.flarebot.util.general.GuildUtils) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) List(java.util.List) Map(java.util.Map)

Example 58 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.

the class CurrencyCommand method getCurrencyRatesEmbed.

private MessageEmbed getCurrencyRatesEmbed(User sender, CurrencyComparison c) {
    EmbedBuilder builder = MessageUtils.getEmbed(sender);
    builder.setColor(Color.CYAN).setDescription("Currency Conversion Rates").addField("From", c.getBase(), true).addField("To", c.getTo(), true).addField("Rate", ConvertCommand.DECIMAL_FORMAT.format(c.getRate()), false);
    return builder.build();
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 59 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.

the class ModlogEvents method handleChannelCreate.

private void handleChannelCreate(GuildWrapper wrapper, Channel channel) {
    if (cannotHandle(wrapper, ModlogEvent.CHANNEL_CREATE))
        return;
    AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0);
    EmbedBuilder builder = new EmbedBuilder().addField("Type", channel.getType().name().toLowerCase(), true).addField("Name", channel.getName(), true);
    if (channel.getParent() != null) {
        builder.addField("Category", channel.getParent().getName(), true);
    }
    ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_CREATE, entry.getUser(), builder);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry)

Example 60 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.

the class ModlogEvents method onGenericRoleUpdate.

private void onGenericRoleUpdate(GenericRoleUpdateEvent event, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.ROLE_EDIT))
        return;
    if (event instanceof RoleUpdatePositionEvent) {
        return;
    }
    if (event.getResponseNumber() == roleResponseNumber) {
        return;
    }
    roleResponseNumber = event.getResponseNumber();
    event.getGuild().getAuditLogs().limit(1).queue(auditLogs -> {
        AuditLogEntry entry = auditLogs.get(0);
        Map<String, AuditLogChange> changes = entry.getChanges();
        EmbedBuilder permissionsBuilder = new EmbedBuilder();
        permissionsBuilder.addField("Role", event.getRole().getName() + " (" + event.getRole().getId() + ")", true);
        if (changes.containsKey("permissions")) {
            AuditLogChange change = changes.get("permissions");
            Map<Boolean, List<Permission>> permChanges = GeneralUtils.getChanged(Permission.getPermissions(((Integer) change.getOldValue()).longValue()), Permission.getPermissions(((Integer) change.getNewValue()).longValue()));
            if (permChanges.get(true).size() > 0) {
                StringBuilder added = new StringBuilder();
                for (Permission addedPerm : permChanges.get(true)) {
                    added.append(addedPerm.getName()).append("\n");
                }
                permissionsBuilder.addField("Added Perms", "```\n" + added.toString() + "```", false);
            }
            if (permChanges.get(false).size() > 0) {
                StringBuilder removed = new StringBuilder();
                for (Permission removedPerm : permChanges.get(false)) {
                    removed.append(removedPerm.getName()).append("\n");
                }
                permissionsBuilder.addField("Removed Perms", "```\n" + removed.toString() + "```", false);
            }
        }
        if (changes.containsKey("name")) {
            AuditLogChange change = changes.get("name");
            permissionsBuilder.addField("Name Change", "`" + change.getOldValue() + "` -> `" + change.getNewValue() + "`", true);
        }
        if (changes.containsKey("mentionable")) {
            AuditLogChange change = changes.get("mentionable");
            permissionsBuilder.addField("Mentionable", "`" + change.getNewValue() + "`", true);
        }
        if (changes.containsKey("hoist")) {
            AuditLogChange change = changes.get("hoist");
            permissionsBuilder.addField("Displayed Separately", "`" + change.getNewValue() + "`", true);
        }
        if (changes.containsKey("color")) {
            AuditLogChange change = changes.get("color");
            permissionsBuilder.addField("Color Change", "`#" + Integer.toHexString(change.getOldValue()) + "` -> `#" + Integer.toHexString(change.getNewValue()) + "`", true);
        }
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.ROLE_EDIT, entry.getUser(), permissionsBuilder);
    });
}
Also used : RoleUpdatePositionEvent(net.dv8tion.jda.core.events.role.update.RoleUpdatePositionEvent) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry) AuditLogChange(net.dv8tion.jda.core.audit.AuditLogChange) Permission(net.dv8tion.jda.core.Permission) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)128 Message (net.dv8tion.jda.core.entities.Message)26 List (java.util.List)24 ArrayList (java.util.ArrayList)22 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)22 User (net.dv8tion.jda.core.entities.User)20 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)20 Collectors (java.util.stream.Collectors)19 MantaroData (net.kodehawa.mantarobot.data.MantaroData)19 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)17 Utils (net.kodehawa.mantarobot.utils.Utils)17 TimeUnit (java.util.concurrent.TimeUnit)16 Permission (net.dv8tion.jda.core.Permission)15 Subscribe (com.google.common.eventbus.Subscribe)13 Color (java.awt.Color)13 Guild (net.dv8tion.jda.core.entities.Guild)12 TextChannel (net.dv8tion.jda.core.entities.TextChannel)12 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)12 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)12 java.awt (java.awt)11