Search in sources :

Example 91 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.

the class GuildInfo method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
    builder.setAuthor("Server Info", guild.getIconUrl(), guild.getIconUrl());
    builder.addField("Number of users", String.valueOf(guild.getMembers().size()), true);
    builder.addField("Online users", String.valueOf(guild.getMembers().stream().filter(m -> m.getOnlineStatus() == OnlineStatus.ONLINE).count()), true);
    builder.addField("Prefix", GuildUtils.getPrefix(guild), true);
    builder.addField("Premium Server", String.valueOf(EntityGuild.get(guild).isPremium()), true);
    builder.addField("Owner", UserUtils.getNameWithDiscriminator(guild.getOwner().getUser().getId()), true);
    builder.addField("Creation Date", guild.getCreationTime().toLocalDate().toString(), true);
    builder.addField("Public channel", guild.getPublicChannel().getAsMention(), true);
    builder.addField("# of Voice Channels", String.valueOf(guild.getVoiceChannels().size()), true);
    builder.addField("# of Text Channels", String.valueOf(guild.getTextChannels().size()), true);
    builder.addField("# of Roles", String.valueOf(guild.getRoles().size()), true);
    builder.addField("Region", guild.getRegion().getName(), true);
    builder.addField("Verification Level", String.valueOf(guild.getVerificationLevel()), true);
    sendEmbed(builder, channel, user);
}
Also used : EntityGuild(tk.ardentbot.utils.rpg.EntityGuild) Guild(net.dv8tion.jda.core.entities.Guild) GuildUtils(tk.ardentbot.utils.discord.GuildUtils) MessageUtils(tk.ardentbot.utils.discord.MessageUtils) User(net.dv8tion.jda.core.entities.User) Command(tk.ardentbot.core.executor.Command) UserUtils(tk.ardentbot.utils.discord.UserUtils) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) OnlineStatus(net.dv8tion.jda.core.OnlineStatus) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 92 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.

the class Roleinfo method getRoleInformation.

private EmbedBuilder getRoleInformation(Role role, Guild guild, User user) throws Exception {
    EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
    String title = "Role Info | Server Specific";
    builder.setAuthor(title, guild.getIconUrl(), guild.getIconUrl());
    builder.addField("Role name", role.getName(), true);
    builder.addField("# with role", String.valueOf(guild.getMembers().stream().filter(member -> {
        boolean found = false;
        for (Role r : member.getRoles()) {
            if (r.getId().equals(role.getId()))
                found = true;
        }
        return found;
    }).count()), true);
    builder.addField("Creation time", role.getCreationTime().toLocalDate().toString(), true);
    try {
        builder.addField("Hex color", "#" + Integer.toHexString(role.getColor().getRGB()).substring(2).toUpperCase(), true);
    } catch (NullPointerException npe) {
        builder.addField("Hex color", "#ffffff", true);
    }
    ArrayList<String> permissions = new ArrayList<>();
    role.getPermissions().forEach(permission -> permissions.add(permission.getName()));
    try {
        builder.addField("Permissions", MessageUtils.listWithCommas(permissions), true);
    } catch (Exception ignored) {
    }
    return builder;
}
Also used : List(java.util.List) MessageUtils(tk.ardentbot.utils.discord.MessageUtils) Command(tk.ardentbot.core.executor.Command) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList)

Example 93 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.

the class Help method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    EmbedBuilder embedBuilder = MessageUtils.getDefaultEmbed(user);
    embedBuilder.setAuthor("Ardent Help", "https://ardentbot.tk/guild", getShard().bot.getAvatarUrl());
    embedBuilder.setThumbnail("https://a.dryicons.com/images/icon_sets/polygon_icons/png/256x256/computer.png");
    StringBuilder description = new StringBuilder();
    for (Category category : Category.values()) {
        if (category == Category.NSFW) {
            if (!NSFW.csn(user, channel, guild)) {
                continue;
            }
        }
        description.append("**" + WordUtils.capitalize(category.name().toLowerCase()) + "**\n");
        ArrayList<BaseCommand> commandsInCategory = getCommandsInCategory(category);
        for (BaseCommand baseCommand : commandsInCategory) {
            description.append("`" + baseCommand.getName() + "`  ");
        }
        description.append("\n");
    }
    description.append("\nType /help [category] to view a specific category View the full help screen by typing {0}help all".replace("{0}", GuildUtils.getPrefix(guild) + args[0]));
    description.append("\n\nIf you need help, join our support guild @ https://ardentbot.tk/guild");
    embedBuilder.setDescription(description.toString());
    sendEmbed(embedBuilder, channel, user);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Category(tk.ardentbot.core.executor.Category) BaseCommand(tk.ardentbot.core.executor.BaseCommand)

