public async Task FlipStats() { var statistics = FlipResults.GetStatistics(); var embed = new EmbedBuilder(); embed.WithTitle("Flip Statistics"); if (statistics == null) { embed.WithDescription("No coin flip statistics to show yet."); } else { embed.AddInlineField("Total Flips", statistics.TotalFlips); embed.AddInlineField("Wins", statistics.Wins); embed.AddInlineField("Losses", statistics.Losses); embed.AddInlineField("Total Flipped", $"{Math.Round((decimal)statistics.TotalFlipped, 2)} {Preferences.BaseCurrency}"); embed.AddInlineField("User Winnings", $"{Math.Round((decimal)statistics.PaidOut, 2)} {Preferences.BaseCurrency}"); embed.AddInlineField("Bot Winnings", $"{Math.Round((decimal)statistics.PaidIn, 2)} {Preferences.BaseCurrency}"); embed.AddInlineField("Win Percentage", Math.Round((decimal)statistics.WinPercentage * 100, 2) + "%"); embed.AddInlineField("Head Flips", statistics.HeadFlips); embed.AddInlineField("Tail Flips", statistics.TailFlips); } await ReplyAsync("", false, embed); }
public async Task Flip(string side, string amount) { if (CanRunTipCommands) { if (Enum.TryParse(side.ToLower(), out CoinSide coinSide)) { if (decimal.TryParse(amount, out var betAmount)) { if (QTCommands.CheckBalance(Context.User.Id, betAmount)) { if (betAmount < MinBetAmount) { await ReplyAsync($"Minimum bet {MinBetAmount} {Preferences.BaseCurrency}"); return; } decimal balance = 0; var houseBalanceCall = QTCommands.GetBalance(Context.Client.CurrentUser.Id).Result; decimal.TryParse(houseBalanceCall, out balance); decimal maxBet = balance / 10; if (betAmount > maxBet) { await ReplyAsync($"Maximum bet exceeded. Max: {maxBet} {Preferences.BaseCurrency}"); return; } var rewardValue = betAmount * (decimal)BetWin; if (QTCommands.CheckBalance(Context.Client.CurrentUser.Id, rewardValue + FantasyPortfolioModule.PrizePool)) { QTCommands.SendTip(Context.User.Id, Context.Client.CurrentUser.Id, betAmount); try { var coin = (CoinSide)RandomInteger(0, 2); //var coin = (CoinSide)Generator.Next(0, 2); var embed = new EmbedBuilder(); string message; if (coin == coinSide) { QTCommands.SendTip(DiscordClientNew._client.CurrentUser.Id, Context.User.Id, rewardValue); embed.AddInlineField("Flipped", FirstCharToUpper(coin.ToString())); embed.AddInlineField("Prize", $"{rewardValue} {Preferences.BaseCurrency}"); embed.AddInlineField("Profit", $"{(rewardValue - betAmount)} {Preferences.BaseCurrency}"); embed.WithColor(Discord.Color.Green); message = $"You won! Congratulations {Context.User.Mention}!"; } else { embed.AddInlineField("Flipped", FirstCharToUpper(coin.ToString())); embed.AddInlineField("Lost", $"{betAmount} {Preferences.BaseCurrency}"); embed.WithColor(Discord.Color.Red); message = $"Unlucky {Context.User.Mention}, you lost :("; } embed.WithFooter(Preferences.FooterText); await ReplyAsync(message, false, embed); using (var context = new FantasyPortfolio_DBEntities()) { var result = new FlipResults(); result.DateTime = DateTime.Now; result.UserId = Context.User.Id.ToString(); result.FlipResult = (byte)coin; result.UserFlip = (byte)coinSide; result.FlipValue = betAmount; context.FlipResults.Add(result); context.SaveChanges(); } Console.WriteLine($"{Context.User.Id} ({Context.User.Username}) bet on {side} and flipped {coin}"); } catch (Exception e) { Console.WriteLine(e.Message); QTCommands.SendTip(DiscordClientNew._client.CurrentUser.Id, Context.User.Id, betAmount); await ReplyAsync("Sorry something went wrong. You have been refunded your bet."); } } else { await ReplyAsync("Sorry, the bot is too poor to reward you if you won :("); } } else { await ReplyAsync("You do not have enough balance to perform this action"); } } } } else { await ReplyAsync($"Please use the <#{Preferences.TipBotChannel}> channel"); } }