Search in sources :

Example 86 with EmbedBuilder

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

the class MessageUtils method getDefaultEmbed.

public static EmbedBuilder getDefaultEmbed(User author) {
    try {
        final Random random = new Random();
        final float hue = random.nextFloat();
        final float saturation = (random.nextInt(2000) + 1000) / 10000f;
        final float luminance = 2f;
        final Color color = Color.getHSBColor(hue, saturation, luminance);
        EmbedBuilder builder = new EmbedBuilder();
        builder.setColor(color);
        builder.setFooter("Requested by {0}".replace("{0}", author.getName() + "#" + author.getDiscriminator()), author.getAvatarUrl());
        return builder;
    } catch (Exception e) {
        new BotException(e);
        return null;
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Random(java.util.Random) BotException(tk.ardentbot.core.misc.logging.BotException) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 87 with EmbedBuilder

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

the class Music method getMusicEmbed.

private EmbedBuilder getMusicEmbed(Guild guild, User user) throws Exception {
    EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
    builder.setAuthor(WordUtils.capitalize(getName()), getShard().url, guild.getSelfMember().getUser().getAvatarUrl());
    return builder;
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 88 with EmbedBuilder

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

the class UD method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    Shard shard = GuildUtils.getShard(guild);
    if (args.length == 1) {
        sendTranslatedMessage("Search a word's definition from Urban Dictionary. Example: {0}ud test".replace("{0}", GuildUtils.getPrefix(guild)), channel, user);
    } else {
        GetRequest getRequest = Unirest.get("http://api.urbandictionary.com/v0/define?term=" + message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "").replaceAll(" ", "%20"));
        String json = "";
        try {
            json = getRequest.asJson().getBody().toString();
        } catch (UnirestException e) {
            e.printStackTrace();
        }
        UrbanDictionary definition = shard.gson.fromJson(json, UrbanDictionary.class);
        if (definition.getList().size() == 0) {
            sendTranslatedMessage("There aren't any definitions for this word!", channel, user);
        } else {
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(message.getAuthor());
            UDList list = definition.getList().get(0);
            String def = "Definition";
            String author = "Author";
            String example = "Example";
            String link = "Link";
            String thumbsUp = "Thumbs Up";
            String thumbsDown = "Thumbs Down";
            String urbanDictionary = "Urban Dictionary";
            builder.setAuthor(urbanDictionary, shard.bot.getAvatarUrl(), shard.bot.getAvatarUrl());
            builder.setThumbnail("https://i.gyazo.com/6a40e32928743e68e9006396ee7c2a14.jpg");
            builder.setColor(Color.decode("#00B7BE"));
            String definitionText = list.getDefinition();
            String exampleText = list.getExample();
            if (definitionText.length() > 1024)
                definitionText = definitionText.substring(0, 1023);
            if (exampleText.length() > 1024)
                exampleText = exampleText.substring(0, 1023);
            builder.addField(def, definitionText, true);
            builder.addField(example, exampleText, true);
            builder.addField(thumbsUp, String.valueOf(list.getThumbsUp() + ":thumbsup:"), true);
            builder.addField(thumbsDown, String.valueOf(list.getThumbsDown() + ":thumbsdown:"), true);
            builder.addField(author, list.getAuthor(), true);
            builder.addField(link, list.getPermalink(), true);
            sendEmbed(builder, channel, user);
        }
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) UDList(tk.ardentbot.core.models.UDList) GetRequest(com.mashape.unirest.request.GetRequest) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) UrbanDictionary(tk.ardentbot.core.models.UrbanDictionary) Shard(tk.ardentbot.main.Shard)

Example 89 with EmbedBuilder

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

the class Blackjack method showResults.

public void showResults(int bet, Hand yourHand, Hand dealerHand, Guild guild, MessageChannel channel, User user, Message message, String[] args) {
    try {
        EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
        builder.setAuthor("Blackjack | Game over", user.getEffectiveAvatarUrl(), user.getEffectiveAvatarUrl());
        while (dealerHand.total() < 17) dealerHand.generate();
        if (yourHand.total() > 21) {
            builder.setDescription("You busted and lost {0} :frowning:".replace("{0}", RPGUtils.formatMoney(bet)));
            Profile.get(user).removeMoney(bet);
        } else if (dealerHand.total() > 21) {
            builder.setDescription("I busted! You won {0}".replace("{0}", RPGUtils.formatMoney(bet)));
            Profile.get(user).addMoney(bet);
        } else if (dealerHand.total() == yourHand.total())
            builder.setDescription("We tied! You don't win or lose anything >.>");
        else if (dealerHand.total() < yourHand.total()) {
            builder.setDescription("You had a higher numbered hand than me! You win {0}".replace("{0}", RPGUtils.formatMoney(bet)));
            Profile.get(user).addMoney(bet);
        } else {
            builder.setDescription("I had a higher numbered hand! You lose {0}".replace("{0}", RPGUtils.formatMoney(bet)));
            Profile.get(user).removeMoney(bet);
        }
        builder.addField("Your hand", yourHand.readable(), true);
        builder.addField("My hand", dealerHand.readable(), true);
        sendEmbed(builder, channel, user);
        sessions.remove(user.getId());
    } catch (Exception e) {
        new BotException(e);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) BotException(tk.ardentbot.core.misc.logging.BotException) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 90 with EmbedBuilder

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

the class RPGMoney method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("See who has the most money - globally!", "top", "top") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length == 2) {
                HashMap<User, Double> moneyAmounts = new HashMap<>();
                Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).limit(20).run(connection);
                top.forEach(hashMap -> {
                    Profile profile = asPojo(hashMap, Profile.class);
                    assert profile.getUser() != null;
                    moneyAmounts.put(profile.getUser(), profile.getMoney());
                });
                Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
                String topMoney = "Global Richest Users";
                EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
                builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
                StringBuilder description = new StringBuilder();
                final int[] current = { 0 };
                sortedAmounts.forEach((u, money) -> {
                    if (u != null) {
                        description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
                        current[0]++;
                    }
                });
                description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
                sendEmbed(builder.setDescription(description.toString()), channel, user);
                return;
            }
            try {
                int page = Integer.parseInt(args[2]) - 1;
                HashMap<User, Double> moneyAmounts = new HashMap<>();
                Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).slice((page * 20), (page * 20) + 11).limit(25).run(connection);
                top.forEach(hashMap -> {
                    Profile profile = asPojo(hashMap, Profile.class);
                    assert profile.getUser() != null;
                    moneyAmounts.put(profile.getUser(), profile.getMoney());
                });
                Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
                String topMoney = "Global Richest Users | Page " + page;
                EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
                builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
                StringBuilder description = new StringBuilder();
                final int[] current = { 0 };
                sortedAmounts.forEach((u, money) -> {
                    if (u != null) {
                        description.append("\n#" + ((page * 20) + current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
                        current[0]++;
                    }
                });
                description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
                sendEmbed(builder.setDescription(description.toString()), channel, user);
            } catch (NumberFormatException e) {
                sendTranslatedMessage("You need to specify a valid page number!", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("See who has the most money in your server", "server", "server", "guild", "topguild") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (!generatedFirstTimeFor.contains(guild.getId())) {
                sendTranslatedMessage("Please wait a second, generating and caching your server's statistics", channel, user);
                generatedFirstTimeFor.add(guild.getId());
            }
            HashMap<User, Double> moneyAmounts = new HashMap<>();
            guild.getMembers().forEach(member -> {
                User u = member.getUser();
                moneyAmounts.put(u, Profile.get(u).getMoney());
            });
            Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor("Richest Users | This Server", getShard().url, guild.getIconUrl());
            StringBuilder description = new StringBuilder();
            description.append("**Richest Users in this Server**");
            final int[] current = { 0 };
            sortedAmounts.forEach((u, money) -> {
                if (current[0] < 10) {
                    description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
                    current[0]++;
                }
            });
            description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
            sendEmbed(builder.setDescription(description.toString()), channel, user);
        }
    });
}
Also used : MessageUtils(tk.ardentbot.utils.discord.MessageUtils) Ratelimitable(tk.ardentbot.core.executor.Ratelimitable) Subcommand(tk.ardentbot.core.executor.Subcommand) Database.r(tk.ardentbot.rethink.Database.r) HashMap(java.util.HashMap) Profile(tk.ardentbot.utils.rpg.profiles.Profile) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) List(java.util.List) Cursor(com.rethinkdb.net.Cursor) User(net.dv8tion.jda.core.entities.User) RPGUtils(tk.ardentbot.utils.rpg.RPGUtils) MapUtils(tk.ardentbot.utils.MapUtils) Database.connection(tk.ardentbot.rethink.Database.connection) Map(java.util.Map) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) HashMap(java.util.HashMap) Guild(net.dv8tion.jda.core.entities.Guild) Cursor(com.rethinkdb.net.Cursor) Profile(tk.ardentbot.utils.rpg.profiles.Profile) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) HashMap(java.util.HashMap) Map(java.util.Map)

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