Exemple #1
0
        public PartialViewResult GetSummonerInfo(string name)
        {
            if (string.IsNullOrEmpty(name.Trim()))
            {
                return(null);
            }

            var key        = WebConfigurationManager.AppSettings["RiotApiKey"];
            var rateLimit1 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Seconds"]);
            var rateLimit2 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Minutes"]);

            SummonerRegisterInfoModel summoner;

            try
            {
                summoner = new SummonerRegisterInfoModel(RiotApi.GetInstance(key, rateLimit1, rateLimit2).GetSummoner(Region.euw, name));
            }
            catch (Exception e)
            {
                // Summoner does not exist or riot API offline
                if (e.Message != "404, Resource not found")
                {
                    return(PartialView("SummonerInfo", new SummonerRegisterInfoModel(true)));
                }

                return(PartialView("SummonerInfo", null));
            }

            return(PartialView("SummonerInfo", summoner));
        }
Exemple #2
0
        public async Task Run(string[] args)
        {
            System.IO.StreamReader file =
                new System.IO.StreamReader("token.txt");
            string riotToken    = file.ReadLine();
            string discordToken = file.ReadLine();

            api       = RiotApi.GetInstance(riotToken);
            staticApi = StaticRiotApi.GetInstance(riotToken);
            client    = new DiscordClient(new DiscordConfig()
            {
                Token                 = discordToken,
                TokenType             = TokenType.Bot,
                DiscordBranch         = Branch.Canary,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true,
                AutoReconnect         = true
            });
            client.UseCommands(new CommandConfig()
            {
                Prefix  = "$",
                SelfBot = false
            });
            CreateCommands(client);
            await client.Connect();

            champions = staticApi.GetChampions(Region.na, ChampionData.info).Champions.Values.ToList <ChampionStatic>();
            spells    = staticApi.GetSummonerSpells(Region.eune, SummonerSpellData.basic).SummonerSpells.Values.ToList <SummonerSpellStatic>();
            Console.ReadLine();
        }
Exemple #3
0
 private void ApiValidate() =>
 _riotApi = _applicationConfig.EnvironmentEnum == DevelopmentEnvironment.Dev
         ? RiotApi.GetDevelopmentInstance(_applicationConfig.RiotApiConfig.ApiKey)
         : RiotApi.GetInstance(
     apiKey: _applicationConfig.RiotApiConfig.ApiKey,
     rateLimitPer10s: _applicationConfig.RiotApiConfig.RateLimitPer10s,
     rateLimitPer10m: _applicationConfig.RiotApiConfig.RateLimitPer10m);
        public void GetSummonerInfo(string summonerName, string api, SummonerViewModel model)
        {
            var myApi     = RiotApi.GetInstance(api);
            var staticApi = StaticRiotApi.GetInstance(api);

            if (summonerName != null)
            {
                GrabSummoner(myApi, summonerName, model);

                var champions      = staticApi.GetChampions(Region.na, ChampionData.image).Champions.Values;
                var summonerSpells = staticApi.GetSummonerSpells(Region.na, SummonerSpellData.image).SummonerSpells.Values;
                var version        = staticApi.GetVersions(Region.na).FirstOrDefault();
                var rankedStats    = myApi.GetStatsRanked(Region.na, model.SummonerId);
                var summonerIdList = new List <long> {
                    model.SummonerId
                };
                var leagues = myApi.GetLeagues(Region.na, summonerIdList).FirstOrDefault().Value;

                GrabEntries(leagues, model);
                GrabMatchHistory(myApi, model, version, champions, summonerSpells);

                model.Champions    = champions;
                model.SummonerIcon = "http://ddragon.leagueoflegends.com/cdn/" + version + "/img/profileicon/" + model.SummonerIconId + ".png";
            }
        }
Exemple #5
0
 public HomeController(IRepositoryBase <Entrada> context)
 {
     _context   = context;
     _rito      = RiotApi.GetInstance(k);
     _claves    = new Claves();
     _staticApi = StaticRiotApi.GetInstance(k);
 }