Example 94 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.

the class Stats method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("See what commands are being used", "commands", "commands") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            StringBuilder commandBars = new StringBuilder();
            Map<String, Long> commandsUsed = getCommandData(ShardManager.getShards());
            final int[] counter = { 0 };
            final int[] totalCommandsReceived = { 0 };
            commandsUsed.forEach((key, value) -> {
                if (counter[0] < 7)
                    totalCommandsReceived[0] += value;
                counter[0]++;
            });
            counter[0] = 0;
            commandsUsed.forEach((key, value) -> {
                if (counter[0] < 7) {
                    int percent = (int) (value * 100 / totalCommandsReceived[0]);
                    String bar = bar(percent);
                    if (bar != null) {
                        commandBars.append(bar + " " + percent + "% **" + key + "**\n");
                    }
                }
                counter[0]++;
            });
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor("Command Statistics", getShard().url, getShard().bot.getAvatarUrl());
            builder.setColor(Color.GREEN);
            builder.setDescription("Command Usage\n" + commandBars.toString());
            sendEmbed(builder, channel, user);
        }
    });
    subcommands.add(new Subcommand("See how many server's I'm joining and leaving", "guilds") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor("Guild Statistics", getShard().url, getShard().bot.getAvatarUrl());
            builder.setColor(Color.GREEN);
            int lPH = 0;
            int lPD = 0;
            int lPS = 0;
            long epochSecond = Instant.now().getEpochSecond();
            long hBar = epochSecond - (60 * 60);
            long dBar = epochSecond - (60 * 60 * 24);
            long sBar = 0;
            for (Instant i : Leave.botLeaveEvents) {
                if (i.getEpochSecond() >= hBar)
                    lPH++;
                if (i.getEpochSecond() >= dBar)
                    lPD++;
                // Always true
                if (i.getEpochSecond() >= sBar)
                    lPS++;
            }
            int jPH = 0;
            int jPD = 0;
            int jPS = 0;
            for (Instant i : Join.botJoinEvents) {
                if (i.getEpochSecond() >= hBar)
                    jPH++;
                if (i.getEpochSecond() >= dBar)
                    jPD++;
                // Always true
                if (i.getEpochSecond() >= sBar)
                    jPS++;
            }
            builder.addField("Hourly", generateGuild(jPH, lPH), false);
            builder.addField("Daily", generateGuild(jPD, lPD), false);
            builder.addField("This Session", generateGuild(jPS, lPS), false);
            builder.addField("Guilds", String.valueOf(InternalStats.collect().getGuilds()), false);
            sendEmbed(builder, channel, user);
        }
    });
}
Also used : ShardManager(tk.ardentbot.main.ShardManager) MessageUtils(tk.ardentbot.utils.discord.MessageUtils) Join(tk.ardentbot.core.events.Join) Command(tk.ardentbot.core.executor.Command) Leave(tk.ardentbot.core.events.Leave) Subcommand(tk.ardentbot.core.executor.Subcommand) HashMap(java.util.HashMap) Instant(java.time.Instant) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Shard(tk.ardentbot.main.Shard) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) java.awt(java.awt) Guild(net.dv8tion.jda.core.entities.Guild) User(net.dv8tion.jda.core.entities.User) MapUtils(tk.ardentbot.utils.MapUtils) Map(java.util.Map) InternalStats(tk.ardentbot.utils.discord.InternalStats) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) Instant(java.time.Instant) Guild(net.dv8tion.jda.core.entities.Guild) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) HashMap(java.util.HashMap) Map(java.util.Map)

Example 95 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.

