Beispiel #1
0
        public XboxHistory()
        {
            Action updates = new Action(() =>
            {
                Log.Logger = new LoggerConfiguration()
                             .WriteTo.Console(theme: AnsiConsoleTheme.Code)
                             .WriteTo.Seq("http://localhost:5341")
                             .CreateLogger();
                try
                {
                    var previousSeason = "";
                    var currentSeason  = "";
                    var savePrevious   = "";
                    Console.WriteLine("Updating Historical Statistics");
                    previousSeason = Utilities.GetPrevious("xbox");

                    currentSeason = Utilities.GetSeason("xbox");
                    savePrevious  = "";
                    Console.WriteLine("Updating Xbox Historical Statistics");

                    for (int i = int.Parse(previousSeason); i < int.Parse(currentSeason); i++)
                    {
                        //PlayerEngine.GetField("xbox", "playerstats", i, "pre", "uh");
                        //GoalieEngine.GetGoalie("xbox", "goaliestats", i, "pre", "uh");
                        //Log.Logger.Warning("Xbox Goalies pre updated\n");
                        //Log.CloseAndFlush();

                        //TeamEngine.GetTeam("xbox", "teamstats", i, "pre", "uh");

                        PlayerEngine.GetField("xbox", "playerstats", i, "reg", "uh");
                        Log.Logger.Warning("Xbox Players updated\n");
                        Log.CloseAndFlush();

                        GoalieEngine.GetGoalie("xbox", "goaliestats", i, "reg", "uh");
                        Log.Logger.Warning("Xbox Goalies updated.\n");
                        Log.CloseAndFlush();

                        TeamEngine.GetTeam("xbox", "teamstats", i, "reg", "uh");
                        Console.WriteLine($"Xbox Stats saved for: {i}  [Historical]");
                        Log.CloseAndFlush();

                        savePrevious = i.ToString();
                        //Console.WriteLine($"--->{previousSeason}\n---->{i}");
                    }

                    Console.WriteLine(!Utilities.SavePrevious("xbox", savePrevious)
                        ? "Failed to update Xbox Previous Season"
                        : "Successfully updated Xbox previous season.");

                    Console.WriteLine("Historical Stats Updated.");
                }
                catch (Exception ex)
                {
                    Log.Logger.Error($"Fatal error running historical stats update.\n{ex}");
                    Console.WriteLine($"Fatal error running historical stats update.\n{ex}");
                }
            });

            this.Schedule(updates).ToRunNow().AndEvery(1).Days().At(15, 0);
        }
Beispiel #2
0
        public PsnHistory()
        {
            Action updates = new Action(() =>
            {
                Log.Logger = new LoggerConfiguration()
                    .WriteTo.Console(theme: AnsiConsoleTheme.Code)
                    .WriteTo.Seq("http://localhost:5341")
                    .CreateLogger();
                var previousSeason = "";
                var currentSeason = "";
                var savePrevious = "";
                try
                {
                    previousSeason = Utilities.GetPrevious("psn");
                    currentSeason = Utilities.GetSeason("psn");
                    savePrevious = "";
                    Console.WriteLine("Updating PSN Historical Statistics");

                    for (int i = int.Parse(previousSeason); i < int.Parse(currentSeason); i++)
                    {
                        //Console.WriteLine($"We are inside the f*****g loop (iteration {i}).");
                        //PlayerEngine.GetField("psn", "playerstats", i, "pre", "uh");
                        //Log.Logger.Warning("PSN Players pre updated.");
                        //Log.CloseAndFlush();

                        //GoalieEngine.GetGoalie("psn", "goaliestats", i, "pre", "uh");
                        //Log.Logger.Warning("PSN Goalies pre updated.");
                        //Log.CloseAndFlush();
                        ////eamEngine.GetTeam("psn", "teamstats", i, "pre", "uh");

                        PlayerEngine.GetField("psn", "playerstats", i, "reg", "uh");
                        Log.Logger.Warning("PSN Players pre updated.");
                        Log.CloseAndFlush();

                        GoalieEngine.GetGoalie("psn", "goaliestats", i, "reg", "uh");
                        Log.Logger.Warning("PSN Goalies pre updated.");
                        Log.CloseAndFlush();

                        //TeamEngine.GetTeam("psn", "teamstats", i, "reg", "uh");
                        Console.WriteLine($"PSN Stats saved for: {i}  [Historical]\n");
                        Log.CloseAndFlush();

                        savePrevious = i.ToString();

                        //Console.WriteLine($"--->{previousSeason}\n---->{i}");
                    }

                    Console.WriteLine(!Utilities.SavePrevious("psn", savePrevious)
                        ? "Failed to update PSN Previous Season"
                        : "Successfully updated PSN previous season.");
                }
                catch (Exception ex)
                {
                    Log.Logger.Error($"Fatal error running historical stats update.\n{ex}");
                    Console.WriteLine($"Fatal error running historical stats update.\n{ex}");
                }
            });
            this.Schedule(updates).ToRunNow().AndEvery(1).Months().OnTheSecond(DayOfWeek.Friday);
        }
