Exemplo n.º 1
0
        //TODO pass bet object
        public void MakeBet(bet bet)
        {
            SqlConnection sql = new SqlConnection(ConnectionString);

            if (bet.Score != null)
            {
                using (sql)
                {
                    SqlCommand Command = new SqlCommand("INSERT INTO Bets (UserID, MatchID, BetMoney, Outcome, Score) VALUES (@UserID, @MatchID, @BetMoney, @Outcome, @Score)", sql);
                    Command.Parameters.AddWithValue("@UserID", bet.UserID);
                    Command.Parameters.AddWithValue("@MatchID", bet.MatchID);
                    Command.Parameters.AddWithValue("@BetMoney", bet.Money);
                    Command.Parameters.AddWithValue("@Score", bet.Score);
                    Command.Parameters.AddWithValue("@Outcome", bet.Outcome);
                    sql.Open();
                    Command.ExecuteNonQuery();
                }
            }
            else
            {
                using (sql)
                {
                    SqlCommand Command = new SqlCommand("INSERT INTO Bets (UserID, MatchID, BetMoney, Outcome) VALUES (@UserID, @MatchID, @BetMoney, @Outcome)", sql);
                    Command.Parameters.AddWithValue("@UserID", bet.UserID);
                    Command.Parameters.AddWithValue("@MatchID", bet.MatchID);
                    Command.Parameters.AddWithValue("@BetMoney", bet.Money);
                    Command.Parameters.AddWithValue("@Outcome", bet.Outcome);
                    sql.Open();
                    Command.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 2
0
        public async Task Bet(long MatchID, string Score, decimal Money)
        {
            //await Context.Message.DeleteAsync();  // SECRET
            long ID = (long)Context.User.Id;

            if (!sql.UserExists(ID))
            {
                await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " you have to register before betting");
            }
            else
            {
                if (!(Score.Length == 3 && char.IsDigit(Score[0]) && char.IsDigit(Score[2]) && Score[1] == '-'))
                {
                    await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " invalid score format");
                }
                else
                {
                    // make bet object
                    bet bet = new bet(ID, MatchID, Score, Money);

                    if (!sql.HasEnoughMoney(ID, Money))
                    {
                        await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " you don't have enough money to make that bet");
                    }
                    else
                    {
                        if (Money <= 0)
                        {
                            await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " invalid number");
                        }
                        else
                        {
                            if (!sql.MatchExists(MatchID))
                            {
                                await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " invalid match");
                            }
                            else
                            {
                                if (sql.IsMatchLive(MatchID))
                                {
                                    await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " you can't bet during a live match baka desu senpai");
                                }
                                else
                                {
                                    if (sql.BetExists(ID, MatchID))
                                    {
                                        await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " you already bet on that match");
                                    }
                                    else
                                    {
                                        // FINALS
                                        if (MatchID == 28)
                                        {
                                            bet.Money += 125;
                                            sql.MakeBet(bet);
                                            sql.SubstractMoney(ID, Money);
                                            sql.AddMoneyBet(ID, Money);
                                            await ReplyAsync(MentionUtils.MentionUser(Context.User.Id) + " FINALS MADNESS! You succesfully placed your bet and we added 125★ to it for free!");
                                        }
                                        else
                                        {
                                            sql.MakeBet(bet);
                                            sql.SubstractMoney(ID, Money);
                                            sql.AddMoneyBet(ID, Money);
                                            ScheduledMatch sm = sql.GetScheduledMatch(MatchID);
                                            //await ReplyAsync(string.Format("{0} bet placed on **{1}** vs **{2}**", MentionUtils.MentionUser(Context.User.Id), sm.TeamA, sm.TeamB));   // Secret
                                            await ReplyAsync(string.Format("{0} bet {3}★ on **{1}** vs **{2}**", MentionUtils.MentionUser(Context.User.Id), sm.TeamA, sm.TeamB, Money));// Public
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }