Search in sources :

Example 1 with Marriage

use of tk.ardentbot.rethink.models.Marriage 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 Marriage

use of tk.ardentbot.rethink.models.Marriage 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 3 with Marriage

use of tk.ardentbot.rethink.models.Marriage in project Ardent by adamint.

the class Marry method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length == 1) {
        Marriage marriage = getMarriage(user);
        if (marriage == null)
            sendTranslatedMessage("You're not married! Marry someone with /marry @(User)", channel, user);
        else {
            sendEditedTranslation("**{0}** is married to **{1}**", user, channel, UserUtils.getUserById(marriage.getUser_one()).getName(), UserUtils.getUserById(marriage.getUser_two()).getName());
        }
    } else {
        List<User> mentionedUsers = message.getMentionedUsers();
        if (mentionedUsers.size() == 0) {
            sendTranslatedMessage("You need to mention someone!", channel, user);
            return;
        }
        User toMarryTo = mentionedUsers.get(0);
        Marriage marriage = getMarriage(user);
        if (marriage != null) {
            sendTranslatedMessage("Polygamy isn't allowed >.>", channel, user);
            return;
        }
        if (toMarryTo.isBot()) {
            sendTranslatedMessage("You can't marry a bot, but nice try! As for me, I'll forever love Adam.", channel, user);
            return;
        }
        if (getMarriage(toMarryTo) != null) {
            sendTranslatedMessage("That person is already married!", channel, user);
            return;
        }
        if (toMarryTo.getId().equals(user.getId())) {
            sendTranslatedMessage("Why are you even trying that??", channel, user);
            return;
        }
        sendEditedTranslation("{0}, {1} is proposing to you! Type `yes` to accept or `no` to brutally reject them", user, channel, toMarryTo.getAsMention(), user.getAsMention());
        longInteractiveOperation(channel, message, toMarryTo, 90, replyMessage -> {
            String reply = replyMessage.getContent();
            if (reply.equalsIgnoreCase("yes")) {
                Marriage m = getMarriage(toMarryTo);
                if (m != null) {
                    sendTranslatedMessage("Polygamy isn't allowed >.>", channel, user);
                    return;
                }
                sendTranslatedMessage("Congratulations! You're now married!", channel, user);
                r.db("data").table("marriages").insert(r.json(gson.toJson(new Marriage(user.getId(), toMarryTo.getId())))).run(connection);
            } else if (reply.equalsIgnoreCase("no")) {
                try {
                    sendEditedTranslation("Damn, {1} rejected you, {0} :frowning:", user, channel, user.getAsMention(), toMarryTo.getName());
                } catch (Exception e) {
                    new BotException(e);
                }
            } else {
                sendTranslatedMessage("Received an invalid response, cancelling marriage...", channel, user);
            }
        });
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) BotException(tk.ardentbot.core.misc.logging.BotException) Marriage(tk.ardentbot.rethink.models.Marriage) BotException(tk.ardentbot.core.misc.logging.BotException)

Aggregations

Marriage (tk.ardentbot.rethink.models.Marriage)3 User (net.dv8tion.jda.core.entities.User)2 Profile (tk.ardentbot.utils.rpg.profiles.Profile)2 SecureRandom (java.security.SecureRandom)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 BotException (tk.ardentbot.core.misc.logging.BotException)1