Beispiel #3
0
        public async Task UpdateSeasonNumber(string system, string newSeason)
        {
            var user = Context.User as SocketGuildUser;

            //Me, Dunks, Brisan
            //remove this as it's not needed
            if (user.Id == 111252573054312448 || user.Id == 336185156106846209 || user.Id == 321805929517678612)
            {
                string JSON = "";
                var    xboxCurrentSeason  = "";
                var    xboxPreviousSeason = xboxCurrentSeason;
                var    psnCurrentSeason   = "";
                var    psnPreviousSeason  = psnCurrentSeason;

                var sFile          = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                var settingsFile   = @"Configuration\websettings.json";
                var configLocation = Path.Combine(sFile, settingsFile);


                if (!File.Exists(configLocation))
                {
                    Log.Error($"UpdateSeason method: {configLocation} does not exist (Ln 27");
                }
                try
                {
                    using (var stream = new FileStream(configLocation, FileMode.Open, FileAccess.ReadWrite))
                        using (var readSettings = new StreamReader(stream))
                        {
                            JSON = readSettings.ReadToEnd();
                        }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, $"Error reading websettings.json ({configLocation}");
                    throw;
                }

                UrlSettings jsonObj = JsonConvert.DeserializeObject <UrlSettings>(JSON);
                xboxCurrentSeason = jsonObj.xboxSeasonId;
                psnCurrentSeason  = jsonObj.psnSeasonId;
                if (system == "xbox")
                {
                    if (int.Parse(newSeason) > int.Parse(xboxCurrentSeason) + 1 || int.Parse(newSeason) < int.Parse(xboxCurrentSeason) - 1)
                    {
                        await Context.Channel.SendMessageAsync(
                            $"Season id entered was caught offside (***enter the real season id jackass***).");

                        return;
                    }
                    else
                    {
                        jsonObj.xboxPrevious = jsonObj.xboxSeasonId;
                        jsonObj.xboxSeasonId = newSeason;
                        string content = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                        File.WriteAllText(configLocation, content);
                        await ReplyAsync($"***{system}*** Season ID Change Request.\nPrevious Season: {xboxCurrentSeason}\nSeason Updated to: ***{newSeason}***");

                        PlayerEngine.GetField(system, "playerstats", int.Parse(jsonObj.xboxPrevious), "pre", "uh");
                        GoalieEngine.GetGoalie(system, "goaliestats", int.Parse(jsonObj.xboxPrevious), "pre", "uh");
                        TeamEngine.GetTeam(system, "teamstats", int.Parse(jsonObj.xboxPrevious), "pre", "uh");
                    }
                }
                else if (system == "psn")
                {
                    if (int.Parse(newSeason) > int.Parse(psnCurrentSeason) + 1 || int.Parse(newSeason) < int.Parse(psnCurrentSeason) - 1)
                    {
                        await Context.Channel.SendMessageAsync(
                            $"Season id entered was caught offside (***enter the real season id jackass***).");

                        return;
                    }
                    else
                    {
                        jsonObj.psnSeasonId = newSeason;
                        string content = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                        File.WriteAllText(configLocation, content);
                        await ReplyAsync($"***{system}*** Season ID Change Request.\nPrevious Season: {psnCurrentSeason}\nSeason Updated to: ***{newSeason}***");
                    }
                }
            }
            else
            {
                await Context.Channel.SendMessageAsync(
                    $"Sorry {user.Mention}, but you don't have permission to use that command.");
            }
        }