Example #1
0
        public IEnumerable <LeagueStats> CalculateLeagueStats(IList <Team> teams)
        {
            IList <LeagueStats> leagueStats = new List <LeagueStats>();

            foreach (var team in teams)
            {
                var stats = new LeagueStats();
                stats.TeamName      = team.Name;
                stats.TotalPins     = team.Scores.Sum(x => x.Pins);
                stats.TotalHandicap = team.Scores.Sum(x => x.Handicap);
                leagueStats.Add(stats);
            }

            var leagueStatsByPins = leagueStats.OrderByDescending(x => x.TotalPins).ToList();
            int position          = 1;

            foreach (var team in leagueStatsByPins)
            {
                team.Position = position;
                position++;
            }


            return(leagueStats.OrderBy(x => x.Position));
        }
        public LeagueStats LastYearsStats(
            string leagueCode)
        {
            var totalScore = 0;
            var totalGames = 0;
            var scoreDict  = new SortedDictionary <int, int>();

            foreach (var item in LeaguePastResults[leagueCode])
            {
                var games = item.Value;
                //Console.WriteLine($"Round {item.Key} has {games.Count} games");
                foreach (var g in games)
                {
                    totalGames++;
                    totalScore += g.HomeScore;
                    totalScore += g.AwayScore;
                    AddScore(scoreDict, g.HomeScore);
                    AddScore(scoreDict, g.AwayScore);
                }
                //if (!(totalGames == (item.Key * 8)))
                //    Console.WriteLine("error");
            }
            decimal averageGamePoints = (decimal)totalScore / totalGames;
            var     stats             = new LeagueStats
            {
                League           = leagueCode,
                TotalPoints      = totalScore,
                TotalGames       = totalGames,
                TeamScoreAverage = (int)Math.Round(averageGamePoints / 2.0M),
                TeamScoreMode    = ScoreMode(scoreDict)
            };

            return(stats);
        }
Example #3
0
        public static void UpdateLeagueStats(LeagueStats LS)
        {
            string strToSend = JsonConvert.SerializeObject(LS);

            WebClient wc = new WebClient();

            wc.QueryString.Add("pin", pin.ToString());
            wc.QueryString.Add("StatName", "league_stats");
            wc.QueryString.Add("jsonData", strToSend);

            var data = wc.UploadValues(url + "statUpdate.php", "POST", wc.QueryString);
        }
Example #4
0
        private static void Pf_CompletedSuccessfully()
        {
            Console.WriteLine("Update completed Sucessfully.");

            // Set update delay and restart timer.
            Console.WriteLine("Updating at " + DateTime.Now.AddMilliseconds(updateIntervalAfterCompletion) + ".");
            pf.PagingDelay = 0;
            timer.Interval = updateIntervalAfterCompletion;
            timer.Start();

            //If ladder empty do nothing
            if (pf.Lf.ladder.entries.Count() == 0)
            {
                return;
            }

            // Save data to file.
            PoeFilesControl.SaveToFile(pf.Lf);

            // Get different data objects for statistics/reporting.
            LeagueInfo         data      = pf.Lf;
            List <AccountInfo> accInfo   = StatsGenerator.GetAccountsInfo(data);
            List <string>      namesList = StatsGenerator.ListOfAccMultipleCharsAlive(accInfo);

            // Report owners of multiple alive characters.
            PTLiveReporter.ReportMultipleAliveChars(namesList);
            Console.WriteLine("Accounts with multiple alive characters reported to web service.");

            // Get classes info.
            List <ClassInfo> x = StatsGenerator.GetClassesInfo(data);
            // Sort by popularity.
            List <ClassInfo> orderedByPopularity = x.OrderByDescending(d => d.totalChars).ToList <ClassInfo>();

            // Update ascendacy classes info
            PTLiveReporter.UpdateAscendancyClasses(orderedByPopularity);
            Console.WriteLine("Ascendancy classes info sent to server.");

            // Get league statistics.
            LeagueStats LS = StatsGenerator.GenerateLeagueStats(pf.Lf, (3600000 / updateIntervalAfterCompletion) + 2);

            // Send league statistics
            PTLiveReporter.UpdateLeagueStats(LS);
            Console.WriteLine("General league stats sent to server.");

            // Update rips counter
            PTLiveReporter.UpdateRipsCounter(LS.DeadCharacters);
            Console.WriteLine("Rips Counter updated.");

            // Increase Updates Counter
            UpdatesCount++;
        }
