Search in sources :

Example 11 with Profile

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

the class Bet method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("Bet a specified amount of money", "start", "start") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length == 2) {
                sendTranslatedMessage("You need to specify a bet amount", channel, user);
                return;
            }
            try {
                double amountToBet = Double.parseDouble(args[2]);
                Profile profile = Profile.get(user);
                if (amountToBet <= 0 || profile.getMoney() < amountToBet) {
                    sendTranslatedMessage("Invalid amount - either it was more than what you have or less than $0", channel, user);
                    return;
                }
                sendEditedTranslation("Are you sure you want to bet **{0}**? Type **yes** if so, or **no** to cancel", user, channel, RPGUtils.formatMoney(amountToBet));
                interactiveOperation(channel, message, (returnedMessage) -> {
                    if (returnedMessage.getContent().equalsIgnoreCase("yes")) {
                        sendTranslatedMessage("Type 1 or 2 below - choose wisely!", channel, user);
                        interactiveOperation(channel, message, (numberInput) -> {
                            try {
                                int num = Integer.parseInt(numberInput.getContent());
                                if (num > 0 && num <= 2) {
                                    int generated = new SecureRandom().nextInt(2) + 1;
                                    if (num == generated || new Random().nextInt(20) == 5) {
                                        profile.addMoney(profile.afterCredit(amountToBet));
                                        sendTranslatedMessage("Congrats! You won " + RPGUtils.formatMoney(profile.afterCredit(amountToBet)), channel, user);
                                    } else {
                                        sendTranslatedMessage("Sorry, you lost " + RPGUtils.formatMoney(amountToBet) + " :frowning: " + "The correct answer " + "was " + generated, channel, user);
                                        profile.removeMoney(amountToBet);
                                    }
                                } else
                                    sendTranslatedMessage("You specified an invalid number", channel, user);
                            } catch (Exception ex) {
                                sendTranslatedMessage("You specified an invalid number", channel, user);
                            }
                        });
                    } else {
                        sendTranslatedMessage("Ok, cancelled your bet", channel, user);
                    }
                });
            } catch (NumberFormatException e) {
                sendTranslatedMessage("That's not a number!", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("Bet all your money", "all", "all") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            Profile profile = Profile.get(user);
            if (profile.getMoney() < 0) {
                sendTranslatedMessage("You can't bet if you're in debt!", channel, user);
                return;
            }
            sendEditedTranslation("Are you sure you want to bet all? Type **yes** if so, or **no** to cancel", user, channel, RPGUtils.formatMoney(profile.getMoney()));
            interactiveOperation(channel, message, (returnedMessage) -> {
                if (returnedMessage.getContent().equalsIgnoreCase("yes")) {
                    sendTranslatedMessage("Type 1 or 2 below - choose wisely!", channel, user);
                    interactiveOperation(channel, message, (numberInput) -> {
                        try {
                            int num = Integer.parseInt(numberInput.getContent());
                            if (num > 0 && num <= 2) {
                                int generated = new SecureRandom().nextInt(2) + 1;
                                if (num == generated || new Random().nextInt(20) == 5) {
                                    profile.addMoney(profile.afterCredit(profile.getMoney()));
                                    sendTranslatedMessage("Congrats! You won " + RPGUtils.formatMoney(profile.afterCredit(profile.getMoney())), channel, user);
                                } else {
                                    sendTranslatedMessage("Sorry, you lost " + RPGUtils.formatMoney(profile.getMoney()) + " :frowning: The correct answer " + "was " + generated, channel, user);
                                    profile.setZero();
                                }
                            } else
                                sendTranslatedMessage("You specified an invalid number", channel, user);
                        } catch (Exception ex) {
                            sendTranslatedMessage("You specified an invalid number", channel, user);
                        }
                    });
                } else {
                    sendTranslatedMessage("Ok, cancelled your bet", channel, user);
                }
            });
        }
    });
}
Also used : SecureRandom(java.security.SecureRandom) Guild(net.dv8tion.jda.core.entities.Guild) User(net.dv8tion.jda.core.entities.User) RPGUtils(tk.ardentbot.utils.rpg.RPGUtils) Command(tk.ardentbot.core.executor.Command) Subcommand(tk.ardentbot.core.executor.Subcommand) Random(java.util.Random) Profile(tk.ardentbot.utils.rpg.profiles.Profile) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) SecureRandom(java.security.SecureRandom) Guild(net.dv8tion.jda.core.entities.Guild) Profile(tk.ardentbot.utils.rpg.profiles.Profile) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) SecureRandom(java.security.SecureRandom) Random(java.util.Random)

Example 12 with Profile

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

the class UserUtils method hasTierOnePermissions.

public static boolean hasTierOnePermissions(User user) {
    String id = user.getId();
    boolean normalPermissions = isStaff(user) || tierOnepatrons.contains(id) || tierTwopatrons.contains(id) || tierThreepatrons.contains(id);
    if (!normalPermissions) {
        Profile profile = Profile.get(user);
        for (Badge badge : profile.getBadges()) {
            if (BadgesList.from(badge.getId()).getId().equalsIgnoreCase(BadgesList.PREMIUM_TRIAL.getId())) {
                return true;
            }
        }
        return false;
    } else
        return true;
}
Also used : Badge(tk.ardentbot.utils.rpg.profiles.Badge) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

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