示例#1
0
        public ScheduledMatch GetScheduledMatch(long MatchID)
        {
            ScheduledMatch Match = new ScheduledMatch();
            SqlConnection  sql   = new SqlConnection(ConnectionString);

            using (sql)
            {
                SqlCommand command = new SqlCommand("SELECT TeamA, TeamB FROM Matches WHERE ID LIKE @MatchID", sql);
                command.Parameters.AddWithValue("@MatchID", MatchID);
                sql.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Match.TeamA = reader.GetString(0);
                    Match.TeamB = reader.GetString(1);
                }
            }
            return(Match);
        }
示例#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
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public async Task MatchOdds(long matchid)
        {
            if (sql.MatchExists(matchid))
            {
                ScheduledMatch match   = sql.GetScheduledMatch(matchid);
                List <long>    bettors = sql.GetMatchBettors(matchid);

                decimal potA = 0;
                decimal potT = 0;
                decimal potB = 0;

                foreach (long user in bettors)
                {
                    sql.GetBetMoney(user, matchid);
                    char Outcome = sql.GetBetOutcome(user, matchid);
                    if (Outcome == 'A')
                    {
                        potA = potA + sql.GetBetMoney(user, matchid);
                    }
                    else if (Outcome == 'B')
                    {
                        potB = potB + sql.GetBetMoney(user, matchid);
                    }
                    else
                    {
                        potT = potT + sql.GetBetMoney(user, matchid);
                    }
                }

                decimal totalpot = potA + potB + potT;

                if (totalpot == 0)
                {
                    await ReplyAsync(string.Format(".\n" +
                                                   " **{0}** vs **{1}** \n\n" +
                                                   // PUBLIC ODDS
                                                   ":regional_indicator_a: 0★ \n" +
                                                   ":regional_indicator_t: 0★ \n" +
                                                   ":regional_indicator_b: 0★ \n" +
                                                   "\n:moneybag: {2}★", match.TeamA, match.TeamB, totalpot));
                }
                else
                {
                    int oddsA = (int)(Math.Round(potA / totalpot, 2) * 100);
                    int oddsT = (int)(Math.Round(potT / totalpot, 2) * 100);
                    int oddsB = (int)(Math.Round(potB / totalpot, 2) * 100);

                    await ReplyAsync(string.Format(".\n" +
                                                   " **{0}** vs **{1}** \n\n" +
                                                   // PUBLIC ODDS
                                                   ":regional_indicator_a: {2}★ ({3}%) \n" +
                                                   ":regional_indicator_t: {4}★ ({5}%) \n" +
                                                   ":regional_indicator_b: {6}★ ({7}%) \n" +
                                                   "\n:moneybag: {8}★", match.TeamA, match.TeamB, potA, oddsA, potT, oddsT, potB, oddsB, totalpot));
                }
            }
            else
            {
                await ReplyAsync("Invalid match");
            }
        }