Search in sources :

Example 11 with UserSQL

use of fun.rubicon.sql.UserSQL in project Rubicon by Rubicon-Bot.

the class CommandPremium method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    String[] args = parsedCommandInvocation.getArgs();
    UserSQL userSQL = UserSQL.fromUser(parsedCommandInvocation.getAuthor());
    if (args.length == 0) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setAuthor(parsedCommandInvocation.getAuthor().getName(), null, parsedCommandInvocation.getAuthor().getAvatarUrl());
        embedBuilder.setColor(Colors.COLOR_SECONDARY);
        String premiumEntry = userSQL.get("premium");
        if (premiumEntry.equalsIgnoreCase("false")) {
            embedBuilder.setDescription("No premium. \n\nBuy premium with `rc!premium buy` for 500k rubys.");
        } else {
            embedBuilder.setDescription("Premium is activated until " + userSQL.formatExpiryDate());
        }
        parsedCommandInvocation.getTextChannel().sendMessage(embedBuilder.build()).queue(message -> message.delete().queueAfter(3, TimeUnit.MINUTES));
        return null;
    }
    if (args[0].equalsIgnoreCase("buy")) {
        if (!userSQL.get("premium").equalsIgnoreCase("false")) {
            return EmbedUtil.message(EmbedUtil.info("Already activated!", "You already have premium until " + userSQL.getPremiumExpiryDate()));
        }
        int userMoney = Integer.parseInt(userSQL.get("money"));
        if (userMoney - PriceList.PREMIUM.getPrice() >= 0) {
            userSQL.set("premium", (PREMIUM_TIME) + "");
            userSQL.set("money", userMoney - PriceList.PREMIUM.getPrice() + "");
            assignPremiumRole(userSQL);
            return EmbedUtil.message(EmbedUtil.success("Success!", "Successfully bought premium."));
        } else {
            return EmbedUtil.message(EmbedUtil.error("Not enough money!", "Premium costs `" + PriceList.PREMIUM.getPrice() + "` rubys but you only have `" + userMoney + "` rubys"));
        }
    } else if (args[0].equalsIgnoreCase("add")) {
        if (authorPermissions.coveredBy(userPermissions)) {
            List<User> users = parsedCommandInvocation.getMessage().getMentionedUsers();
            if (users.size() == 0) {
                return EmbedUtil.message(EmbedUtil.error("Error!", "You have to mention at least 1 user."));
            } else {
                StringBuilder successValue = new StringBuilder();
                successValue.append("Successfully added premium to");
                for (User user : users) {
                    UserSQL pUser = UserSQL.fromUser(user);
                    pUser.set("premium", (PREMIUM_TIME) + "");
                    assignPremiumRole(pUser);
                    successValue.append(" / ").append(user.getAsMention());
                }
                String successText = successValue.toString().replaceFirst(" /", "");
                return EmbedUtil.message(EmbedUtil.success("Success!", successText + "."));
            }
        }
    } else if (args[0].equalsIgnoreCase("remove")) {
        if (authorPermissions.coveredBy(userPermissions)) {
            List<User> users = parsedCommandInvocation.getMessage().getMentionedUsers();
            if (users.size() == 0) {
                return EmbedUtil.message(EmbedUtil.error("Error!", "You have to mention at least 1 user."));
            } else {
                StringBuilder successValue = new StringBuilder();
                successValue.append("Successfully removed premium from");
                for (User user : users) {
                    UserSQL pUser = UserSQL.fromUser(user);
                    pUser.set("premium", "false");
                    assignPremiumRole(pUser);
                    successValue.append(" / ").append(user.getAsMention());
                }
                String successText = successValue.toString().replaceFirst(" /", "");
                return EmbedUtil.message(EmbedUtil.success("Success!", successText + "."));
            }
        }
    }
    return createHelpMessage();
}
Also used : UserSQL(fun.rubicon.sql.UserSQL) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) List(java.util.List) PriceList(fun.rubicon.core.PriceList)

Aggregations

UserSQL (fun.rubicon.sql.UserSQL)11 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)4 MusicManager (fun.rubicon.core.music.MusicManager)2 MemberSQL (fun.rubicon.sql.MemberSQL)2 PriceList (fun.rubicon.core.PriceList)1 CoinhiveUser (fun.rubicon.core.coinhive.CoinhiveUser)1 PermissionRequirements (fun.rubicon.permission.PermissionRequirements)1 List (java.util.List)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)1 Message (net.dv8tion.jda.core.entities.Message)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 User (net.dv8tion.jda.core.entities.User)1