Search in sources :

Example 51 with EmbedBuilder

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

the class ServerInfoCommand method sendGuildInfo.

private void sendGuildInfo(Guild guild, TextChannel channel) {
    EmbedBuilder eb = new EmbedBuilder();
    eb.setTitle(guild.getName());
    eb.setThumbnail(guild.getIconUrl());
    eb.addField("Users", "**Total:** " + guild.getMembers().size() + "\n" + "\n" + "**Online:** " + guild.getMembers().stream().filter(member -> !member.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count() + "\n" + "\n" + "**Owner:** " + MessageUtils.getTag(guild.getOwner().getUser()), true);
    String afk = guild.getAfkChannel() == null ? "" : "**AFK:**\n" + "Channel: " + guild.getAfkChannel().getName() + "\n" + "\n" + "Timeout: " + FormatUtils.formatTime(guild.getAfkTimeout().getSeconds(), TimeUnit.SECONDS, true, false);
    eb.addField("Channels", "**Text**\n" + "Total: " + guild.getTextChannels().size() + "\n" + "\n" + "**Voice**\n" + "Total: " + guild.getVoiceChannels().size() + "\n" + "\n" + "Active: " + guild.getVoiceChannels().stream().filter(voiceChannel -> voiceChannel.getMembers().size() > 0).count() + "\n" + "\n" + afk, true);
    eb.addField("Misc info", "**Creation time:** " + guild.getCreationTime().toLocalDateTime().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " UTC\n" + "\n" + "**Roles:** " + guild.getRoles().size() + "\n" + "\n" + "**Server region:** " + guild.getRegion().getName() + "\n" + "\n" + "**Verification Level:** " + GeneralUtils.getVerificationString(guild.getVerificationLevel()), true);
    eb.setFooter("ID: " + guild.getId(), null);
    eb.setColor(Color.CYAN);
    channel.sendMessage(eb.build()).queue();
}
Also used : Color(java.awt.Color) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GeneralUtils(stream.flarebot.flarebot.util.general.GeneralUtils) Getters(stream.flarebot.flarebot.Getters) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) OnlineStatus(net.dv8tion.jda.core.OnlineStatus) TimeUnit(java.util.concurrent.TimeUnit) FormatUtils(stream.flarebot.flarebot.util.general.FormatUtils) Permission(stream.flarebot.flarebot.permissions.Permission) Command(stream.flarebot.flarebot.commands.Command) DateTimeFormatter(java.time.format.DateTimeFormatter) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) ZoneOffset(java.time.ZoneOffset) CommandType(stream.flarebot.flarebot.commands.CommandType) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 52 with EmbedBuilder

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

