use of fun.rubicon.sql.UserSQL in project Rubicon by Rubicon-Bot.
the class CommandSlot method execute.
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
UserSQL userSQL = new UserSQL(parsedCommandInvocation.getAuthor());
int slot_one = 0;
int slot_two = 0;
int slot_three = 0;
int payed_money = 0;
int user_set_money = 0;
int multiplicator = 0;
int user_has_money = Integer.parseInt(userSQL.get("money"));
if (parsedCommandInvocation.getArgs().length >= 1) {
try {
payed_money = Integer.parseInt(parsedCommandInvocation.getArgs()[0]);
} catch (NumberFormatException exception) {
sendHelpMessage(parsedCommandInvocation.getMessage().getChannel());
return message(error("Invalid argument", "Your bet must be an integer number."));
}
if (payed_money <= user_has_money && payed_money > 0) {
slot_one = ThreadLocalRandom.current().nextInt(0, SlotMachine.Slots.length);
slot_two = ThreadLocalRandom.current().nextInt(0, SlotMachine.Slots.length);
slot_three = ThreadLocalRandom.current().nextInt(0, SlotMachine.Slots.length);
parsedCommandInvocation.getMessage().getChannel().sendMessage(message(info("The slot machine rolled!", "The slot machine rolled: " + SlotMachine.Slots[slot_one] + " " + SlotMachine.Slots[slot_two] + " " + SlotMachine.Slots[slot_three]))).queue();
if (slot_one == slot_two && slot_one == slot_three) {
if (slot_one <= 7) {
multiplicator = 2;
} else if (slot_one <= 11) {
multiplicator = 3;
} else if (slot_one <= 13) {
multiplicator = 5;
} else {
multiplicator = 8;
}
user_set_money = user_has_money + (payed_money * multiplicator);
userSQL.set("money", String.valueOf(user_set_money));
return message(embed("You win!", "Congratulations! " + parsedCommandInvocation.getMessage().getAuthor().getAsMention() + " You won " + (payed_money * multiplicator) + " Ruby's. :tada:").setColor(Colors.COLOR_SECONDARY));
} else {
user_set_money = user_has_money - payed_money;
userSQL.set("money", String.valueOf(user_set_money));
return message(embed("You lose!", "Sorry. " + parsedCommandInvocation.getMessage().getAuthor().getAsMention() + " you lose. :cry: More luck next time!").setColor(Colors.COLOR_SECONDARY));
}
} else {
if (payed_money == 0) {
return message(error("You didn't pay", parsedCommandInvocation.getMessage().getAuthor().getAsMention() + " you have to pay Ruby's to play at a slot machine."));
}
return message(error("Not enough money", parsedCommandInvocation.getMessage().getAuthor().getAsMention() + " you don't have enough Ruby's. You only have " + user_has_money + " Ruby's."));
}
}
sendHelpMessage(parsedCommandInvocation.getMessage().getChannel());
return message(error("You didn't pay", parsedCommandInvocation.getMessage().getAuthor().getAsMention() + " you have to pay Ruby's to play at a slot machine."));
}
use of fun.rubicon.sql.UserSQL in project Rubicon by Rubicon-Bot.
the class CommandMiner method execute.
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
CoinhiveUser coinhiveUser = CoinhiveManager.getCoinhiveUser(parsedCommandInvocation.getAuthor());
UserSQL userSQL = new UserSQL(parsedCommandInvocation.getAuthor());
if (parsedCommandInvocation.getArgs().length == 0) {
return EmbedUtil.message(new EmbedBuilder().setDescription("You currently have `" + coinhiveUser.getBalance() + "` hashes.").setAuthor(parsedCommandInvocation.getAuthor().getName(), null, parsedCommandInvocation.getAuthor().getAvatarUrl()).setColor(Colors.COLOR_PRIMARY).setFooter("Miner more on https://miner.rubicon.fun", null));
}
if (parsedCommandInvocation.getArgs()[0].equalsIgnoreCase("payout")) {
int withdrawAmount = (int) coinhiveUser.getBalance();
if (withdrawAmount == 0) {
return EmbedUtil.message(EmbedUtil.error("No money!", "You have to mine new rubys first."));
}
int oldMoney = Integer.parseInt(userSQL.get("money"));
int newMoney = oldMoney + withdrawAmount;
userSQL.set("money", newMoney + "");
CoinhiveManager.withdrawUser(coinhiveUser, withdrawAmount);
return EmbedUtil.message(EmbedUtil.success("Payout successfull!", "Transfered `" + withdrawAmount + "` rubys."));
} else {
return createHelpMessage();
}
}
use of fun.rubicon.sql.UserSQL in project Rubicon by Rubicon-Bot.
the class CommandProfile method generateProfile.
private void generateProfile(Member member, TextChannel textChannel) {
User user = member.getUser();
MemberSQL memberSQL = new MemberSQL(member);
UserSQL userSQL = new UserSQL(user);
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Colors.COLOR_PRIMARY);
embedBuilder.setAuthor(member.getEffectiveName() + "'s profile", null, member.getUser().getAvatarUrl());
if (Arrays.asList(Info.BOT_AUTHOR_IDS).contains(member.getUser().getIdLong())) {
embedBuilder.addField("VIP", "Official RubiconBot Developer", false);
} else {
Role staffRole = member.getGuild().getRoleById(Info.COMMUNITY_STAFF_ROLE);
if (member.getRoles().contains(staffRole))
embedBuilder.addField("VIP", "RubiconBot Community Staff", false);
}
embedBuilder.setDescription(userSQL.get("bio"));
embedBuilder.addField("Money", "Balance: " + userSQL.get("money") + " Rubys", true);
embedBuilder.addField("Premium", (userSQL.isPremium()) ? "Until " + userSQL.formatExpiryDate() : "No premium", true);
embedBuilder.addField("Level", buildProgressBar(memberSQL), false);
textChannel.sendMessage(EmbedUtil.message(embedBuilder)).queue(message -> message.delete().queueAfter(5, TimeUnit.MINUTES));
}
use of fun.rubicon.sql.UserSQL in project Rubicon by Rubicon-Bot.
the class CommandRoulette method execute.
@Override
protected Message execute(CommandManager.ParsedCommandInvocation invocation, UserPermissions permissions) {
UserSQL userSQL = new UserSQL(invocation.getAuthor());
if (invocation.getArgs().length < 2)
return createHelpMessage(invocation);
else {
int betAmount;
// parse bet amount
try {
betAmount = Integer.parseInt(invocation.getArgs()[0]);
} catch (NumberFormatException e) {
return message(error("Invalid value", "The minimum value `" + invocation.getArgs()[0] + "` is not an integer number."));
}
// check if bet amount is > 0
if (betAmount <= 0)
return message(error("Bet too little", "You need to bet at least 1 ruby to play Roulette."));
// check if the user has enough money to cover his bet
if (betAmount > Integer.parseInt(userSQL.get("money")))
return message(error("Not enough money", "You don't have `" + betAmount + "` rubys. " + "Check your money with `" + invocation.getPrefix() + "money`."));
// already generate random number
String betOption = invocation.getArgs()[1];
// 0 - 36
int rolledNumber = (int) (Math.random() * 37);
int multiplier;
boolean wins;
switch(betOption) {
case "even":
multiplier = 2;
wins = rolledNumber != 0 && rolledNumber % 2 == 0;
break;
case "odd":
multiplier = 2;
wins = rolledNumber % 2 != 0;
break;
case "red":
multiplier = 2;
wins = RouletteNumber.RouletteColor[rolledNumber].equals("red");
break;
case "black":
multiplier = 2;
wins = RouletteNumber.RouletteColor[rolledNumber].equals("black");
break;
case "1-18":
multiplier = 2;
wins = rolledNumber > 0 && rolledNumber < 19;
break;
case "19-36":
multiplier = 2;
// numbers can not be greater than 36
wins = rolledNumber > 18;
break;
case "1-12":
multiplier = 3;
wins = rolledNumber > 0 && rolledNumber < 13;
break;
case "13-24":
multiplier = 3;
wins = rolledNumber > 12 && rolledNumber < 25;
break;
case "25-36":
multiplier = 3;
wins = rolledNumber > 24;
break;
case "column_low":
multiplier = 3;
wins = rolledNumber % 3 == 1;
break;
case "column_mid":
multiplier = 3;
wins = rolledNumber % 3 == 2;
break;
case "column_up":
multiplier = 3;
wins = rolledNumber != 0 && rolledNumber % 3 == 0;
break;
default:
int betNumber;
try {
betNumber = Integer.parseInt(betOption);
if (betNumber < 0 || betNumber > 36)
throw new IllegalArgumentException();
} catch (IllegalArgumentException e) {
// NumberFormatException is an IllegalArgumentException
return message(error("Invalid bet option", "You can not bid on `" + betOption + "`. Use `" + invocation.getPrefix() + invocation.getCommandInvocation() + "` for a full bet option list."));
}
multiplier = 36;
wins = betNumber == rolledNumber;
break;
}
sendAndDeleteOnGuilds(invocation.getMessage().getChannel(), message(info("Rien ne va plus!", "The number is " + rolledNumber + ".\nIt's color is " + RouletteNumber.RouletteColor[rolledNumber] + ".")));
if (wins) {
int wonMoney = betAmount * (multiplier - 1);
// update money
userSQL.set("money", String.valueOf(Integer.parseInt(userSQL.get("money")) + wonMoney));
// respond
return message(embed(":star: You win", "Congratulations " + invocation.getMessage().getAuthor().getAsMention() + "! You won " + wonMoney + " rubys.").setColor(Color.YELLOW));
} else {
// update money
userSQL.set("money", String.valueOf(Integer.parseInt(userSQL.get("money")) - betAmount));
// respond
return message(embed(":cry: You lose", "Sorry, no luck this time!"));
}
}
}
use of fun.rubicon.sql.UserSQL in project Rubicon by Rubicon-Bot.
the class CommandMoney method execute.
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
UserSQL userSQL = new UserSQL(parsedCommandInvocation.getAuthor());
UserSQL userSQL2 = null;
if (parsedCommandInvocation.getMessage().getMentionedUsers().size() == 1) {
userSQL2 = new UserSQL(parsedCommandInvocation.getMessage().getMentionedUsers().get(0));
}
int user1_has_money = 0;
int user2_has_money = 0;
int user_spend_money = 0;
if (parsedCommandInvocation.getArgs().length == 0) {
parsedCommandInvocation.getTextChannel().sendMessage(new EmbedBuilder().setColor(Colors.COLOR_PRIMARY).setDescription("Balance: `" + new UserSQL(parsedCommandInvocation.getAuthor()).get("money") + "`").setAuthor(parsedCommandInvocation.getAuthor().getName() + "'s money", null, parsedCommandInvocation.getAuthor().getAvatarUrl()).build()).queue();
return null;
}
switch(parsedCommandInvocation.getArgs()[0]) {
case "give":
if (parsedCommandInvocation.getArgs().length == 3) {
try {
if (parsedCommandInvocation.getMessage().getMentionedMembers().size() == 1) {
if (parsedCommandInvocation.getMessage().getMentionedMembers().get(0).getUser().getId().equalsIgnoreCase(parsedCommandInvocation.getAuthor().getId())) {
return new MessageBuilder().setEmbed(EmbedUtil.error("Error!", "You cant donate money yourself!").build()).build();
}
} else {
return createHelpMessage();
}
user_spend_money = Integer.parseInt(parsedCommandInvocation.getArgs()[parsedCommandInvocation.getArgs().length - 1]);
user1_has_money = Integer.parseInt(userSQL.get("money"));
user2_has_money = Integer.parseInt(userSQL2.get("money"));
if (user1_has_money < user_spend_money) {
return message(error("Not enough Money", "Sorry " + parsedCommandInvocation.getMessage().getAuthor().getAsMention() + ". You only have " + user1_has_money + " Ruby's!"));
} else {
if ((user2_has_money + user_spend_money) <= 2147483647) {
userSQL.set("money", String.valueOf(user1_has_money - user_spend_money));
userSQL2.set("money", String.valueOf(user2_has_money + user_spend_money));
return message(success("Donation completed", parsedCommandInvocation.getMessage().getAuthor().getAsMention() + " give " + user_spend_money + " Ruby's to " + parsedCommandInvocation.getMessage().getMentionedUsers().get(0).getAsMention() + "."));
} else {
return message(error("Money value to big!", "Money value must be smaller than " + ((2147483647 - user2_has_money) + 1) + "!"));
}
}
} catch (NumberFormatException exception) {
return message(error("NaN or money value is to big!", "The money value is not a number or bigger than 2.147.483.647!"));
}
} else {
return message(error("Wrong count of arguments", "Three arguments are necessary!\n" + getParameterUsage()));
}
case "set":
if (new PermissionRequirements("command.money.modify", true, false).coveredBy(userPermissions)) {
if (parsedCommandInvocation.getArgs().length == 3) {
try {
user_spend_money = Integer.parseInt(parsedCommandInvocation.getArgs()[parsedCommandInvocation.getArgs().length - 1]);
if (user_spend_money > -1) {
userSQL2.set("money", String.valueOf(user_spend_money));
return message(success("Money has been set!", "Money of " + parsedCommandInvocation.getMessage().getMentionedUsers().get(0).getAsMention() + " has been set to " + user_spend_money + " Ruby's."));
} else {
return message(error("Money value to small!", "Money value must be 0 or bigger!"));
}
} catch (NumberFormatException exception) {
return message(error("NaN or money value is to big!", "The money value is not a number or bigger than 2.147.483.647!"));
}
} else {
return message(error("Wrong count of arguments", "Three arguments are necessary!\n" + getParameterUsage()));
}
} else {
return message(no_permissions());
}
case "add":
int max_money = 2147483647;
user2_has_money = Integer.parseInt(userSQL.get("money"));
if (new PermissionRequirements("command.money.modify", true, false).coveredBy(userPermissions)) {
if (parsedCommandInvocation.getArgs().length == 3) {
try {
user_spend_money = Integer.parseInt(parsedCommandInvocation.getArgs()[parsedCommandInvocation.getArgs().length - 1]);
if (user_spend_money > 0) {
if ((user2_has_money + user_spend_money) <= 2147483647 && (user2_has_money + user_spend_money) > 0) {
if (user2_has_money == 2147483647) {
return message(error("Too much money!", parsedCommandInvocation.getMessage().getMentionedUsers().get(0).getAsMention() + " has already the money maximum!"));
} else {
userSQL2.set("money", String.valueOf(user2_has_money + user_spend_money));
return message(success("Money has been added!", "Money of " + parsedCommandInvocation.getMessage().getMentionedUsers().get(0).getAsMention() + " has been set to " + (user2_has_money + user_spend_money) + " Ruby's."));
}
} else {
return message(error("Money value to big!", "Money value must be smaller than " + ((max_money - user2_has_money) + 1) + "!"));
}
} else {
return message(error("Money value to small!", "Money value must be bigger than 0!"));
}
} catch (NumberFormatException exception) {
return message(error("Not a number!", "The money value is not a number!"));
}
} else {
return message(error("Wrong count of arguments", "Three arguments are necessary!\n" + getParameterUsage()));
}
} else {
return message(no_permissions());
}
case "remove":
user2_has_money = Integer.parseInt(userSQL2.get("money"));
if (new PermissionRequirements("command.money.modify", true, false).coveredBy(userPermissions)) {
if (parsedCommandInvocation.getArgs().length == 3) {
try {
user_spend_money = Integer.parseInt(parsedCommandInvocation.getArgs()[parsedCommandInvocation.getArgs().length - 1]);
if (user_spend_money > 0) {
if ((Integer.parseInt(userSQL2.get("money")) - user_spend_money) >= 0) {
userSQL2.set("money", String.valueOf(user2_has_money - user_spend_money));
return message(success("Money has been removed!", "Money of " + parsedCommandInvocation.getMessage().getMentionedUsers().get(0).getAsMention() + " has been set to " + (user2_has_money - user_spend_money) + " Ruby's."));
} else {
return message(error("Money value to big!", "Money value must be smaller than " + ((2147483647 - user2_has_money) + 1) + "!"));
}
} else {
return message(error("Money value to small!", "Money value must be bigger than 0!"));
}
} catch (NumberFormatException exception) {
return message(error("NaN or money value is to big!", "The money value is not a number or bigger than 2.147.483.647!"));
}
} else {
return message(error("Wrong count of arguments", "Three arguments are necessary!\n" + getParameterUsage()));
}
} else {
return message(no_permissions());
}
default:
return message(error("No valid money option", "Only give, set, add, remove are valid money options!"));
}
}
Aggregations