public async Task Award(ShmartNumber amount, ulong usrId, [Leftover] string msg = null) { if (amount <= 0) { return; } await _cs.AddAsync(usrId, $"Awarded by bot owner. ({ctx.User.Username}/{ctx.User.Id}) {(msg ?? "")}", amount, gamble : (ctx.Client.CurrentUser.Id != usrId)).ConfigureAwait(false); await ReplyConfirmLocalizedAsync("awarded", n(amount) + CurrencySign, $"<@{usrId}>").ConfigureAwait(false); }
public async Task Award(ShmartNumber amount, ulong usrId, [Remainder] string msg = null) { if (amount <= 0) { return; } await _cs.AddAsync(usrId, $"Awarded: ({Context.User.Username}/{Context.User.Id}) {(msg ?? "")}", amount, gamble : (Context.Client.CurrentUser.Id != usrId)).ConfigureAwait(false); await ReplyConfirmLocalizedAsync("awarded", amount + CurrencySign, $"<@{usrId}>").ConfigureAwait(false); }
public async Task WheelOfFortuneVisual(ShmartNumber amount) { if (!_runningUsers.Add(Context.User.Id)) { return; } try { if (!await CheckBetMandatory(amount).ConfigureAwait(false)) { return; } if (!await _cs.RemoveAsync(Context.User.Id, "Wheel Of Fortune - bet", amount, gamble: true).ConfigureAwait(false)) { await ReplyErrorLocalized("not_enough", Bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } var result = await _service.WheelOfFortuneSpinAsync(Context.User.Id, amount).ConfigureAwait(false); using (var bgImage = Image.Load(_images.WheelBackground)) { using (var Emoji = Image.Load(_images.WheelEmojis[result.Index])) { bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, Emoji, new Point(0, 0))); using (var CenterEmoji = Image.Load(_images.WheelEmojis[8])) { bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, CenterEmoji, new Point(120, 120))); } } using (var imgStream = bgImage.ToStream()) { await Context.Channel.SendFileAsync(imgStream, "result.png", Context.User.Mention + $" {GetText("wheel_bet", amount, Bc.BotConfig.CurrencySign)}\n{GetText("wheel_won", result.Amount, Wof.Multipliers[result.Index], Bc.BotConfig.CurrencySign)}").ConfigureAwait(false); } } } finally { var _ = Task.Run(async() => { await Task.Delay(1500).ConfigureAwait(false); _runningUsers.Remove(Context.User.Id); }); } }
public async Task Betflip(ShmartNumber amount, BetFlipGuess guess) { if (!await CheckBetMandatory(amount).ConfigureAwait(false) || amount == 1) { return; } var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false, gamble : true).ConfigureAwait(false); if (!removed) { await ReplyErrorLocalizedAsync("not_enough", Bc.BotConfig.CurrencyPluralName).ConfigureAwait(false); return; } BetFlipGuess result; Uri imageToSend; var coins = _images.ImageUrls.Coins; if (rng.Next(0, 1000) <= 499) { imageToSend = coins.Heads[rng.Next(0, coins.Heads.Length)]; result = BetFlipGuess.Heads; } else { imageToSend = coins.Tails[rng.Next(0, coins.Tails.Length)]; result = BetFlipGuess.Tails; } string str; if (guess == result) { var toWin = (long)(amount * Bc.BotConfig.BetflipMultiplier); str = Format.Bold(Context.User.ToString()) + " " + GetText("flip_guess", toWin + Bc.BotConfig.CurrencySign); await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false, gamble : true).ConfigureAwait(false); } else { ///Format.Bold(Context.User.ToString()) instead of Context.User.Mention to not mention users? Bug or feature? str = Context.User.Mention + " " + GetText("better_luck"); } await Context.Channel.EmbedAsync(new EmbedBuilder() .WithDescription(str) .WithOkColor() .WithImageUrl(imageToSend.ToString())).ConfigureAwait(false); }
public async Task Take(ShmartNumber amount, [Leftover] IRole role) { var users = (await role.GetMembersAsync()).ToList(); await _cs.RemoveBulkAsync(users.Select(x => x.Id), users.Select(x => $"Taken by bot owner from **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"), users.Select(x => amount.Value), gamble : true) .ConfigureAwait(false); await ReplyConfirmLocalizedAsync("mass_take", n(amount) + CurrencySign, Format.Bold(users.Count.ToString()), Format.Bold(role.Name)).ConfigureAwait(false); }
public async Task Take(ShmartNumber amount, [Remainder] IGuildUser user) { if (amount <= 0) { return; } if (await _cs.RemoveAsync(user, $"Oh no, it's the fun police! They're here for your loot!({Context.User.Username}/{Context.User.Id})", amount, true).ConfigureAwait(false)) { await ReplyConfirmLocalizedAsync("take", amount + CurrencySign, Format.Bold(user.ToString())).ConfigureAwait(false); } else { await ReplyErrorLocalizedAsync("take_fail", amount + CurrencySign, Format.Bold(user.ToString()), CurrencyPluralName).ConfigureAwait(false); } }
public async Task Award(ShmartNumber amount, [Remainder] IRole role) { var users = (await Context.Guild.GetUsersAsync()) .Where(u => u.GetRoles().Contains(role)) .ToList(); await _cs.AddBulkAsync(users.Select(x => x.Id), users.Select(x => $"Awarded by bot owner to **{role.Name}** role. ({Context.User.Username}/{Context.User.Id})"), users.Select(x => amount.Value), gamble : true) .ConfigureAwait(false); await ReplyConfirmLocalized("mass_award", amount + CurrencySign, Format.Bold(users.Count.ToString()), Format.Bold(role.Name)).ConfigureAwait(false); }
public async Task Take(ShmartNumber amount, [Remainder] ulong usrId) { if (amount <= 0) { return; } if (await _cs.RemoveAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount, gamble: (Context.Client.CurrentUser.Id != usrId))) { await ReplyConfirmLocalized("take", amount + CurrencySign, $"<@{usrId}>").ConfigureAwait(false); } else { await ReplyErrorLocalized("take_fail", amount + CurrencySign, Format.Code(usrId.ToString()), CurrencyPluralName).ConfigureAwait(false); } }
public async Task Take(ShmartNumber amount, [Leftover] IGuildUser user) { if (amount <= 0) { return; } if (await _cs.RemoveAsync(user, $"Taken by bot owner.({ctx.User.Username}/{ctx.User.Id})", amount, gamble: (ctx.Client.CurrentUser.Id != user.Id)).ConfigureAwait(false)) { await ReplyConfirmLocalizedAsync("take", n(amount) + CurrencySign, Format.Bold(user.ToString())).ConfigureAwait(false); } else { await ReplyErrorLocalizedAsync("take_fail", n(amount) + CurrencySign, Format.Bold(user.ToString()), CurrencyPluralName).ConfigureAwait(false); } }
public async Task Give(ShmartNumber amount, IGuildUser receiver, [Remainder] string msg = null) { if (amount <= 0 || Context.User.Id == receiver.Id || receiver.IsBot) { return; } var success = await _cs.RemoveAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, false).ConfigureAwait(false); if (!success) { await ReplyErrorLocalized("not_enough", CurrencyPluralName).ConfigureAwait(false); return; } await _cs.AddAsync(receiver, $"Gift from {Context.User.Username} ({Context.User.Id}) - {msg}.", amount, true).ConfigureAwait(false); await ReplyConfirmLocalized("gifted", amount + CurrencySign, Format.Bold(receiver.ToString()), msg) .ConfigureAwait(false); }
public async Task Slot(ShmartNumber amount) { if (!_runningUsers.Add(Context.User.Id)) { return; } try { if (!await CheckBetMandatory(amount)) { return; } const int maxAmount = 9999; if (amount > maxAmount) { await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false, gamble: true)) { await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } Interlocked.Add(ref _totalBet, amount.Value); using (var bgFileStream = _images.SlotBackground.ToStream()) { var bgImage = ImageSharp.Image.Load(bgFileStream); var result = SlotMachine.Pull(); int[] numbers = result.Numbers; for (int i = 0; i < 3; i++) { using (var file = _images.SlotEmojis[numbers[i]].ToStream()) using (var randomImage = ImageSharp.Image.Load(file)) { bgImage.DrawImage(randomImage, 100, default, new Point(95 + 142 * i, 330));
public async Task BlackJack(ShmartNumber amount) { if (!await CheckBetMandatory(amount).ConfigureAwait(false)) { return; } var newBj = new Blackjack(_cs, _db); Blackjack bj; if (newBj == (bj = _service.Games.GetOrAdd(Context.Channel.Id, newBj))) { if (!await bj.Join(Context.User, amount).ConfigureAwait(false)) { _service.Games.TryRemove(Context.Channel.Id, out _); await ReplyErrorLocalized("not_enough", Bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } bj.StateUpdated += Bj_StateUpdated; bj.GameEnded += Bj_GameEnded; bj.Start(); await ReplyConfirmLocalized("bj_created").ConfigureAwait(false); } else { if (await bj.Join(Context.User, amount).ConfigureAwait(false)) { await ReplyConfirmLocalized("bj_joined").ConfigureAwait(false); } else { _log.Info($"{Context.User} can't join a blackjack game as it's in " + bj.State.ToString() + " state already."); } } await Context.Message.DeleteAsync().ConfigureAwait(false); }
public Task Convert(string origin, string target, ShmartNumber value) => Convert(origin, target, (decimal)value.Value);
public Task RaffleCur(Mixed _, ShmartNumber amount) => RaffleCur(amount, true);
public async Task Slot(ShmartNumber amount) { if (!_runningUsers.Add(Context.User.Id)) { return; } try { if (!await CheckBetMandatory(amount).ConfigureAwait(false)) { return; } const int maxAmount = 9999; if (amount > maxAmount) { await ReplyErrorLocalized("max_bet_limit", maxAmount + Bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false, gamble: true).ConfigureAwait(false)) { await ReplyErrorLocalized("not_enough", Bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } Interlocked.Add(ref _totalBet, amount.Value); using (var bgImage = Image.Load(_images.SlotBackground)) { var result = SlotMachine.Pull(); int[] numbers = result.Numbers; for (int i = 0; i < 3; i++) { using (var randomImage = Image.Load(_images.SlotEmojis[numbers[i]])) { bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, randomImage, new Point(95 + 142 * i, 330))); } } var won = amount * result.Multiplier; var printWon = won; var n = 0; do { var digit = (int)(printWon % 10); using (var img = Image.Load(_images.SlotNumbers[digit])) { bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, img, new Point(230 - n * 16, 462))); } n++; } while ((printWon /= 10) != 0); var printAmount = amount; n = 0; do { var digit = (int)(printAmount % 10); using (var img = Image.Load(_images.SlotNumbers[digit])) { bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, img, new Point(395 - n * 16, 462))); } n++; } while ((printAmount /= 10) != 0); var msg = GetText("better_luck"); if (result.Multiplier != 0) { await _cs.AddAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount *result.Multiplier, false, gamble : true).ConfigureAwait(false); Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier); if (result.Multiplier == 1) { msg = GetText("slot_single", Bc.BotConfig.CurrencySign, 1); } else if (result.Multiplier == 4) { msg = GetText("slot_two", Bc.BotConfig.CurrencySign, 4); } else if (result.Multiplier == 10) { msg = GetText("slot_three", 10); } else if (result.Multiplier == 30) { msg = GetText("slot_jackpot", 30); } } using (var imgStream = bgImage.ToStream()) { await Context.Channel.SendFileAsync(imgStream, "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("won")}:` {amount * result.Multiplier}{Bc.BotConfig.CurrencySign}").ConfigureAwait(false); } } } finally { var _ = Task.Run(async() => { await Task.Delay(1500).ConfigureAwait(false); _runningUsers.Remove(Context.User.Id); }); } }
public async Task Rps(RpsPick pick, ShmartNumber amount = default) { long oldAmount = amount; if (!await CheckBetOptional(amount) || (amount == 1)) { return; } string getRpsPick(RpsPick p) { switch (p) { case RpsPick.R: return("🚀"); case RpsPick.P: return("📎"); default: return("✂️"); } } var embed = new EmbedBuilder(); var KotocornPick = (RpsPick) new KotocornRandom().Next(0, 3); if (amount > 0) { if (!await _cs.RemoveAsync(Context.User.Id, "Rps-bet", amount, gamble: true)) { await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } } string msg; if (pick == KotocornPick) { await _cs.AddAsync(Context.User.Id, "Rps-draw", amount, gamble : true); embed.WithOkColor(); msg = GetText("rps_draw", getRpsPick(pick)); } else if ((pick == RpsPick.Paper && KotocornPick == RpsPick.Rock) || (pick == RpsPick.Rock && KotocornPick == RpsPick.Scissors) || (pick == RpsPick.Scissors && KotocornPick == RpsPick.Paper)) { amount = (long)(amount * _bc.BotConfig.BetflipMultiplier); await _cs.AddAsync(Context.User.Id, "Rps-win", amount, gamble : true); embed.WithOkColor(); embed.AddField(GetText("won"), amount); msg = GetText("rps_win", Context.User.Mention, getRpsPick(pick), getRpsPick(KotocornPick)); } else { embed.WithErrorColor(); amount = 0; msg = GetText("rps_win", Context.Client.CurrentUser.Mention, getRpsPick(KotocornPick), getRpsPick(pick)); } embed .WithDescription(msg); await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); }
public Task BetRoll(ShmartNumber amount) => InternallBetroll(amount);
public async Task RollDuel(ShmartNumber amount, IUser u) { if (Context.User.Id == u.Id) { return; } if (amount <= 0) { return; } var embed = new EmbedBuilder() .WithOkColor() .WithTitle(GetText("roll_duel")); var game = new RollDuelGame(_cs, _client.CurrentUser.Id, Context.User.Id, u.Id, amount); //means challenge is just created if (_service.Duels.TryGetValue((Context.User.Id, u.Id), out var other)) { if (other.Amount != amount) { await ReplyErrorLocalized("roll_duel_already_challenged").ConfigureAwait(false); } else { await RollDuel(u).ConfigureAwait(false); } return; } if (_service.Duels.TryAdd((u.Id, Context.User.Id), game)) { game.OnGameTick += Game_OnGameTick; game.OnEnded += Game_OnEnded; await ReplyConfirmLocalized("roll_duel_challenge", Format.Bold(Context.User.ToString()), Format.Bold(u.ToString()), Format.Bold(amount + CurrencySign)) .ConfigureAwait(false); } async Task Game_OnGameTick(RollDuelGame arg) { var rolls = arg.Rolls.Last(); embed.Description += $@"{Format.Bold(Context.User.ToString())} rolled **{rolls.Item1}** {Format.Bold(u.ToString())} rolled **{rolls.Item2}** -- "; if (rdMsg == null) { rdMsg = await Context.Channel.EmbedAsync(embed) .ConfigureAwait(false); } else { await rdMsg.ModifyAsync(x => { x.Embed = embed.Build(); }).ConfigureAwait(false); } } async Task Game_OnEnded(RollDuelGame rdGame, RollDuelGame.Reason reason) { try { if (reason == RollDuelGame.Reason.Normal) { var winner = rdGame.Winner == rdGame.P1 ? Context.User : u; embed.Description += $"\n**{winner}** Won {((long)(rdGame.Amount * 2 * 0.98)) + CurrencySign}"; await rdMsg.ModifyAsync(x => x.Embed = embed.Build()) .ConfigureAwait(false); } else if (reason == RollDuelGame.Reason.Timeout) { await ReplyErrorLocalized("roll_duel_timeout").ConfigureAwait(false); } else if (reason == RollDuelGame.Reason.NoFunds) { await ReplyErrorLocalized("roll_duel_no_funds").ConfigureAwait(false); } } finally { _service.Duels.TryRemove((u.Id, Context.User.Id), out var _); } } }
public async Task WheelOfFortune(ShmartNumber amount) { if (!await CheckBetMandatory(amount).ConfigureAwait(false)) { return; } if (!await _cs.RemoveAsync(Context.User.Id, "Wheel Of Fortune - bet", amount, gamble: true).ConfigureAwait(false)) { await ReplyErrorLocalized("not_enough", Bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } var _rng = new NadekoRandom(); var result = _rng.Next(0, _results.Length); var wonAmountTemp = _results[result].Item1 * amount; string commentary = GetText(_results[result].Item2); var rotation = (result * 360) / _results.Length; var mayhem = _rng.Next(0, 100); if (mayhem == 0) { wonAmountTemp = wonAmountTemp * _mayhemMultiplier; await Context.Channel.SendConfirmAsync("Let's spin the " + Format.Bold("Wheel of Mayhem") + " for x" + _mayhemMultiplier + " multiplier, " + Context.User.Mention + "!") .ConfigureAwait(false); System.Threading.Thread.Sleep(2000); await Context.Channel.SendConfirmAsync("Ratatata-ta-ta-ta ta ta...!").ConfigureAwait(false); System.Threading.Thread.Sleep(2000); await Context.Channel.SendConfirmAsync("Ta...!").ConfigureAwait(false); System.Threading.Thread.Sleep(2000); await Context.Channel.SendConfirmAsync("...").ConfigureAwait(false); System.Threading.Thread.Sleep(2000); await Context.Channel.SendConfirmAsync("Ta!").ConfigureAwait(false); System.Threading.Thread.Sleep(200); } long wonAmount = (long)wonAmountTemp; //remove the decimal part if (wonAmount > 0) { await _cs.AddAsync(Context.User.Id, "Wheel Of Fortune - won", wonAmount, gamble : true) .ConfigureAwait(false); } else if (wonAmount < 0) { await _cs.RemoveAsync(Context.User.Id, "Wheel Of Fortune - lost", -wonAmount, gamble : true) .ConfigureAwait(false); } using (var bgImage = Image.Load(_images.Roulette)) { var originalWidth = bgImage.Width; var originalHeight = bgImage.Height; bgImage.Mutate(x => x.Rotate(-rotation)); var widthCrop = (bgImage.Width - originalWidth) / 2; var heightCrop = (bgImage.Height - originalHeight) / 2; bgImage.Mutate(x => x.Crop(new Rectangle(widthCrop, heightCrop, originalWidth, originalHeight))); using (var ptImage = Image.Load(_images.RoulettePointer)) { var resizeOptions = new ResizeOptions(); resizeOptions.Mode = ResizeMode.Pad; resizeOptions.Position = AnchorPositionMode.TopLeft; resizeOptions.Size = new Size(originalWidth + (ptImage.Width / 2), originalHeight); bgImage.Mutate(x => x.Resize(resizeOptions)); var pointerPosX = bgImage.Width - ptImage.Width; var pointerPosY = (bgImage.Height / 2) - (ptImage.Height / 2); bgImage.Mutate(x => x.DrawImage(GraphicsOptions.Default, ptImage, new Point(pointerPosX, pointerPosY))); } using (var imgStream = bgImage.ToStream()) { string outText; long outAmount; if (wonAmount >= 0) { outText = GetText("won"); outAmount = wonAmount; } else { outText = GetText("lost"); outAmount = -wonAmount; } await Context.Channel.SendFileAsync(imgStream, "result.png", $@"{Format.Bold(Context.User.ToString())} {outText}: `{outAmount}`{Bc.BotConfig.CurrencySign}{System.Environment.NewLine}{commentary}") .ConfigureAwait(false); } } }
public Task Award(ShmartNumber amount, [Remainder] IGuildUser usr) => Award(amount, usr.Id);
public Task Award(ShmartNumber amount, IGuildUser usr, [Remainder] string msg) => Award(amount, usr.Id, msg);
public Task Give(ShmartNumber amount, [Remainder] IGuildUser receiver) => Give(amount, receiver, null);
public Task Award(ShmartNumber amount, [Leftover] IGuildUser usr) => Award(amount, usr.Id);