Search in sources :

Example 1 with Profile

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

the class Divorce method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    Marriage marriage = Marry.getMarriage(user);
    if (marriage == null)
        sendTranslatedMessage("You're not married!", channel, user);
    else {
        sendTranslatedMessage("Are you sure you want to divorce this person? There's a 50% chance that half of your assets will be " + "transferred to them. Respond **yes** if you want to go through with the divorce, or **no** if not.", channel, user);
        interactiveOperation(channel, message, responseMessage -> {
            if (responseMessage.getContent().equalsIgnoreCase("yes")) {
                r.db("data").table("marriages").filter(row -> row.g("user_one").eq(user.getId()).or(row.g("user_two").eq(user.getId()))).delete().run(connection);
                sendTranslatedMessage("You're now single", channel, user);
                boolean takeAllMoney = !new SecureRandom().nextBoolean();
                if (takeAllMoney) {
                    Profile userProfile = Profile.get(user);
                    Profile divorceeProfile = Profile.get(UserUtils.getUserById(marriage.getUser_one().equals(user.getId()) ? marriage.getUser_two() : marriage.getUser_one()));
                    divorceeProfile.addMoney(userProfile.getMoney() / 2);
                    userProfile.removeMoney(userProfile.getMoney() / 2);
                    sendTranslatedMessage("Unlucky! Half of your assets were transferred to your ex.", channel, user);
                }
            } else
                sendTranslatedMessage("Ok, cancelling the divorce, but you should probably go to couples' therapy.", channel, user);
        });
    }
}
Also used : SecureRandom(java.security.SecureRandom) Marriage(tk.ardentbot.rethink.models.Marriage) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

Example 2 with Profile

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

the class UserUtils method hasTierTwoPermissions.

public static boolean hasTierTwoPermissions(User user) {
    String id = user.getId();
    boolean normalPermissions = isStaff(user) || 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)

Example 3 with Profile

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

the class UserUtils method hasTierThreePermissions.

public static boolean hasTierThreePermissions(User user) {
    String id = user.getId();
    boolean normalPermissions = isStaff(user) || 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)

Example 4 with Profile

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

the class TriviaGame method finish.

public void finish(Shard shard, Command command) throws Exception {
    totalRounds = 9001;
    final int bonus = 250;
    final int perQuestion = 50;
    Trivia.gamesInSession.remove(this);
    Trivia.gamesSettingUp.remove(guildId);
    Guild guild = shard.jda.getGuildById(guildId);
    TextChannel channel = guild.getTextChannelById(textChannelId);
    channel.sendMessage(displayScores(shard, command).build()).queue();
    channel.sendMessage("Thanks for playing! You'll receive **$50** for every correct answer").queue();
    Map<String, Integer> sorted = MapUtils.sortByValue(scores);
    Iterator<Map.Entry<String, Integer>> iterator = sorted.entrySet().iterator();
    int current = 0;
    while (iterator.hasNext()) {
        Map.Entry<String, Integer> entry = iterator.next();
        User user = guild.getMemberById(entry.getKey()).getUser();
        Profile profile = Profile.get(user);
        profile.addMoney(perQuestion * entry.getValue());
        if (current == 0 && !isSolo() && scores.size() > 1) {
            profile.addMoney(bonus);
            channel.sendMessage(user.getAsMention() + ", you won a **$250** bonus for being so smart!").queue();
        }
        current++;
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) User(net.dv8tion.jda.core.entities.User) Guild(net.dv8tion.jda.core.entities.Guild) HashMap(java.util.HashMap) Map(java.util.Map) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

Example 5 with Profile

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

the class ProfileUpdater method updateProfiles.

public static void updateProfiles() {
    Cursor<HashMap> profiles = r.db("data").table("profiles").run(connection);
    profiles.forEach(hashMap -> {
        Profile profile = asPojo(hashMap, Profile.class);
        if (profile.getUser() == null && !Ardent.testingBot) {
            r.table("profiles").get(profile.user_id).delete().run(connection);
            return;
        }
        for (Iterator<Badge> iterator = profile.getBadges().iterator(); iterator.hasNext(); ) {
            Badge badge = iterator.next();
            if (badge.getExpirationEpochSeconds() < Instant.now().getEpochSecond() && badge.getExpirationEpochSeconds() != 1) {
                User user = profile.getUser();
                if (user != null) {
                    user.openPrivateChannel().queue(privateChannel -> {
                        Ardent.shard0.help.sendTranslatedMessage("Your badge with the ID of **" + badge.getName() + "** has " + "expired" + ".", privateChannel, user);
                        r.db("data").table("badges").filter(row -> row.g("user_id").eq(user.getId()).and(row.g("badge_id").eq(badge.getId()))).delete().run(connection);
                        iterator.remove();
                    });
                }
            }
        }
    });
}
Also used : User(net.dv8tion.jda.core.entities.User) HashMap(java.util.HashMap) 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