Search in sources :

Example 31 with EmbedBuilder

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

the class Blackjack method dispatchRound.

public void dispatchRound(int bet, Hand yourHand, Hand dealerHand, Guild guild, MessageChannel channel, User user, Message message, String[] args) {
    EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
    builder.setAuthor("Blackjack | " + user.getName(), user.getEffectiveAvatarUrl(), user.getEffectiveAvatarUrl());
    builder.setDescription("Type `hit` to get another card, `stay` to stay with your current cards, or `cancel` to cancel the game " + "(you " + "will lose 50% of your original bet)");
    builder.addField("Your hand", yourHand.readable(), true);
    builder.addField("My hand", dealerHand.readable(), true);
    sendEmbed(builder, channel, user);
    boolean success = longInteractiveOperation(channel, message, 25, actionMessage -> {
        String content = actionMessage.getContent();
        if (content.equalsIgnoreCase("hit")) {
            yourHand.generate();
            if (yourHand.total() > 21) {
                showResults(bet, yourHand, dealerHand, guild, channel, user, message, args);
            } else
                dispatchRound(bet, yourHand, dealerHand, guild, channel, user, message, args);
        } else if (content.equalsIgnoreCase("stay")) {
            showResults(bet, yourHand, dealerHand, guild, channel, user, message, args);
        } else if (content.equalsIgnoreCase("cancel")) {
            sendTranslatedMessage("Cancelled game, but you lost 50% of your original bet", channel, user);
            sessions.remove(user.getId());
            Profile.get(user).removeMoney(bet / 2);
        } else {
            sendTranslatedMessage("Invalid input! Restarting your round... type `cancel` if you want to cancel this game", channel, user);
            dispatchRound(bet, yourHand, dealerHand, guild, channel, user, message, args);
        }
    });
    if (!success)
        sessions.remove(user.getId());
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 32 with EmbedBuilder

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

the class Whois method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] arg) throws Exception {
    Shard shard = GuildUtils.getShard(guild);
    Member member;
    List<User> mentionedUsers = message.getMentionedUsers();
    if (mentionedUsers.size() > 0) {
        member = guild.getMember(mentionedUsers.get(0));
    } else
        member = guild.getMember(user);
    List<Role> rolesList = member.getRoles();
    String nick;
    if (member.getNickname() == null)
        nick = "None";
    else
        nick = member.getNickname();
    long digTemp = Instant.now().atOffset(ZoneOffset.UTC).toEpochSecond() - member.getJoinDate().toInstant().atOffset(ZoneOffset.UTC).toEpochSecond();
    long daysInGuild = Math.round(digTemp / (60 * 60 * 24));
    if (daysInGuild == 0)
        daysInGuild = 1;
    StringBuilder roles = new StringBuilder();
    for (int i = 0; i < rolesList.size(); i++) {
        if (i == 0)
            roles.append(rolesList.get(0).getName());
        else
            roles.append(", " + rolesList.get(i).getName());
    }
    EmbedBuilder builder = MessageUtils.getDefaultEmbed(message.getAuthor());
    builder.setAuthor("Information About {0}".replace("{0}", member.getUser().getName()), "https://ardentbot.tk/guild", shard.bot.getAvatarUrl());
    builder.setThumbnail(member.getUser().getAvatarUrl());
    builder.addField("Discord Name", member.getUser().getName(), true);
    builder.addField("Nickname", nick, true);
    builder.addField("Discriminator", "#" + member.getUser().getDiscriminator(), true);
    builder.addField("Server Join Date", member.getJoinDate().toLocalDate().toString(), true);
    builder.addField("Days in Server", String.valueOf(daysInGuild), true);
    builder.addField("Roles", roles.toString(), true);
    builder.addField("Discord Join Date", member.getUser().getCreationTime().toLocalDate().toString(), true);
    sendEmbed(builder, channel, user);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Shard(tk.ardentbot.main.Shard)

Example 33 with EmbedBuilder

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

the class Help method setupSubcommands.

@Override
public void setupSubcommands() {
    all = new Subcommand("See the traditional help screen", "all", "all") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            EmbedBuilder helpEmbed = MessageUtils.getDefaultEmbed(user);
            helpEmbed.setAuthor("Ardent Help", "https://ardentbot.tk/guild", getShard().bot.getAvatarUrl());
            helpEmbed.setThumbnail("https://a.dryicons.com/images/icon_sets/polygon_icons/png/256x256/computer" + ".png");
            StringBuilder description = new StringBuilder();
            description.append("Command Categories\n");
            for (Category category : Category.values()) {
                description.append(" > **" + category.name().toLowerCase() + "**\n");
            }
            description.append("\nType /help [category] to view a specific category\n\nIf you need help, join our support guild: " + "https://ardentbot.tk/guild");
            helpEmbed.setDescription(description.toString());
            sendEmbed(helpEmbed, channel, user);
        }
    };
    subcommands.add(all);
    for (Category category : Category.values()) {
        subcommands.add(new Subcommand("how tf did you see this", Category.getName(category), Category.getName(category)) {

            @Override
            public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
                EmbedBuilder embedBuilder = MessageUtils.getDefaultEmbed(user);
                embedBuilder.setAuthor("Commands in Category ".replace("{0}", WordUtils.capitalize(category.name().toLowerCase())), "https://ardentbot.tk/guild", getShard().bot.getAvatarUrl());
                ArrayList<BaseCommand> commandsInCategory = Help.this.getCommandsInCategory(category);
                StringBuilder description = new StringBuilder();
                for (BaseCommand baseCommand : commandsInCategory) {
                    description.append(" > **" + baseCommand.getName() + "**: " + baseCommand.getDescription() + "\n");
                }
                embedBuilder.setDescription(description.toString());
                sendEmbed(embedBuilder, channel, user);
            }
        });
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) Category(tk.ardentbot.core.executor.Category) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) BaseCommand(tk.ardentbot.core.executor.BaseCommand) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel)

