Search in sources :

Example 6 with Profile

use of tk.ardentbot.utils.rpg.profiles.Profile in project Ardent by adamint.

the class UserProfile method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    User toGet;
    List<User> mentionedUsers = message.getMentionedUsers();
    if (mentionedUsers.size() == 0)
        toGet = user;
    else
        toGet = mentionedUsers.get(0);
    Profile profile = Profile.get(toGet);
    EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
    builder.setAuthor("{0}'s profile".replace("{0}", toGet.getName()), getShard().url, toGet.getAvatarUrl());
    Marriage marriage = Marry.getMarriage(toGet);
    if (marriage == null)
        builder.addField("Married to", "No one :(", true);
    else {
        builder.addField("Married to", UserUtils.getNameWithDiscriminator(marriage.getUser_one().equals(toGet.getId()) ? marriage.getUser_two() : marriage.getUser_one()), true);
    }
    builder.addField("Balance", RPGUtils.formatMoney(profile.getMoney()), true);
    builder.addField("Items", "Coming soon!", true);
    sendEmbed(builder, channel, user);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) Marriage(tk.ardentbot.rethink.models.Marriage) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

Example 7 with Profile

use of tk.ardentbot.utils.rpg.profiles.Profile in project Ardent by adamint.

the class Daily method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    Profile profile = Profile.get(user);
    if (profile.canCollect()) {
        Random rand = new Random();
        int random = rand.nextInt(1000);
        profile.addMoney(random);
        sendTranslatedMessage("Your daily bonus was **$" + random + "**, you can use this again in 24 hours!", channel, user);
        profile.setCollected();
    } else {
        sendTranslatedMessage(profile.getCollectionTime(), channel, user);
    }
}
Also used : Random(java.util.Random) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

Example 8 with Profile

use of tk.ardentbot.utils.rpg.profiles.Profile in project Ardent by adamint.

the class Blackjack method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (sessions.contains(user.getId()))
        return;
    sendTranslatedMessage("Enter an amount to bet", channel, user);
    interactiveOperation(channel, message, betMessage -> {
        try {
            int amountToBet = Integer.parseInt(betMessage.getContent());
            Profile profile = Profile.get(user);
            if (amountToBet <= 0 || profile.getMoney() < amountToBet) {
                sendTranslatedMessage("You entered an invalid amount of money", channel, user);
                return;
            } else if (amountToBet > 5000) {
                sendTranslatedMessage("The max bet is **$5,000**!", channel, user);
                return;
            }
            Hand yourHand = new Hand().generate().generate();
            Hand dealerHand = new Hand().generate().generate();
            sessions.add(user.getId());
            dispatchRound(amountToBet, yourHand, dealerHand, guild, channel, user, message, args);
        } catch (Exception e) {
            sendTranslatedMessage("You need to enter a whole number. Cancelling...", channel, user);
        }
    });
}
Also used : Hand(tk.ardentbot.utils.games.Hand) Profile(tk.ardentbot.utils.rpg.profiles.Profile) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 9 with Profile

use of tk.ardentbot.utils.rpg.profiles.Profile in project Ardent by adamint.

the class Pay method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    String[] raw = message.getRawContent().split(" ");
    if (raw.length == 3) {
        List<User> mentionedUsers = message.getMentionedUsers();
        if (mentionedUsers.size() > 0) {
            User mentioned = mentionedUsers.get(0);
            if (mentioned.getId().equalsIgnoreCase(user.getId()) || mentioned.getId().equalsIgnoreCase(guild.getSelfMember().getUser().getId())) {
                sendTranslatedMessage("You can't pay yourself or me, lol", channel, user);
                return;
            }
            try {
                double amount = Double.parseDouble(raw[2]);
                Profile profile = Profile.get(user);
                if (amount <= 0 || profile.getMoney() < amount) {
                    sendTranslatedMessage("You don't have enough money to do this!", channel, user);
                    return;
                }
                Profile.get(mentioned).addMoney(amount);
                profile.removeMoney(amount);
                sendEditedTranslation("**{0}** paid **{1}** {2}", user, channel, user.getName(), mentioned.getName(), RPGUtils.formatMoney(amount));
            } catch (NumberFormatException ex) {
                sendTranslatedMessage("That's not a number!", channel, user);
            }
        } else
            sendTranslatedMessage("You need to mention a user", channel, user);
    } else {
        sendTranslatedMessage("Use /pay @User [amount]", channel, user);
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

Example 10 with Profile

use of tk.ardentbot.utils.rpg.profiles.Profile 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

Profile (tk.ardentbot.utils.rpg.profiles.Profile)12 User (net.dv8tion.jda.core.entities.User)6 Badge (tk.ardentbot.utils.rpg.profiles.Badge)4 HashMap (java.util.HashMap)3 Guild (net.dv8tion.jda.core.entities.Guild)3 SecureRandom (java.security.SecureRandom)2 Map (java.util.Map)2 Random (java.util.Random)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 Message (net.dv8tion.jda.core.entities.Message)2 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)2 Subcommand (tk.ardentbot.core.executor.Subcommand)2 Marriage (tk.ardentbot.rethink.models.Marriage)2 RPGUtils (tk.ardentbot.utils.rpg.RPGUtils)2 Cursor (com.rethinkdb.net.Cursor)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 Command (tk.ardentbot.core.executor.Command)1 Ratelimitable (tk.ardentbot.core.executor.Ratelimitable)1