Exemple #6
0
        private static MatchDetail GetMatchDetail(long id)
        {
            var api    = RiotApi.GetInstance(API_KEY);
            var detail = api.GetMatch(Region.na, id, includeTimeline: true);

            return(detail);
        }
        public PartialViewResult GetSummonerInfo(string name)
        {
            if (string.IsNullOrEmpty(name.Trim()))
            {
                return(null);
            }

            var key = WebConfigurationManager.AppSettings["RiotApiKey"];

            SummonerRegisterInfoModel summoner;

            try
            {
                // TODO fix cringy magic numbers (rate limits)
                summoner = new SummonerRegisterInfoModel(RiotApi.GetInstance(key, 3000, 180000).GetSummoner(Region.euw, name));
            }
            catch (Exception e)
            {
                // Summoner does not exist or riot API offline
                if (e.Message != "404, Resource not found")
                {
                    return(PartialView("SummonerInfo", new SummonerRegisterInfoModel(true)));
                }

                return(PartialView("SummonerInfo", null));
            }

            return(PartialView("SummonerInfo", summoner));
        }
Exemple #8
0
        public Handler(string key)
        {
#if DEBUG
            API = RiotApi.GetDevelopmentInstance(key);
#else
            API = RiotApi.GetInstance(key, 20, 100);
#endif
        }
        public RiotApiScrapeJob()
        {
            var key        = WebConfigurationManager.AppSettings["RiotApiKey"];
            var rateLimit1 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Seconds"]);
            var rateLimit2 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Minutes"]);

            _api       = RiotApi.GetInstance(key, rateLimit1, rateLimit2);
            _staticApi = StaticRiotApi.GetInstance(key);
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var apikey = ConfigurationManager.AppSettings["apikey"];

            Console.WriteLine("waddup boois");
            Console.WriteLine(apikey);

            var api = RiotApi.GetInstance(apikey, 8, 500); // , 7, 500

            GameBase gamebase      = GameBase.LoadFromFile("DataFiles/gamebaseEX.xml");
            GameBase gamebaseToAdd = GameBase.LoadFromFile("DataFiles/gamebase.xml");
            int      gamesToAdd    = 0; //gamebaseToAdd.games.Count(g => !gamebase.games.Any(p => g.GameId == p.GameId));
            int      index         = 0;

            Console.WriteLine("Games to Add: " + gamesToAdd);

            ChampStatBase champStatBase = ChampStatBase.LoadFromFile("DataFiles/ChampStatBase.xml"); // new ChampStatBase();//

            var timer = new System.Threading.Timer((e) =>
            {
                gamebase.SaveToFile("DataFiles/gamebaseEX.xml");
                champStatBase.SaveToFile("DataFiles/ChampStatBase.xml");

                Console.WriteLine("SAVING FILES");
            }, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));

            foreach (Game game in gamebaseToAdd.games)
            {
                if (!gamebase.games.Any(g => g.GameId == game.GameId)) // if not already in de gamebase
                {
                    MatchDetail apiGame = null;
                    try
                    {
                        apiGame = api.GetMatch(Region.euw, game.GameId);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    gamebase.games.Add(new Game(game.GameId, apiGame.MatchCreation, 1, (int)apiGame.MatchDuration.TotalSeconds, apiGame.Region));

                    foreach (var participant in apiGame.Participants)
                    {
                        champStatBase.champStats.Add(new ChampStat(game.GameId, participant));
                    }

                    index++;

                    Console.WriteLine("GameId: " + game.GameId + " Game " + index + " out of " + gamesToAdd + " Total Games: " + gamebase.games.Count());
                }
            }


            Console.WriteLine("All Done! press any key to close.");
            Console.ReadKey();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            var    api       = RiotApi.GetInstance(ConfigurationManager.AppSettings["ApiKey"]);
            var    staticApi = StaticRiotApi.GetInstance(ConfigurationManager.AppSettings["ApiKey"]);
            var    statusApi = StatusRiotApi.GetInstance();
            int    id        = int.Parse(ConfigurationManager.AppSettings["Summoner1Id"]);
            string name      = ConfigurationManager.AppSettings["Summoner1Name"];
            int    id2       = int.Parse(ConfigurationManager.AppSettings["Summoner2Id"]);
            string name2     = ConfigurationManager.AppSettings["Summoner2Name"];
            string team      = ConfigurationManager.AppSettings["Team1Id"];
            string team2     = ConfigurationManager.AppSettings["Team2Id"];
            int    gameId    = int.Parse(ConfigurationManager.AppSettings["GameId"]);
            Region region    = (Region)Enum.Parse(typeof(Region), ConfigurationManager.AppSettings["Region"]);

            var languages = staticApi.GetLanguages(region);

            Console.WriteLine(string.Join(", ", languages));

            var summ = api.GetSummoner(region, name);

            var teams = summ.GetTeams();

            var match1 = api.GetMatch(region, gameId);

            Console.WriteLine(match1.MapType);

            var shards = statusApi.GetShards();

            var shardStatus = statusApi.GetShardStatus(region);

            var statSummaries = api.GetStatsSummaries(region, id);

            var championIds = new List <int>();

            for (int i = 0; i < 30; i += 15)
            {
                var matches = api.GetMatchHistory(region, id, i, i + 15, null,
                                                  new List <Queue>()
                {
                    Queue.RankedSolo5x5
                });
                foreach (var match in matches)
                {
                    championIds.Add(match.Participants[0].ChampionId);
                }
            }
            var mostPlayedChampId = championIds.GroupBy(c => c).OrderByDescending(g => g.Count()).FirstOrDefault().Key;
            var mostPlayedChamp   = staticApi.GetChampion(region, mostPlayedChampId);

            Console.WriteLine(mostPlayedChamp.Name);

            var games = api.GetRecentGames(region, id);

            Console.WriteLine("Done! Press Enter to exit.");
            Console.ReadLine();
        }
