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();
}
Aggregations