the class Iam method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("See a list of setup Iams", "view", "view") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            Shard shard = GuildUtils.getShard(guild);
            String title = "Auto Roles | /iam";
            String givesYouRole = "will give you the role";
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor(title, shard.url, shard.bot.getAvatarUrl());
            StringBuilder msg = new StringBuilder();
            msg.append("**" + title + "**");
            for (Pair<String, Role> autorole : getAutoRoles(guild)) {
                String roleName;
                Role role = autorole.getV();
                if (role == null)
                    roleName = "deleted-role";
                else
                    roleName = role.getName();
                msg.append("\n**" + autorole.getK() + "** " + givesYouRole + " **" + roleName + "**");
            }
            msg.append("\n\nAdd an autorole by doing /iam role and going through the setup wizard");
            builder.setDescription(msg.toString());
            sendEmbed(builder, channel, user);
        }
    });
    subcommands.add(new Subcommand("Give yourself an autorole", "role", "role") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length > 2) {
                String query = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + args[1] + " ", "");
                boolean found = false;
                ArrayList<Pair<String, Role>> autoroles = getAutoRoles(guild);
                for (Pair<String, Role> rolePair : autoroles) {
                    if (rolePair.getK().equalsIgnoreCase(query)) {
                        found = true;
                        Role role = rolePair.getV();
                        if (role == null)
                            sendTranslatedMessage("Hmm.. there's no role for this", channel, user);
                        else {
                            boolean failure = false;
                            try {
                                guild.getController().addRolesToMember(guild.getMember(user), role).queue();
                            } catch (Exception ex) {
                                failure = true;
                                sendTranslatedMessage("Please make sure I can add roles", channel, user);
                            }
                            if (!failure)
                                sendTranslatedMessage("Successfully gave you the role {0}".replace("{0}", role.getName()), channel, user);
                        }
                    }
                }
                if (!found)
                    sendTranslatedMessage("An autorole with that name wasn't found", channel, user);
            } else
                sendTranslatedMessage("You need to include an autorole name", channel, user);
        }
    });
    subcommands.add(new Subcommand("Remove autoroles", "remove", "remove") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (UserUtils.hasManageServerOrStaff(guild.getMember(user))) {
                String query = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + args[1] + " ", "");
                boolean found = false;
                ArrayList<Pair<String, Role>> autoroles = getAutoRoles(guild);
                for (Pair<String, Role> rolePair : autoroles) {
                    if (rolePair.getK().equalsIgnoreCase(query)) {
                        found = true;
                        r.db("data").table("autoroles").filter(row -> row.g("name").eq(query).and(row.g("guild_id").eq(guild.getId()))).delete().run(connection);
                        sendTranslatedMessage("Deleted the autorole **{0}**".replace("{0}", rolePair.getK()), channel, user);
                    }
                }
                if (!found)
                    sendTranslatedMessage("An autorole with that name wasn't found", channel, user);
            } else
                sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
        }
    });
    subcommands.add(new Subcommand("Add an autorole", "add", "add") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
            if (UserUtils.hasManageServerOrStaff(guild.getMember(user))) {
                sendTranslatedMessage("Type the name of the autorole you want to add", channel, user);
                interactiveOperation(channel, message, nameMessage -> {
                    String name = nameMessage.getContent();
                    sendTranslatedMessage("Type the name of the **discord role** you want this set to", channel, user);
                    interactiveOperation(channel, message, roleMessage -> {
                        try {
                            String role = roleMessage.getRawContent();
                            boolean found = false;
                            ArrayList<Pair<String, Role>> autoroles = getAutoRoles(guild);
                            for (Pair<String, Role> rolePair : autoroles) {
                                if (rolePair.getK().equalsIgnoreCase(name)) {
                                    found = true;
                                }
                            }
                            if (found)
                                sendTranslatedMessage("An autorole with that name is already setup", channel, user);
                            else {
                                List<Role> roleList = guild.getRolesByName(role, true);
                                if (roleList.size() > 0) {
                                    Role toAdd = roleList.get(0);
                                    r.table("autoroles").insert(r.json(gson.toJson(new AutoroleModel(guild.getId(), name, toAdd.getId())))).run(connection);
                                    sendTranslatedMessage("Successfully added autorole **{0}** which gives the role **{1}**".replace("{0}", name).replace("{1}", role), channel, user);
                                } else
                                    sendTranslatedMessage("An role with that name wasn't found", channel, user);
                            }
                        } catch (Exception e) {
                            new BotException(e);
                        }
                    });
                });
            } else
                sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
        }
    });
}
Also used : MessageUtils(tk.ardentbot.utils.discord.MessageUtils) Command(tk.ardentbot.core.executor.Command) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) UserUtils(tk.ardentbot.utils.discord.UserUtils) Subcommand(tk.ardentbot.core.executor.Subcommand) Database.r(tk.ardentbot.rethink.Database.r) HashMap(java.util.HashMap) BotException(tk.ardentbot.core.misc.logging.BotException) Shard(tk.ardentbot.main.Shard) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) GuildUtils(tk.ardentbot.utils.discord.GuildUtils) List(java.util.List) Cursor(com.rethinkdb.net.Cursor) Database.connection(tk.ardentbot.rethink.Database.connection) AutoroleModel(tk.ardentbot.rethink.models.AutoroleModel) Pair(tk.ardentbot.utils.javaAdditions.Pair) Subcommand(tk.ardentbot.core.executor.Subcommand) ArrayList(java.util.ArrayList) BotException(tk.ardentbot.core.misc.logging.BotException) AutoroleModel(tk.ardentbot.rethink.models.AutoroleModel) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) BotException(tk.ardentbot.core.misc.logging.BotException) ArrayList(java.util.ArrayList) List(java.util.List) Shard(tk.ardentbot.main.Shard) Pair(tk.ardentbot.utils.javaAdditions.Pair)

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