Exemplo n.º 1
0
        public async Task Tip(string amount, SocketUser user)
        {
            if (CanRunTipCommands)
            {
                if (decimal.TryParse(amount, out var decAmount))
                {
                    if (decAmount < MinimumTipValue)
                    {
                        await ReplyAsync($"Minimum tip amount is {MinimumTipValue}");

                        return;
                    }

                    if (QTCommands.CheckBalance(Context.User.Id, decAmount))
                    {
                        QTCommands.SendTip(Context.User.Id, user.Id, decAmount);
                        await ReplyAsync($"{Context.User.Mention} tipped {user.Username} {amount} {Preferences.BaseCurrency}");
                    }
                    else
                    {
                        await ReplyAsync("You do not have enough balance to tip that much!");
                    }
                }
            }
            else
            {
                await ReplyAsync($"Please use the <#{Preferences.TipBotChannel}> channel");
            }
        }
Exemplo n.º 2
0
        private void FantasyTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            var embed          = FantasyPortfolioModule.GetLeaderboardEmbed();
            var winner         = FantasyPortfolioModule.GetWinner();
            var additionalText = "";

            TimeSpan span = (Round.CurrentRoundEnd - DateTime.Now);

            if (Round.CurrentRoundEnd <= DateTime.Now)
            {
                Console.WriteLine($"Round {Round.CurrentRoundEnd} Finished. Winner: {winner.UserId}");
                using (var context = new FantasyPortfolio_DBEntities()) {
                    if (context.Leaderboards.Any(d => d.RoundId == Round.CurrentRound))
                    {
                        if (FantasyPortfolioModule.PrizePool > 0)
                        {
                            additionalText = $"Congratulations <@{winner.UserId}>! You have won the fantasy portfolio and won {FantasyPortfolioModule.PrizePool} {Preferences.BaseCurrency}";
                            QTCommands.SendTip(_client.CurrentUser.Id, ulong.Parse(winner.UserId), FantasyPortfolioModule.PrizePool);
                        }
                        else
                        {
                            additionalText = $"Congratulations <@{winner.UserId}>! You have won the fantasy portfolio! There was no prize.";
                        }
                    }
                    else
                    {
                        embed.WithDescription("Round has finished! There were no participants in this round, so nobody wins!");
                    }
                    Round round = new Round {
                        RoundEnds = DateTime.Now.AddDays(Round.RoundDurationDays)
                    };
                    context.Rounds.Add(round);
                    context.SaveChanges();
                }
            }
            else if (span.TotalMilliseconds < fantasyTickerTimer.Interval)
            {
                //Set next interval to 5000ms after the round ends
                fantasyTimer.Interval = span.TotalMilliseconds + 5000;
                Console.WriteLine("Next fantasy interval set to 5 seconds");
            }
            else
            {
                // Set the next interval to 2 hours
                fantasyTickerTimer.Interval = 7200000;
                Console.WriteLine("Next fantasy interval set to 2 hours");
            }
            _client.GetGuild(Settings.Default.GuildId).GetTextChannel(Settings.Default.FantasyChannel).SendMessageAsync(additionalText, false, embed);
        }
Exemplo n.º 3
0
 private string SendRain(SocketUser fromUser, List <SocketGuildUser> tipUsers, decimal amount)
 {
     if (QTCommands.CheckBalance(fromUser.Id, amount))
     {
         if (amount / tipUsers.Count < (decimal)0.01)
         {
             return($"Rain amount must be at least 0.01 {Preferences.BaseCurrency} per person");
         }
         foreach (var person in tipUsers)
         {
             QTCommands.SendTip(Context.User.Id, person.Id, Math.Round(amount / tipUsers.Count, 7));
         }
         var mentionList = new List <string>();
         foreach (var users in tipUsers)
         {
             mentionList.Add($"{DiscordClientNew._client.GetUser(users.Id).Mention}");
         }
         return($"{fromUser.Mention} made it rain :cloud_rain:! Congratulations to {(mentionList.Count == 2 ? string.Join(" and ", mentionList) : string.Join(", ", mentionList))} who {(mentionList.Count > 1 ? "have" : "has")} been awarded {Math.Round(amount / mentionList.Count, 7)} {Preferences.BaseCurrency} {(mentionList.Count > 1 ? "each" : "")}");
     }
     return("You do not have enough balance to perform this rain");
 }
