use of me.shadorc.shadbot.data.lotto.LottoPlayer in project Shadbot by Shadorc.
the class LottoCmd method show.
private void show(Context context) {
List<LottoPlayer> players = LottoManager.getPlayers();
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Lotto").withThumbnail("https://cdn.onlineunitedstatescasinos.com/wp-content/uploads/2016/04/Lottery-icon.png").withDescription(String.format("The next draw will take place in **%s**%nTo participate, type: `%s%s %d-%d`", FormatUtils.formatCustomDate(LottoCmd.getDelay()), context.getPrefix(), this.getName(), MIN_NUM, MAX_NUM)).appendField("Number of participants", Integer.toString(players.size()), false).appendField("Prize pool", FormatUtils.formatCoins(LottoManager.getPool()), false);
LottoPlayer player = players.stream().filter(lottoPlayer -> lottoPlayer.getUserID() == context.getAuthor().getLongID()).findAny().orElse(null);
if (player != null) {
embed.withFooterIcon("https://images.emojiterra.com/twitter/512px/1f39f.png");
embed.withFooterText(String.format("%s, you bet on number %d.", context.getAuthorName(), player.getNum()));
}
LottoHistoric historic = LottoManager.getHistoric();
if (historic != null) {
String people;
switch(historic.getWinnersCount()) {
case 0:
people = "nobody";
break;
case 1:
people = "one person";
break;
default:
people = historic.getWinnersCount() + " people";
break;
}
embed.appendField("Historic", String.format("Last week, the prize pool contained **%s**, the winning number was **%d** and **%s won**.", FormatUtils.formatCoins(historic.getPool()), historic.getNum(), people), false);
}
BotUtils.sendMessage(embed.build(), context.getChannel());
}
use of me.shadorc.shadbot.data.lotto.LottoPlayer in project Shadbot by Shadorc.
the class LottoCmd method draw.
public static void draw() {
LogUtils.infof("Lottery draw started...");
int winningNum = ThreadLocalRandom.current().nextInt(MIN_NUM, MAX_NUM + 1);
List<LottoPlayer> winners = LottoManager.getPlayers().stream().filter(player -> player.getNum() == winningNum && Shadbot.getClient().getGuildByID(player.getGuildID()) != null && Shadbot.getClient().getUserByID(player.getUserID()) != null).collect(Collectors.toList());
for (LottoPlayer winner : winners) {
IGuild guild = Shadbot.getClient().getGuildByID(winner.getGuildID());
IUser user = Shadbot.getClient().getUserByID(winner.getUserID());
int coins = (int) Math.ceil((double) LottoManager.getPool() / winners.size());
Database.getDBUser(guild, user).addCoins(coins);
BotUtils.sendMessage(String.format("Congratulations, you have the winning Lotto number! You earn %s.", FormatUtils.formatCoins(coins)), user.getOrCreatePMChannel());
}
LogUtils.infof("Lottery draw done (Winning number: %d | %d winner(s) | Prize pool: %d)", winningNum, winners.size(), LottoManager.getPool());
LottoManager.setHistoric(winners.size(), LottoManager.getPool(), winningNum);
LottoManager.resetUsers();
if (!winners.isEmpty()) {
LottoManager.resetPool();
}
}
use of me.shadorc.shadbot.data.lotto.LottoPlayer in project Shadbot by Shadorc.
the class LottoCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
this.show(context);
return;
}
DBUser dbUser = Database.getDBUser(context.getGuild(), context.getAuthor());
if (dbUser.getCoins() < PAID_COST) {
BotUtils.sendMessage(TextUtils.notEnoughCoins(context.getAuthor()), context.getChannel());
return;
}
LottoPlayer player = LottoManager.getPlayers().stream().filter(lottoPlayer -> lottoPlayer.getUserID() == context.getAuthor().getLongID()).findAny().orElse(null);
if (player != null) {
throw new IllegalCmdArgumentException("You're already participating.");
}
Integer num = CastUtils.asIntBetween(context.getArg(), MIN_NUM, MAX_NUM);
if (num == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid number, it must be between %d and %d.", context.getArg(), MIN_NUM, MAX_NUM));
}
dbUser.addCoins(-PAID_COST);
LottoManager.addPlayer(context.getGuild(), context.getAuthor(), num);
BotUtils.sendMessage(String.format(Emoji.TICKET + " You bought a lottery ticket and bet on number **%d**. Good luck !", num), context.getChannel());
}
Aggregations