Example #5
0
    //public class PlayerStats
    //{
    //    public Dictionary<int, List<byte>> BestScoresByHole;
    //    public Dictionary<int, List<byte>> WorstScoresByHole;
    //    public Dictionary<int, List<decimal>> AverageScoresByHole;

    //    public int bestNineHoleScore;
    //    public int worstNineHoleScore;

    //    public Dictionary<int, int> ScoreByEvent; //Key:LeagueEvent, Value: Score
    //    //Dictionary<int, Decimal> HandicapByEvent;

    //    public void initialize()
    //    {
    //         BestScoresByHole = new Dictionary<int, List<byte>>();
    //         WorstScoresByHole = new Dictionary<int, List<byte>>();
    //         AverageScoresByHole = new Dictionary<int,List<decimal>>();

    //        ScoreByEvent = new Dictionary<int,int>();
    //       // Dictionary<int, Decimal> HandicapByEvent = new Dictionary<int,decimal>();
    //    }
    //}

    //public static Dictionary<int, decimal> SortDictionaryByAscendingValue(Dictionary<int, decimal> dictionary)
    //{
    //    var items = from pair in dictionary
    //                orderby pair.Value ascending
    //                select pair;

    //    Dictionary<int, decimal> retVal = new Dictionary<int, decimal>();
    //}


    public static LeagueStats GetSeasonStats(int LeagueID, int SeasonID, List <int> CourseIDs)
    {
        LeagueStats retVal = new LeagueStats();

        //playerStats = new Dictionary<int,PlayerStats>();
        retVal.initialize();

        Dictionary <int, string> golfers = DatabaseFunctions.GetGolferNamesAndIDs(LeagueID.ToString());
        var  settings        = DatabaseFunctions.GetLeagueSettings(LeagueID);
        bool useCurrentRound = settings.ContainsKey("UseCurrentRoundForHandicap") ? bool.Parse(settings["UseCurrentRoundForHandicap"]) : true;

        useCurrentRound = true;
        retVal.SetupDictionaries(CourseIDs, golfers.Keys.ToList());
        retVal.handicaps = GetHandicaps(LeagueID, useCurrentRound);

        //InitializeDictionaries(CourseIDs, golfers.Keys,
        //retVal.Birdies, retVal.Pars, retVal.Bogeys,
        //retVal.DoubleBogeys, retVal.TripleOrWorse, retVal.AvgScores, retVal.NumberOfEventsPlayed,
        //retVal.NumRoundsByGolferAndCourse, retVal.NumberOfRoundsPlayedByCourse,
        //Dictionary<int, List<byte>> LeagueRingerNineByCourse, Dictionary<int, List<Decimal>> LeagueHoleAveragesByCourse, Dictionary<int, List<byte>> LeagueHighHoleScoresByCourse)


        Dictionary <int, EventInfo> events = DatabaseFunctions.GetEventsWithScoresPosted(LeagueID, SeasonID);

        foreach (int LeagueEventID in events.Keys)
        {
            //Dictionary<int, int> matchups = DatabaseFunctions.GetMatchups(LeagueEventID);

            Dictionary <int, List <byte> > scores = DatabaseFunctions.GetScores(LeagueEventID);
            CourseInfo courseInfo = DatabaseFunctions.GetCourseInfo(LeagueEventID);

            List <int> eventSkins = calculateSkins(scores);
            int        holeIndex  = 0;
            foreach (int GolferID in eventSkins)
            {
                if (GolferID != 0)
                {
                    retVal.Skins[GolferID]++;
                    retVal.SkinsByCourseID[courseInfo.CourseID][GolferID][holeIndex]++;
                }
                holeIndex++;
            }

            //Dictionary<int, int> handicaps = GetPlayerHandicapsForEvent(LeagueEventID, scores.Keys.ToList());

            //Dictionary<int, int> subs = DatabaseFunctions.GetSubs(LeagueEventID);
            //List<int> noShows = DatabaseFunctions.GetNoShows(LeagueEventID);
            //Dictionary<int, int> handicaps = DatabaseFunctions.GetHandicapOverrides(LeagueEventID);
            //int Team1PlayerA_ID, Team1PlayerB_ID, Team2PlayerA_ID, Team2PlayerB_ID;
            //Add No shows to Handicaps and scores
            //scores.Add(0, Scoring.GetNoShowScores(courseInfo));
            //handicaps.Add(0, 0);

            int index = 0;
            //foreach matchup
            foreach (int GolferID in scores.Keys)
            {
                //if(!playerStats.ContainsKey(GolferID))
                //{
                //    PlayerStats newPlayerStats = new PlayerStats();
                //    newPlayerStats.initialize();
                //    playerStats.Add(GolferID, newPlayerStats);
                //}
                //ModifyHoleByHoleScores(courseInfo.CourseID, GolferID, scores[GolferID], retVal.NumRoundsByGolferAndCourse, retVal.NumberOfRoundsPlayedByCourse, playerStats[GolferID].BestScoresByHole, playerStats[GolferID].WorstScoresByHole, playerStats[GolferID].AverageScoresByHole, retVal.LeagueRingerNineByCourse, retVal.LeagueHoleAveragesByCourse, retVal.LeagueHighScoreByCourse);
                retVal.ModifyHoleByHoleScores(courseInfo.CourseID, GolferID, scores[GolferID]);
                //int totalScore = ComputeParStatsAndTotalScore(courseInfo, GolferID, scores[GolferID], retVal.Birdies, retVal.Pars, retVal.Bogeys, retVal.DoubleBogeys, retVal.TripleOrWorse, retVal.AvgScores, retVal.NumberOfEventsPlayed);
                retVal.ComputeParStatsAndTotalScore(courseInfo, GolferID, LeagueEventID, scores[GolferID], retVal.handicaps[GolferID][LeagueEventID]);


                //if (playerStats[GolferID].bestNineHoleScore > totalScore)
                //{
                //    playerStats[GolferID].bestNineHoleScore = totalScore;
                //}

                //if (playerStats[GolferID].worstNineHoleScore > totalScore)
                //{
                //    playerStats[GolferID].worstNineHoleScore = totalScore;
                //}
            }
        }

        return(retVal);
    }