the class QueryCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    try {
        CassandraController.runUnsafeTask(conn -> {
            ResultSet set = conn.execute(MessageUtils.getMessage(args, 0));
            List<String> header = new ArrayList<>();
            List<List<String>> table = new ArrayList<>();
            int columnsCount = set.getColumnDefinitions().size();
            for (int i = 0; i < columnsCount; i++) {
                header.add(set.getColumnDefinitions().getName(i));
            }
            for (Row setRow : set) {
                List<String> row = new ArrayList<>();
                for (int i = 0; i < columnsCount; i++) {
                    String value = setRow.getObject(i).toString();
                    row.add(value.substring(0, Math.min(30, value.length())));
                }
                table.add(row);
            }
            String output = MessageUtils.makeAsciiTable(header, table, null);
            if (output.length() < 2000) {
                channel.sendMessage(output).queue();
            } else {
                MessageUtils.sendErrorMessage("The query result set was very large, it has been posted to paste [here](" + MessageUtils.paste(output) + ")", channel, sender);
            }
        });
    } catch (QueryExecutionException | QueryValidationException e) {
        EmbedBuilder eb = new EmbedBuilder();
        eb.setTitle("Failed to execute query");
        eb.addField("Error", "```\n" + e.getMessage() + "\n```", false);
        channel.sendMessage(eb.build()).queue();
    }
}
Also used : QueryExecutionException(com.datastax.driver.core.exceptions.QueryExecutionException) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) QueryValidationException(com.datastax.driver.core.exceptions.QueryValidationException) ResultSet(com.datastax.driver.core.ResultSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Row(com.datastax.driver.core.Row)

Example 53 with EmbedBuilder

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

the class PostUpdateCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message msg, String[] args, Member member) {
    if (guild.getGuildId().equals("226785954537406464") && PerGuildPermissions.isStaff(sender)) {
        if (args.length == 0) {
            channel.sendMessage("You kinda need like.... a message to announce... like yeah...").queue();
            return;
        }
        Role r = guild.getGuild().getRoleById(320304080926801922L);
        r.getManager().setMentionable(true).queue(aVoid -> {
            if (args[0].startsWith("pr:")) {
                channel.sendMessage(new MessageBuilder().setEmbed(GitHubUtils.getEmbedForPR(args[0].substring(3)).build()).append(r.getAsMention()).build()).queue(bVoid -> channel.sendMessage("make sure to report any bugs over to be <#242206261767176192> channel " + "and if you need any support we're happy to help over in the <#226786463440699392> " + "channel!").queue());
            } else {
                String message = msg.getContentRaw();
                message = message.substring(message.indexOf(" ") + 1);
                channel.sendMessage(new MessageBuilder().setContent(r.getAsMention()).setEmbed(new EmbedBuilder().setTitle("Some announcement thing!").setDescription(message).setFooter("Announcement by " + member.getEffectiveName(), sender.getEffectiveAvatarUrl()).build()).build()).complete();
            }
        });
        r.getManager().setMentionable(false).queue();
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageBuilder(net.dv8tion.jda.core.MessageBuilder)

Example 54 with EmbedBuilder

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

the class PlaylistsCommand 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("mark")) {
            if (getPermissions(channel).isCreator(sender)) {
                if (args.length == 1 || args.length == 2) {
                    MessageUtils.sendUsage(this, channel, sender, args);
                } else {
                    String playlist = MessageUtils.getMessage(args, 2);
                    CassandraController.runTask(session -> {
                        ResultSet set = session.execute(session.prepare("SELECT playlist_name FROM flarebot.playlist WHERE " + "guild_id = ? AND playlist_name = ?").bind().setString(0, channel.getGuild().getId()).setString(1, playlist));
                        if (set.one() != null) {
                            if (args[1].equalsIgnoreCase("global") || args[1].equalsIgnoreCase("local")) {
                                session.execute(session.prepare("UPDATE flarebot.playlist SET " + "scope = ? WHERE guild_id = ? AND playlist_name = ?").bind().setString(0, args[1].toLowerCase()).setString(1, channel.getGuild().getId()).setString(2, playlist));
                                channel.sendMessage(MessageUtils.getEmbed().setDescription("Changed the scope of '" + playlist + "' to " + args[1].toLowerCase()).build()).queue();
                            } else {
                                MessageUtils.sendErrorMessage("Invalid scope! Scopes are local and global!", channel);
                            }
                        } else {
                            MessageUtils.sendErrorMessage("That playlist could not be found!", channel);
                        }
                    });
                }
            }
        }
    } else {
        channel.sendTyping().complete();
        CassandraController.runTask(session -> {
            ResultSet set = session.execute("SELECT playlist_name, scope FROM flarebot.playlist WHERE " + "scope = 'global' ALLOW FILTERING");
            ArrayList<Row> tmp = new ArrayList<>(set.all());
            set = session.execute("SELECT playlist_name, scope FROM flarebot.playlist WHERE " + "guild_id = '" + channel.getGuild().getId() + "' AND scope = 'local' ALLOW FILTERING");
            tmp.addAll(set.all());
            StringBuilder sb = new StringBuilder();
            StringBuilder globalSb = new StringBuilder();
            List<String> songs = new ArrayList<>();
            int i = 1;
            boolean loopingGlobal = true;
            Iterator<Row> rows = tmp.iterator();
            while (rows.hasNext() && songs.size() < 25) {
                Row row = rows.next();
                String toAppend;
                if (row.getString("scope").equalsIgnoreCase("global")) {
                    toAppend = String.format("%s. %s\n", i++, MessageUtils.escapeMarkdown(row.getString("playlist_name")));
                    globalSb.append(toAppend);
                } else {
                    if (loopingGlobal) {
                        loopingGlobal = false;
                        i = 1;
                    }
                    toAppend = String.format("%s. %s\n", i++, MessageUtils.escapeMarkdown(row.getString("playlist_name")));
                    if (sb.length() + toAppend.length() > 1024) {
                        songs.add(sb.toString());
                        sb = new StringBuilder();
                    }
                    sb.append(toAppend);
                }
            }
            songs.add(sb.toString());
            EmbedBuilder builder = MessageUtils.getEmbed(sender);
            i = 1;
            builder.addField("Global Playlists", (globalSb.toString().isEmpty() ? "No global playlists!" : globalSb.toString()), false);
            for (String s : songs) {
                builder.addField("Page " + i++, s.isEmpty() ? "**No playlists!**" : s, false);
            }
            channel.sendMessage(builder.build()).queue();
        });
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ResultSet(com.datastax.driver.core.ResultSet) ArrayList(java.util.ArrayList) Row(com.datastax.driver.core.Row)

Example 55 with EmbedBuilder

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

the class RepeatCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    Player player = FlareBot.instance().getMusicManager().getPlayer(channel.getGuild().getId());
    if (player.getPlayingTrack() == null) {
        MessageUtils.sendErrorMessage("Can't repeat when their is no song to repeat!", channel);
    } else {
        Queue<Track> queue = new ConcurrentLinkedQueue<>();
        queue.add(player.getPlayingTrack().makeClone());
        queue.addAll(player.getPlaylist());
        player.getPlaylist().clear();
        player.getPlaylist().addAll(queue);
        channel.sendMessage(new EmbedBuilder().setColor(Color.green).setDescription("The player will now repeat the current track!").build()).queue();
    }
}
Also used : Player(com.arsenarsen.lavaplayerbridge.player.Player) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Track(com.arsenarsen.lavaplayerbridge.player.Track)

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