Example 34 with EmbedBuilder

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

the class Restrict method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("Prevent a user from using Ardent commands", "block @User", "block") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            Member member = guild.getMember(user);
            if (member.hasPermission(Permission.MANAGE_SERVER)) {
                List<User> mentionedUsers = message.getMentionedUsers();
                if (mentionedUsers.size() > 0) {
                    for (User mentioned : mentionedUsers) {
                        Member mentionedMember = guild.getMember(mentioned);
                        if (mentionedMember.hasPermission(member.getPermissions()) || mentionedMember.hasPermission(Permission.MANAGE_SERVER) || mentionedMember.getUser().getId().equalsIgnoreCase(guild.getSelfMember().getUser().getId())) {
                            sendTranslatedMessage("You cannot modify this user because they have the same or higher permissions than " + "you.", channel, user);
                            return;
                        }
                        EntityGuild entityGuild = EntityGuild.get(guild);
                        boolean isRestricted = entityGuild.isRestricted(mentioned);
                        if (isRestricted) {
                            sendTranslatedMessage("This user has already been blocked from using commands!", channel, user);
                        } else {
                            RestrictedUser restrictedUser = new RestrictedUser(mentioned.getId(), user.getId(), guild);
                            entityGuild.addRestricted(restrictedUser);
                            r.db("data").table("restricted").insert(r.json(gson.toJson(new RestrictedUserModel(guild.getId(), mentioned.getId(), user.getId())))).run(connection);
                            sendEditedTranslation("{1} has blocked {0} from sending commands", user, channel, mentioned.getName(), user.getName());
                        }
                    }
                } else
                    sendTranslatedMessage("You need to mention one or more users", channel, user);
            } else
                sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
        }
    });
    subcommands.add(new Subcommand("Allow a blocked user to run Ardent commands again", "unblock @User", "unblock") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
                List<User> mentionedUsers = message.getMentionedUsers();
                if (mentionedUsers.size() > 0) {
                    for (User mentioned : mentionedUsers) {
                        EntityGuild entityGuild = EntityGuild.get(guild);
                        boolean isRestricted = entityGuild.isRestricted(mentioned);
                        if (!isRestricted) {
                            sendEditedTranslation("{0} isn't restricted from sending commands!", user, channel, mentioned.getName());
                        } else {
                            entityGuild.removeRestricted(mentioned.getId());
                            r.db("data").table("restricted").filter(row -> row.g("user_id").eq(mentioned.getId()).and(row.g("guild_id").eq(guild.getId()))).delete().run(connection);
                            sendEditedTranslation("{0} unrestricted {1}, allowing them to use commands again", user, channel, mentioned.getName(), user.getName());
                        }
                    }
                } else
                    sendTranslatedMessage("You need to mention one or more users", channel, user);
            } else
                sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
        }
    });
    subcommands.add(new Subcommand("View all the users who have been blocked in your server", "view") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            EntityGuild entityGuild = EntityGuild.get(guild);
            ArrayList<RestrictedUser> restrictedUsers = entityGuild.getRestrictedUsers();
            String title = "Restricted users";
            String restrictedBy = "restricted by";
            StringBuilder response = new StringBuilder();
            response.append("**" + title + "**");
            if (restrictedUsers.size() == 0) {
                response.append("\nNo one");
            } else {
                restrictedUsers.forEach(restrictedUser -> response.append("\n - " + guild.getMemberById(restrictedUser.getUserId()).getUser().getName() + ", " + restrictedBy + " " + guild.getMemberById(restrictedUser.getRestrictedById()).getUser().getName()));
            }
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor(title, getShard().url, guild.getSelfMember().getUser().getAvatarUrl());
            builder.setDescription(response.toString());
            sendEmbed(builder, 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) Subcommand(tk.ardentbot.core.executor.Subcommand) RestrictedUserModel(tk.ardentbot.rethink.models.RestrictedUserModel) RestrictedUser(tk.ardentbot.utils.models.RestrictedUser) Database.r(tk.ardentbot.rethink.Database.r) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) EntityGuild(tk.ardentbot.utils.rpg.EntityGuild) List(java.util.List) Permission(net.dv8tion.jda.core.Permission) Database.connection(tk.ardentbot.rethink.Database.connection) RestrictedUser(tk.ardentbot.utils.models.RestrictedUser) Subcommand(tk.ardentbot.core.executor.Subcommand) ArrayList(java.util.ArrayList) EntityGuild(tk.ardentbot.utils.rpg.EntityGuild) EntityGuild(tk.ardentbot.utils.rpg.EntityGuild) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) List(java.util.List) RestrictedUserModel(tk.ardentbot.rethink.models.RestrictedUserModel) RestrictedUser(tk.ardentbot.utils.models.RestrictedUser)