Exemplo n.º 4
0
 public async Task Join()
 {
     if (FantasyPortfolioModule.EntryFee == 0 || QTCommands.CheckBalance(Context.User.Id, FantasyPortfolioModule.EntryFee))
     {
         if (FantasyPortfolioModule.EntryFee > 0)
         {
             QTCommands.SendTip(Context.User.Id, DiscordClientNew._client.CurrentUser.Id, FantasyPortfolioModule.EntryFee);
         }
         if (Portfolio.Join(Context.User.Id.ToString()))
         {
             await ReplyAsync($"You have joined round {Round.CurrentRound}. An entry fee of {FantasyPortfolioModule.EntryFee} {Preferences.BaseCurrency} has been taken.");
         }
         else
         {
             await ReplyAsync("You have already joined this round!");
         }
     }
     else
     {
         await ReplyAsync($"You do not have the required entry fee of {FantasyPortfolioModule.EntryFee} {Preferences.BaseCurrency}. Please send some {Preferences.BaseCurrency} to your tipping account and try again.");
     }
 }
Exemplo n.º 5
0
        public async Task RockPaperScissorsGame(string rps, string amount)
        {
            if (CanRunTipCommands)
            {
                if (Enum.TryParse(rps.ToLower(), out RockPaperScissors userDecision))
                {
                    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(DiscordClientNew._client.CurrentUser.Id, rewardValue + FantasyPortfolioModule.PrizePool))
                            {
                                QTCommands.SendTip(Context.User.Id, DiscordClientNew._client.CurrentUser.Id, betAmount);
                                try {
                                    var botDecision = (RockPaperScissors)RandomInteger(0, 3);

                                    var embed = new EmbedBuilder();

                                    string message = "";

                                    var userOutcome = new Outcome();

                                    switch (botDecision)
                                    {
                                    case RockPaperScissors.rock: {
                                        switch (userDecision)
                                        {
                                        case RockPaperScissors.rock:
                                            userOutcome = Outcome.draw;
                                            break;

                                        case RockPaperScissors.paper:
                                            userOutcome = Outcome.win;
                                            break;

                                        case RockPaperScissors.scissors:
                                            userOutcome = Outcome.lose;
                                            break;
                                        }
                                        break;
                                    }

                                    case RockPaperScissors.paper: {
                                        switch (userDecision)
                                        {
                                        case RockPaperScissors.rock:
                                            userOutcome = Outcome.lose;
                                            break;

                                        case RockPaperScissors.paper:
                                            userOutcome = Outcome.draw;
                                            break;

                                        case RockPaperScissors.scissors:
                                            userOutcome = Outcome.win;
                                            break;
                                        }
                                        break;
                                    }

                                    case RockPaperScissors.scissors: {
                                        switch (userDecision)
                                        {
                                        case RockPaperScissors.rock:
                                            userOutcome = Outcome.win;
                                            break;

                                        case RockPaperScissors.paper:
                                            userOutcome = Outcome.lose;
                                            break;

                                        case RockPaperScissors.scissors:
                                            userOutcome = Outcome.draw;
                                            break;
                                        }
                                        break;
                                    }
                                    }

                                    switch (userOutcome)
                                    {
                                    case Outcome.win:
                                        QTCommands.SendTip(DiscordClientNew._client.CurrentUser.Id, Context.User.Id, rewardValue);
                                        embed.AddInlineField("Outcome", $"Bot opted for {botDecision.ToString()} whereas you opted for {userDecision.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}!";
                                        break;

                                    case Outcome.draw:
                                        QTCommands.SendTip(DiscordClientNew._client.CurrentUser.Id, Context.User.Id, betAmount);
                                        embed.AddInlineField("Outcome", $"Bot opted for {botDecision.ToString()} whereas you opted for {userDecision.ToString()}");
                                        embed.WithColor(Discord.Color.Gold);
                                        message = "It was a draw! Bet refunded";
                                        break;

                                    case Outcome.lose:
                                        QTCommands.SendTip(DiscordClientNew._client.CurrentUser.Id, Context.User.Id, betAmount);
                                        embed.AddInlineField("Outcome", $"Bot opted for {botDecision.ToString()} whereas you opted for {userDecision.ToString()}");
                                        embed.AddInlineField("Prize", $"{rewardValue} {Preferences.BaseCurrency}");
                                        embed.AddInlineField("Profit", $"{(rewardValue - betAmount)} {Preferences.BaseCurrency}");
                                        embed.WithColor(Discord.Color.Red);
                                        message = "Unlucky! You lose! Bot won";
                                        break;
                                    }
                                    embed.WithFooter(Preferences.FooterText);
                                    await ReplyAsync(message, false, embed);

                                    Console.WriteLine($"{Context.User.Id} ({Context.User.Username}) opted for {userDecision} and bot opted for {botDecision}");
                                }
                                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");
            }
        }
Exemplo n.º 6
0
        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");
            }
        }