Exemple #12
0
        /// <summary>
        /// Calls the lol api for the current game of the user passed in
        /// </summary>
        /// <param name="summonerApi"></param>
        /// <returns></returns>
        public static string GetCurrentGame(dynamic summonerApi)
        {
            var api             = RiotApi.GetInstance(Environment.GetEnvironmentVariable("lol_api_key"));
            var currentGameData = api.GetCurrentGame((Platform)Region.euw, summonerApi.Id);

            Console.WriteLine(currentGameData);
            //var message = summonerApi.Name + " is currently in a game as " + Champion + " and is " + Current Stats + " as of " + time;

            return("current");
        }
Exemple #13
0
        /// <summary>
        /// Calls the Lol api for the summonername passed in
        /// </summary>
        /// <param name="summonerName"></param>
        /// <returns></returns>
        public static dynamic GetSummonerData(string summonerName)
        {
            int summonerId;
            var api = RiotApi.GetInstance(Environment.GetEnvironmentVariable("lol_api_key"));

            if (int.TryParse(summonerName, out summonerId))
            {
                return(api.GetSummoner(Region.euw, summonerId));
            }
            return(api.GetSummoner(Region.euw, summonerName));
        }
Exemple #14
0
 public static List <MatchSummary> GetRecentMatches(Summoner summoner)
 {
     try
     {
         var api     = RiotApi.GetInstance(API_KEY);
         var matches = api.GetMatchHistory(Region.na, summoner.Id);
         return(matches);
     }
     catch
     {
         return(null);
     }
 }
Exemple #15
0
 public static List <Game> GetRecentGames(Summoner summoner)
 {
     try
     {
         var api   = RiotApi.GetInstance(API_KEY);
         var games = api.GetRecentGames(Region.na, summoner.Id);
         return(games);
     }
     catch
     {
         return(null);
     }
 }