Example #6
0
        /// <summary>
        /// Adds all commands to the commandservice.
        /// </summary>
        private void AddAllCommands()
        {
            #region Help Commands
            commands.CreateCommand("help").Do(async(e) =>
            {
                string serverName = "servers";
                if (e.Server != null)
                {
                    serverName = e.Server.Name;
                }
                string output = String.Format("Helpful commands for {0} in {1}. (NOTE: Lowercase is key!)", client.CurrentUser.Name, serverName)
                                + "``` \n"
                                + "Command".PadRight(20) + "Description" + "\n" + "\n"
                                + String.Format("{0}help", Properties.Default.prefix).PadRight(20) + "Displays this message again with commands. \n"
                                + String.Format("{0}gambling", Properties.Default.prefix).PadRight(20) + "Shows all the gambling commands. \n"
                                + String.Format("{0}league", Properties.Default.prefix).PadRight(20) + "Shows all the league commands. \n"
                                + String.Format("{0}roles", Properties.Default.prefix).PadRight(20) + "Shows all the roles commands. \n"
                                + String.Format("{0}admin", Properties.Default.prefix).PadRight(20) + "Shows all the admin commands. \n"
                                + "```";
                await e.User.SendMessage(output);
            });

            commands.CreateCommand("admin").Do(async(e) =>
            {
                string output = "Commands regarding Admin, can only be used by people with administrator privileges. (NOTE: Lowercase is key!)"
                                + "``` \n"
                                + "Command".PadRight(35) + "Description".PadRight(85) + "Example" + "\n" + "\n"
                                + String.Format("{0}addcommand <command> <response>", Properties.Default.prefix).PadRight(35)
                                + "Add a command to the current instance of SmellyBot, will be lost after reconnecting.".PadRight(85)
                                + String.Format("Example: {0}command sayhi Hi!", Properties.Default.prefix) + "\n"
                                + String.Format("{0}save", Properties.Default.prefix).PadRight(35)
                                + "Permanently saves the changes to bot settings.".PadRight(85) + "\n"
                                + String.Format("{0}disconnect", Properties.Default.prefix).PadRight(35)
                                + "Disconnects SmellyBot from the server.".PadRight(85) + "\n"
                                + String.Format("{0}setgame <status>", Properties.Default.prefix).PadRight(35)
                                + "Sets the status of this SmellyBot instance. Displays as: 'Playing <status>'".PadRight(85)
                                + String.Format("Example: {0}setgame something", Properties.Default.prefix) + "\n"
                                + String.Format("{0}clear", Properties.Default.prefix).PadRight(35)
                                + "Clears all of SmellyBot's messages in this channel.".PadRight(85) + "\n"
                                + String.Format("{0}clear", Properties.Default.prefix).PadRight(35)
                                + "Clears every message in this channel.".PadRight(85) + "\n"
                                + String.Format("{0}toggleall", Properties.Default.prefix).PadRight(35)
                                + "Toggles all events showing in chat. Turns them on if currently off and the opposite.".PadRight(85)
                                + String.Format("Example: {0}toggleall", Properties.Default.prefix) + "\n"
                                + String.Format("{0}toggleuser <channel> <channel>", Properties.Default.prefix).PadRight(35)
                                + "Toggles the user events. Optional parameters for channels.".PadRight(85)
                                + String.Format("Example: {0}toggleuser announcements events", Properties.Default.prefix) + "\n"
                                + String.Format("{0}togglerole <channel> <channel>", Properties.Default.prefix).PadRight(35)
                                + "Toggles the role events. Optional parameters for channels.".PadRight(85)
                                + String.Format("Example: {0}togglerole announcements events", Properties.Default.prefix) + "\n"
                                + String.Format("{0}togglechannel <channel> <channel>", Properties.Default.prefix).PadRight(35)
                                + "Toggles the channel events. Optional parameters for channels.".PadRight(85)
                                + String.Format("Example: {0}togglechannel announcements events", Properties.Default.prefix) + "\n"
                                + "```";
                await e.User.SendMessage(output);
            });

            commands.CreateCommand("gambling").Do(async(e) =>
            {
                string output = "Commands regarding Gambling. (NOTE: Lowercase is key!)"
                                + "``` \n"
                                + "Command".PadRight(25) + "Description".PadRight(60) + "Example" + "\n" + "\n"
                                + String.Format("{0}roll <min>-<max>", Properties.Default.prefix).PadRight(25)
                                + "Rolls a random number between the given minimum & maximum.".PadRight(60)
                                + String.Format("Example: {0}roll 1-100", Properties.Default.prefix) + "\n"
                                + String.Format("{0}slots <betAmount>", Properties.Default.prefix).PadRight(25)
                                + "Generates a play on a slotmachine.".PadRight(60)
                                + String.Format("Example: {0}slots 25", Properties.Default.prefix) + "\n"
                                + String.Format("{0}startgambling", Properties.Default.prefix).PadRight(25)
                                + "Registers an account at SmellyBank to start gambling.".PadRight(60) + "\n"
                                + String.Format("{0}checkcash", Properties.Default.prefix).PadRight(25)
                                + "Checks the balance of your account at SmellyBank.".PadRight(60) + "\n"
                                + "```";
                await e.User.SendMessage(output);
            });

            commands.CreateCommand("league").Do(async(e) =>
            {
                string output = "Commands regarding League of Legends. (NOTE: Lowercase is key!)"
                                + "``` \n"
                                + "Command".PadRight(45) + "Description".PadRight(75) + "Example" + "\n" + "\n"
                                + String.Format("{0}level <region> <summoner>", Properties.Default.prefix).PadRight(45)
                                + "Shows the level of the summoner in the region.".PadRight(75)
                                + String.Format("Example: {0}level euw ChallengerJanna", Properties.Default.prefix) + "\n"
                                + String.Format("{0}rank <region> <summoner>", Properties.Default.prefix).PadRight(45)
                                + "Shows the rank(s) of the summoner in the region.".PadRight(75)
                                + String.Format("Example: {0}rank kr hide on bush", Properties.Default.prefix) + "\n"
                                + String.Format("{0}rankedstats <region> <champion> <summoner>", Properties.Default.prefix).PadRight(45)
                                + "Shows ranked stats of the summoner in the region for a champion.".PadRight(75)
                                + String.Format("Example: {0}rankedstats na draven DravenMasterX", Properties.Default.prefix) + "\n"
                                + String.Format("{0}winrate <region> <summoner>", Properties.Default.prefix).PadRight(45)
                                + "Shows ranked winrate of the summoner in the region.".PadRight(75)
                                + String.Format("Example: {0}winrate eune Argloud", Properties.Default.prefix) + "\n"
                                + String.Format("{0}currentgame <region> <summoner>", Properties.Default.prefix).PadRight(45)
                                + "Displays the current game that the summoner in the region is playing.".PadRight(75)
                                + String.Format("Example: {0}currentgame na xxRivenMaster98xx", Properties.Default.prefix) + "\n"
                                + String.Format("{0}status <region>", Properties.Default.prefix).PadRight(45)
                                + "Checks the status of the requested region.".PadRight(75)
                                + String.Format("Example: {0}status euw", Properties.Default.prefix) + "\n"
                                + String.Format("{0}stats <champion>", Properties.Default.prefix).PadRight(45)
                                + "Fetches information for the champion.".PadRight(75)
                                + String.Format("Example: {0}stats Nami", Properties.Default.prefix) + "\n"
                                + String.Format("{0}counter <champion>", Properties.Default.prefix).PadRight(45)
                                + "Shows Riot's tips for playing against a certain champion.".PadRight(75)
                                + String.Format("Example: {0}counter Draven", Properties.Default.prefix) + "\n"
                                + String.Format("{0}howto <champion>", Properties.Default.prefix).PadRight(45)
                                + "Shows Riot's tips for playing a certain champion.".PadRight(75)
                                + String.Format("Example: {0}howto Yasuo", Properties.Default.prefix) + "\n"
                                + String.Format("{0}lore <champion>", Properties.Default.prefix).PadRight(45)
                                + "Displays the lore of a champion.".PadRight(75)
                                + String.Format("Example: {0}lore Teemo", Properties.Default.prefix) + "\n"
                                + "```";
                await e.User.SendMessage(output);
            });

            commands.CreateCommand("roles").Do(async(e) =>
            {
                string output = "Commands regarding Roles. (NOTE: Lowercase is key!)"
                                + "``` \n"
                                + "Command".PadRight(30) + "Description".PadRight(50) + "Example" + "\n" + "\n"
                                + String.Format("{0}assignrole <role1> <role2>", Properties.Default.prefix).PadRight(30)
                                + "Assigns the requested role(s) to the user.".PadRight(50)
                                + String.Format("Example: {0}assignrole Bot", Properties.Default.prefix) + "\n"
                                + String.Format("{0}removerole <role1> <role2>", Properties.Default.prefix).PadRight(30)
                                + "Removes the mentioned role(s) from the user.".PadRight(50)
                                + String.Format("Example: {0}removerole Bot", Properties.Default.prefix) + "\n"
                                + "```";
                await e.User.SendMessage(output);
            });
            #endregion
            #region Admin Commands
            #region Toggle Events
            commands.CreateCommand("toggleall").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    Properties.Default.userEvents    = !Properties.Default.userEvents;
                    Properties.Default.channelEvents = !Properties.Default.channelEvents;
                    Properties.Default.roleEvents    = !Properties.Default.roleEvents;
                    await e.Channel.SendMessage(ToggleEvents(eventType.user));
                    await e.Channel.SendMessage(ToggleEvents(eventType.channel));
                    await e.Channel.SendMessage(ToggleEvents(eventType.role));
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });

            commands.CreateCommand("toggleuser").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    Properties.Default.userEvents = !Properties.Default.userEvents;
                    await e.Channel.SendMessage(ToggleEvents(eventType.user));
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });

            commands.CreateCommand("togglechannel").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    Properties.Default.channelEvents = !Properties.Default.channelEvents;
                    await e.Channel.SendMessage(ToggleEvents(eventType.channel));
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });

            commands.CreateCommand("togglerole").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    Properties.Default.roleEvents = !Properties.Default.roleEvents;
                    await e.Channel.SendMessage(ToggleEvents(eventType.role));
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });

            commands.CreateCommand("toggleuser").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    await ToggleSpecificEvent(e);
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });

            commands.CreateCommand("togglechannel").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    await ToggleSpecificEvent(e);
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });

            commands.CreateCommand("togglerole").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    await ToggleSpecificEvent(e);
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });
            #endregion
            #region Create Basic Command
            commands.CreateCommand("addcommand").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    await AddCommand(e);
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });
            #endregion
            #region Save Changes To Properties.
            commands.CreateCommand("save").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    Properties.Default.Save();
                    Console.WriteLine("Property changes saved.");
                    await e.Channel.SendMessage("The changes to the settings file were saved!");
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });
            #endregion
            #region Disconnect Command
            commands.CreateCommand("disconnect").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    this.casino.WriteAllGamblers();
                    await e.Channel.SendMessage(string.Format("{0} signing out.", client.CurrentUser.Name));
                    System.Threading.Thread.Sleep(500);
                    await client.Disconnect();
                    Dispose();
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });
            #endregion
            #region Set SmellyBot's Game
            commands.CreateCommand("setgame").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    string game = "";
                    foreach (string s in Utils.ReturnInputParameterStringArray(e))
                    {
                        game += s.PadRight(1);
                    }
                    client.SetGame(game);
                    Console.WriteLine(String.Format("Changed status to {0}", game));
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });
            #endregion
            #region Delete Channel Messages
            commands.CreateCommand("clear").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    List <Message> toRemoveMessages = new List <Message>();

                    foreach (Message m in await e.Channel.DownloadMessages())
                    {
                        //If SmellyBot sent the message, it will be added to the list.
                        if (m.IsAuthor)
                        {
                            toRemoveMessages.Add(m);
                            continue;
                        }
                        //Also removes the messages that ask for clears.
                        else if (m.Text.Equals(String.Format("{0}clear", Properties.Default.prefix)))
                        {
                            toRemoveMessages.Add(m);
                        }
                    }

                    await e.Channel.DeleteMessages(toRemoveMessages.ToArray());
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });
            commands.CreateCommand("clearall").Do(async(e) =>
            {
                if (e.User.ServerPermissions.Administrator)
                {
                    await e.Channel.DeleteMessages(await e.Channel.DownloadMessages());
                }
                else
                {
                    await e.Channel.SendMessage("You do not have sufficient permissions to use this command.");
                }
            });
            #endregion
            #endregion
            #region Gambling
            commands.CreateCommand("checkcash").Do(async(e) =>
            {
                if (this.casino == null)
                {
                    this.casino = new Casino();
                    this.casino.FetchGamblers();
                }

                Int64 cash = this.casino.GetCash(e.User.Name);

                if (cash != -1)
                {
                    await e.Channel.SendMessage(String.Format("{0} has a total of {1} SmellyBucks.", e.User.Nickname, cash));
                }
                else
                {
                    await e.Channel.SendMessage(String.Format("You don't have an account at SmellyBank yet. Please register one with {0}startgambling.", Properties.Default.prefix));
                }
            });

            commands.CreateCommand("startgambling").Do(async(e) =>
            {
                if (this.casino == null)
                {
                    this.casino = new Casino();
                    this.casino.FetchGamblers();
                }

                if (this.casino.AddNewGambler(e.User.Name))
                {
                    await e.Channel.SendMessage("You have succesfully registered at SmellyBank and have received your starting 500 SmellyBucks.");
                }
                else
                {
                    await e.Channel.SendMessage(String.Format("You already have an account at SmellyBank. You can use {0}checkcash to see your cash.", Properties.Default.prefix));
                }
            });

            commands.CreateCommand("leaderboard").Do(async(e) =>
            {
                if (this.casino == null)
                {
                    this.casino = new Casino();
                    this.casino.FetchGamblers();
                }

                await this.casino.Leaderboard(e);
            });
            #region Slot Machine
            commands.CreateCommand("slots").Parameter("message", ParameterType.Required).Do(async(e) =>
            {
                if (this.casino == null)
                {
                    this.casino = new Casino();
                    this.casino.FetchGamblers();
                }
                await this.casino.Slots(e);
            });
            #endregion
            #region Random Roll
            commands.CreateCommand("roll").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                await Casino.Roll(e);
            });
            #endregion
            #endregion
            #region Request Role Addition/Removal
            commands.CreateCommand("assignrole").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                await Utils.AssignRole(e);
            });

            commands.CreateCommand("removerole").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                await Utils.RemoveRole(e);
            });
            #endregion
            #region League of Legends
            commands.CreateCommand("level").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetSummonerLevel(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("rank").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetSummonerRank(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("currentgame").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetCurrentGameStats(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("status").Parameter("message", ParameterType.Required).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetServerStatus(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("stats").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }
                    await stats.GetChampionStats(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("counter").Parameter("message", ParameterType.Required).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetChampionCounter(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("howto").Parameter("message", ParameterType.Required).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetChampionTips(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("lore").Parameter("message", ParameterType.Required).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetChampionLore(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("rankedstats").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetRankedChampStats(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });

            commands.CreateCommand("winrate").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                try
                {
                    if (stats == null)
                    {
                        stats = new LeagueStats(Properties.Default.riotAPIkey);
                    }

                    await stats.GetRankedWinrate(e);
                }
                catch (InvalidAPITokenException ex)
                {
                    Console.WriteLine(ex.Message);
                    await e.Channel.SendMessage(ex.Message);
                }
            });
            #endregion
        }
Example #7
0
        private LeagueStats GetLeagueStatsForTeam(IEnumerable <Match> matches, Team team)
        {
            int goalsScored   = 0;
            int goalsConceded = 0;
            int matchesPlayed = 0;
            int matchesWon    = 0;
            int matchesLost   = 0;
            int matchesDrawn  = 0;

            foreach (Match m in matches)
            {
                matchesPlayed++;

                if (m.HomeTeamId == team.Id)
                {
                    goalsScored   += m.HomeGoalsCount;
                    goalsConceded += m.AwayGoalsCount;

                    if (m.HomeGoalsCount > m.AwayGoalsCount)
                    {
                        matchesWon++;
                    }
                    else if (m.HomeGoalsCount == m.AwayGoalsCount)
                    {
                        matchesDrawn++;
                    }
                    else
                    {
                        matchesLost++;
                    }
                }
                else if (m.AwayTeamId == team.Id)
                {
                    goalsScored   += m.AwayGoalsCount;
                    goalsConceded += m.HomeGoalsCount;

                    if (m.HomeGoalsCount < m.AwayGoalsCount)
                    {
                        matchesWon++;
                    }
                    else if (m.HomeGoalsCount == m.AwayGoalsCount)
                    {
                        matchesDrawn++;
                    }
                    else
                    {
                        matchesLost++;
                    }
                }
            }

            var leagueStats = new LeagueStats()
            {
                GoalsConceded = goalsConceded,
                GoalsScored   = goalsScored,
                MatchesDrawn  = matchesDrawn,
                MatchesLost   = matchesLost,
                MatchesPlayed = matchesPlayed,
                MatchesWon    = matchesWon,
                Team          = team
            };

            return(leagueStats);
        }