Example 35 with EmbedBuilder

use of net.dv8tion.jda.core.EmbedBuilder in project DiscordBot by LXGaming.

the class ClearCommand method execute.

@Override
public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) {
    DiscordBot.getInstance().getDiscord().getAudioQueue().setRepeatQueue(false);
    DiscordBot.getInstance().getDiscord().getAudioQueue().setRepeatSong(false);
    DiscordBot.getInstance().getDiscord().getAudioQueue().getQueue().clear();
    DiscordBot.getInstance().getDiscord().getAudioPlayer().stopTrack();
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl());
    embedBuilder.setColor(DiscordUtil.DEFAULT);
    embedBuilder.setTitle("Queue cleared.", null);
    DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Aggregations

EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)73 Message (net.dv8tion.jda.core.entities.Message)15 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)13 ArrayList (java.util.ArrayList)12 Guild (net.dv8tion.jda.core.entities.Guild)11 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)11 MantaroData (net.kodehawa.mantarobot.data.MantaroData)11 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)11 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)11 Color (java.awt.Color)10 User (net.dv8tion.jda.core.entities.User)10 Command (net.kodehawa.mantarobot.modules.Command)10 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)10 TimeUnit (java.util.concurrent.TimeUnit)9 Utils (net.kodehawa.mantarobot.utils.Utils)9 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)8 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)8 Module (net.kodehawa.mantarobot.modules.Module)8