Exemple #16
0
 public static Summoner GetSummoner(string name)
 {
     try
     {
         var api      = RiotApi.GetInstance(API_KEY);
         var summoner = api.GetSummoner(Region.na, name);
         return(summoner);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
 public static async Task <Summoner> GetSummoner(string name, Region region)
 {
     try
     {
         var api = RiotApi.GetInstance(Variables.ApiKey);
         return(await api.GetSummonerAsync(region, name));
     }
     catch (RiotSharpException e)
     {
         Debug.WriteLine(e.Message);
         return(null);
     }
 }
        public static async Task <bool> CheckSummoner(string name, Region region)
        {
            try
            {
                var api = RiotApi.GetInstance(Variables.ApiKey);
                await api.GetSummonerAsync(region, name);

                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(false);
            }
        }
Exemple #19
0
        /// <summary>
        /// This is the root of the functions app.
        /// It is used to initialize all services that are
        /// used via dependency injections.
        /// </summary>
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton <CloudTables>();
            builder.Services.AddSingleton <LolChestConfig>();
            builder.Services.AddTransient <ISmtpClient>(provider => new SmtpClient());

            var cd = new ConcurrentDictionary <TimeSpan, int>();

            cd.AddOrUpdate(TimeSpan.FromSeconds(1), span => 20, (span, i) => i);
            cd.AddOrUpdate(TimeSpan.FromSeconds(2), span => 100, (span, i) => i);

            builder.Services.AddSingleton <IRiotApi>(provider => RiotApi.GetInstance(
                                                         provider.GetService <LolChestConfig>().ApiKey, cd, new PassThroughCache()));
            builder.Services.AddSingleton <ISummonerEndpoint>(provider => provider.GetService <IRiotApi>().Summoner);
            builder.Services.AddSingleton <IMatchEndpoint>(provider => provider.GetService <IRiotApi>().Match);
        }
        /// <summary>
        /// Constructor for this class which fetches the API instance..
        /// </summary>
        /// <param name="apiKey">A developer key from https://developer.riotgames.com/ </param>
        public LeagueStats(string apiKey)
        {
            api       = RiotApi.GetInstance(apiKey);
            staticApi = StaticRiotApi.GetInstance(apiKey);
            statusApi = StatusRiotApi.GetInstance();

            try
            {
                this.api.GetChampion(Region.br, 1);
            }
            catch (RiotSharpException ex)
            {
                Console.WriteLine(ex.Message);
                throw new InvalidAPITokenException("Please provide a valid Riot API token for SmellyBot to use League of Legends commands.");
            }
        }
Exemple #21
0
        static void Main(string[] args)
        {
            var    api       = RiotApi.GetInstance(ConfigurationManager.AppSettings["ApiKey"]);
            var    staticApi = StaticRiotApi.GetInstance(ConfigurationManager.AppSettings["ApiKey"]);
            var    statusApi = StatusRiotApi.GetInstance();
            int    id        = int.Parse(ConfigurationManager.AppSettings["Summoner1Id"]);
            string name      = ConfigurationManager.AppSettings["Summoner1Name"];
            int    id2       = int.Parse(ConfigurationManager.AppSettings["Summoner2Id"]);
            string name2     = ConfigurationManager.AppSettings["Summoner2Name"];
            string team      = ConfigurationManager.AppSettings["Team1Id"];
            string team2     = ConfigurationManager.AppSettings["Team2Id"];

            var match1 = api.GetMatch(Region.euw, 1929054645);

            Console.WriteLine(match1.MapType);

            var shards = statusApi.GetShards();

            var shardStatus = statusApi.GetShardStatus(Region.euw);

            var statSummaries = api.GetStatsSummaries(Region.euw, id);

            var championIds = new List <int>();

            for (int i = 0; i < 30; i += 15)
            {
                var matches = api.GetMatchHistory(Region.euw, id, i, i + 15, null,
                                                  new List <Queue>()
                {
                    Queue.RankedSolo5x5
                });
                foreach (var match in matches)
                {
                    championIds.Add(match.Participants[0].ChampionId);
                }
            }
            var mostPlayedChampId = championIds.GroupBy(c => c).OrderByDescending(g => g.Count()).FirstOrDefault().Key;
            var mostPlayedChamp   = staticApi.GetChampion(Region.euw, mostPlayedChampId);

            Console.WriteLine(mostPlayedChamp.Name);

            var games = api.GetRecentGames(Region.euw, id);

            Console.ReadLine();
        }
Exemple #22
0
        public RiotApiScrapeJob()
        {
            var key = WebConfigurationManager.AppSettings["RiotApiKey"];

            _api = RiotApi.GetInstance(key, 3000, 180000);

            var timeSetting = WebConfigurationManager.AppSettings["TournamentStart"];

            tournamentStart = DateTime.ParseExact(timeSetting, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);


            // For summoner statistics, always 1 hour
            var intervalSummoners = new TimeSpan(1, 0, 0);
            var intervalMatches   = new TimeSpan(1, 0, 0);

            new Timer(ScrapeSummoners, null, new TimeSpan(0, 0, 0, 0, 0), intervalSummoners);
            new Timer(ScrapeMatches, null, new TimeSpan(0, 0, 0, 0, 0), intervalMatches);
        }
Exemple #23
0
        public void GetSummonerInfo(string summonerName, string api)
        {
            var myApi     = RiotApi.GetInstance(api);
            var staticApi = StaticRiotApi.GetInstance(api);
            var statusApi = StatusRiotApi.GetInstance();

            var summoner = myApi.GetSummoner(Region.na, summonerName);

            var champions = staticApi.GetChampions(Region.na, ChampionData.image).Champions.Values;

            foreach (var champion in champions)
            {
                Console.WriteLine(champion.Name);
            }



            var varusRanked = summoner.GetStatsRanked(RiotSharp.StatsEndpoint.Season.Season2017);

            Console.WriteLine(varusRanked);
            Console.ReadLine();
        }
Exemple #24
0
        static void Main(string[] args)
        {
            var    api       = RiotApi.GetInstance(ConfigurationManager.AppSettings["ApiKey"]);
            var    staticApi = StaticRiotApi.GetInstance(ConfigurationManager.AppSettings["ApiKey"]);
            var    statusApi = StatusRiotApi.GetInstance();
            int    id        = int.Parse(ConfigurationManager.AppSettings["Summoner1Id"]);
            string name      = ConfigurationManager.AppSettings["Summoner1Name"];
            int    id2       = int.Parse(ConfigurationManager.AppSettings["Summoner2Id"]);
            string name2     = ConfigurationManager.AppSettings["Summoner2Name"];
            string team      = ConfigurationManager.AppSettings["Team1Id"];
            string team2     = ConfigurationManager.AppSettings["Team2Id"];
            int    gameId    = int.Parse(ConfigurationManager.AppSettings["GameId"]);
            Region region    = (Region)Enum.Parse(typeof(Region), ConfigurationManager.AppSettings["Region"]);

            var mastery = staticApi.GetMastery(Region.euw, 6111, MasteryData.all);

            var languages = staticApi.GetLanguages(region);

            Console.WriteLine(string.Join(", ", languages));

            var summ = api.GetSummoner(region, name);

            var teams = summ.GetTeams();

            var match1 = api.GetMatch(region, gameId);

            Console.WriteLine(match1.MapType);

            var shards = statusApi.GetShards();

            var shardStatus = statusApi.GetShardStatus(region);

            var statSummaries = api.GetStatsSummaries(region, id);

            var games = api.GetRecentGames(region, id);

            Console.WriteLine("Done! Press Enter to exit.");
            Console.ReadLine();
        }
Exemple #25
0
        public static void FixMatchCreationDates()
        {
            var key        = WebConfigurationManager.AppSettings["RiotApiKey"];
            var rateLimit1 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Seconds"]);
            var rateLimit2 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Minutes"]);

            var api = RiotApi.GetInstance(key, rateLimit1, rateLimit2);

            foreach (var m in Mongo.Matches.FindAll())
            {
                MatchDetail game;
                try
                {
                    game = api.GetMatch(Region.euw, m.RiotMatchId);
                }
                catch (Exception)
                {
                    File.AppendAllText("C:\\Users\\Steven\\Desktop\\test.txt", m.BlueTeam.Name + " vs. " + m.RedTeam.Name + " (" + m.Phase + "." + m.Priority + ")\n");
                    continue;
                }

                m.AssistsBlueTeam = game.Participants.Where(x => x.TeamId == 100).Sum(x => x.Stats.Assists);
                m.DeathsBlueTeam  = game.Participants.Where(x => x.TeamId == 100).Sum(x => x.Stats.Deaths);
                m.KillsBlueTeam   = game.Participants.Where(x => x.TeamId == 100).Sum(x => x.Stats.Kills);

                m.AssistsRedTeam = game.Participants.Where(x => x.TeamId == 200).Sum(x => x.Stats.Assists);
                m.DeathsRedTeam  = game.Participants.Where(x => x.TeamId == 200).Sum(x => x.Stats.Deaths);
                m.KillsRedTeam   = game.Participants.Where(x => x.TeamId == 200).Sum(x => x.Stats.Kills);

                m.ChampionIds = game.Participants.Select(x => x.ChampionId).ToArray();
                m.BanIds      = game.Teams.Where(x => x.Bans != null).SelectMany(x => x.Bans).Select(x => x.ChampionId).ToArray();

                m.Duration = game.MatchDuration;

                Mongo.Matches.Save(m);
            }
        }
Exemple #26
0
        public JsonResult GetMatchInformation(int hours, int minutes, string date)
        {
            SummonerModel model = new SummonerModel();

            API riotApi = new API();


            DateTime parsedDate = DateTime.Parse(date);

            parsedDate = parsedDate.AddHours(hours);
            parsedDate = parsedDate.AddMinutes(minutes);

            List <long> gameIds = riotApi.GetUrfGames(parsedDate);

            if (gameIds.Count > 0)
            {
                var api       = RiotApi.GetInstance(riotApi.KeyOnly);
                var staticApi = StaticRiotApi.GetInstance(riotApi.KeyOnly);

                List <MatchDetail> matchDetails = new List <MatchDetail>();


                for (int i = 0; i < gameIds.Count; i++)
                {
                    matchDetails.Add(api.GetMatch(Region.euw, gameIds[i]));
                }

                ChampionListStatic championList = staticApi.GetChampions(Region.euw);


                ScoreCardCalculator scoreCalculator = new ScoreCardCalculator();

                model.ChampionScoreCards = scoreCalculator.CalculateChampionScores(matchDetails, riotApi.GetChampions());
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemple #27
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            var      api = RiotApi.GetInstance("d254864f-4fda-4807-8e01-6e44b2349ad7");
            Summoner summoner;

            RiotSharp.Region region = RiotSharp.Region.euw;

            try
            {
                summoner = api.GetSummoner(region, summonerTextBox.Text);
                //MessageBox.Show(string.Format("Id : {0} {1}", summoner.Id, "toto"));

                //var matchList = api.GetMatchList(region, summoner.Id, null, );
                var gameList  = api.GetRecentGames(region, summoner.Id);
                var masteries = api.GetMasteryPages(region, summoner.Id);

                gameGridView.DataSource = gameList;
            }
            catch (RiotSharpException ex)
            {
                MessageBox.Show(ex.Message);
                // Handle the exception however you want.
            }
        }
Exemple #28
0
        public LeagueofLegendsService(
            DiscordSocketClient discord,
            CommandService commands,
            IConfigurationRoot config,
            LoggingService logging)
        {
            _config   = config;
            _discord  = discord;
            _commands = commands;
            _logging  = logging;

            try
            {
                cacheTimer = TimeSpan.FromHours(1);
                api        = RiotApi.GetInstance(RiotApiKey, RateLimitPer10S,
                                                 RateLimitPer10M); // This gets an API instance with our API Key and rate limits.
                staticApi = StaticRiotApi.GetInstance(RiotApiKey, true,
                                                      cacheTimer); // THis gets a static endpoint API instance with our API key.
            }
            catch (RiotSharpException ex)
            {
                _logging.OnLogAsync(ex).ConfigureAwait(false);
            }
        }
Exemple #29
0
        static void Main(string[] args)
        {
            MySqlConnectionStringBuilder b = new MySqlConnectionStringBuilder();

            b.Server              = ConfigurationManager.AppSettings["server"];
            b.UserID              = ConfigurationManager.AppSettings["uid"];
            b.Password            = ConfigurationManager.AppSettings["password"];
            b.Database            = ConfigurationManager.AppSettings["database"];
            b.Port                = 3306;
            b.ConvertZeroDateTime = true;
            b.AllowZeroDateTime   = true;

            link = new MySqlConnection(b.ToString()); //b.ToString()
            MySqlCommand cmd = link.CreateCommand();

            Console.WriteLine("waddup boois");
            Console.WriteLine(apikey);

            var api = RiotApi.GetInstance(apikey, 8, 500); // , 7, 500


            List <Region> regions = new List <Region>();

            regions.Add(new Region("euw", RiotSharp.Misc.Region.euw, 1));
            regions.Add(new Region("eune", RiotSharp.Misc.Region.eune, 0));
            regions.Add(new Region("na", RiotSharp.Misc.Region.na, 3));
            regions.Add(new Region("kr", RiotSharp.Misc.Region.kr, 2));

            Region region = null;

            try
            {
                region = regions.Find(r => r.name == args[0]);
            }
            catch (Exception) { }


            while (region == null)
            {
                Console.Write("Enter Region(euw/eune/na/kr): ");
                string result = Console.ReadLine().ToLower();
                region = regions.Find(r => r.name == result);
            }

            Console.WriteLine("Region selected: " + region.region.ToString());
            Console.Title = "GameFinder " + region.region.ToString().ToUpper();

            regions.Clear();

            while (!link.Ping())
            {
                try
                {
                    link.Open();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            PlayerBase players = new PlayerBase(region, link); //  new PlayerBase(); //
            //PlayerBase newPlayers = new PlayerBase(region, link);
            GameBase gamebase = new GameBase(region);          //new GameBase();

            players.LoadFromDatabase(link, 100);

            while (players.PlayersAvailable())
            {
                if (players.players.Count < 5)
                {
                    Console.WriteLine("UPLINK TO DATABASE...");
                    players.UpdatePlayers(link);
                    gamebase.AddPlayersAndGamesToDatabase(link);
                    players.LoadFromDatabase(link, 100);
                    Console.WriteLine("QUIT NOW !");
                    //System.Threading.Thread.Sleep(5000);
                    //Console.WriteLine("to late.");
                }

                try
                {
                    List <RiotSharp.GameEndpoint.Game> games = new List <RiotSharp.GameEndpoint.Game>();

                    Console.WriteLine("Checking games from " + players.CurrentPlayer().SummonerID);
                    try
                    {
                        games = api.GetRecentGames(region.region, players.CurrentPlayer().SummonerID); //get 10 games
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        try
                        {
                            RiotSharpException ex = (RiotSharpException)e;
                            Console.WriteLine("ERROR: " + ex.Message);
                            if (ex.Message == "429, Rate Limit Exceeded")
                            {
                                //Console.WriteLine("429, Rate Limit Exceeded");
                                System.Threading.Thread.Sleep(10000);
                                continue;
                            }
                            else
                            {
                                players.NextPlayer();
                                continue;
                            }
                        }
                        catch (Exception)
                        {
                        }
                        //Console.WriteLine(e.Message);
                        players.NextPlayer();
                        continue;
                    }

                    players.CurrentPlayer().AddGamesFound(games.Count);

                    // Console.Write(">");
                    foreach (var game in games)             // for all games
                    {
                        if (game.GameMode == GameMode.Aram) // if this game is aram game
                        {
                            if (game.CreateDate > players.CurrentPlayer().CheckedUntill)
                            {
                                players.CurrentPlayer().AddAramsFound(1);

                                gamebase.AddGame(new Game(game.GameId, game.FellowPlayers));
                            }
                        }
                    }

                    if (games.Count > 0)
                    {
                        players.CurrentPlayer().CheckedUntill = games[0].CreateDate;
                    }
                }
                catch (RiotSharpException ex)
                {
                    // Handle the exception however you want.
                    throw;
                }

                players.NextPlayer();

                //players.IncrementIndex();

                //Console.WriteLine("checking player " + players.index + " out of " + players.players.Count +" |" + ((float)players.index/players.players.Count*100 ).ToString("0.00") + "%| Games: " + gamebase.games.Count + " Est Total Games:" + (((float)gamebase.games.Count/ players.index)* players.players.Count).ToString("0"));
                //Console.WriteLine();
            }


            Console.ReadKey();
        }
Exemple #30
0
 public ToolModule(Configuration configuration)
 {
     _configuration = configuration;
     _riotApi       = RiotApi.GetInstance(_configuration.LolApiKey, 1500, 90000);
 }