Ejemplo n.º 1
0
        public static async void GetOldestRecord(string levelName, string newrecord, bool clear)
        {
            var            levelPath        = LevelInfo[ILCounter].Item3;
            var            oldestRecordPath = GeneralPath + "OldestRecord.txt";
            var            NewRecord        = GetRunInfo(newrecord, true, "IL");
            DiscordChannel chan             = await Program._client.GetChannelAsync(channelID);

            TimeSpan start = new TimeSpan(00, 50, 0);
            TimeSpan end   = new TimeSpan(00, 59, 59);
            TimeSpan now   = DateTime.Now.TimeOfDay;

            if ((now > start) && (now < end) && UpdateBot == false && ILCounter == 0)
            {
                SetTopic("Bot is refreshing");
                Console.WriteLine("Bot refresh is starting!");
                UpdateBot = true;
                if (File.Exists(oldestRecordPath))
                {
                    File.Delete(oldestRecordPath);
                }
            }


            if (!File.Exists(oldestRecordPath))
            {
                using (StreamWriter sw = File.CreateText(oldestRecordPath))
                {
                    sw.WriteLine("Level: " + levelName + " - " + NewRecord.Item7);
                    var topicString = "Longest standing | " + levelName + " - [" + NewRecord.Item3 + "] by " + NewRecord.Item1 + " [" + NewRecord.Item6.Days.ToString() + " days]";
                    SetTopic(topicString);
                }
            }
            else
            {
                try
                {
                    var testRekky = GetRunInfo(File.ReadLines(oldestRecordPath).Last(), false, "IL");
                } catch
                {
                    File.Delete(oldestRecordPath);
                    using (StreamWriter sw = File.CreateText(oldestRecordPath))
                    {
                        Console.WriteLine("OldestRecord.txt was empty! Deleting and recreating");
                        sw.WriteLine("Level: " + levelName + " - " + NewRecord.Item7);
                        var topicString = "Longest standing | " + levelName + " - [" + NewRecord.Item3 + "] by " + NewRecord.Item1 + " [" + NewRecord.Item6.Days.ToString() + " days]";
                        SetTopic(topicString);
                    }
                }
                var OldRecord = GetRunInfo(File.ReadLines(oldestRecordPath).Last(), false, "IL");

                if ((chan.Topic == "Bot is refreshing") && UpdateBot == false)
                {
                    doUpdate = true;
                }


                if (clear == false)
                {
                    if (NewRecord.Item6 > OldRecord.Item6)
                    {
                        File.Delete(oldestRecordPath);
                        using (StreamWriter sw = File.CreateText(oldestRecordPath))
                        {
                            sw.WriteLine("Level: " + levelName + " - " + NewRecord.Item7);
                            var topicString = "Longest standing | " + levelName + " - [" + NewRecord.Item3 + "] by " + NewRecord.Item1 + " [" + NewRecord.Item6.Days.ToString() + " days]";
                            SetTopic(topicString);
                        }
                    }
                    else if ((NewRecord.Item6 == OldRecord.Item6) || doUpdate == true)
                    {
                        string[] readText = File.ReadAllLines(oldestRecordPath);
                        if (!readText.Contains("Level: " + levelName + " - " + NewRecord.Item7) || doUpdate == true)
                        {
                            string topicString = "Longest standing records:\r\n";
                            using (StreamWriter sw = File.AppendText(oldestRecordPath))
                            {
                                if (doUpdate == false)
                                {
                                    sw.WriteLine("Level: " + levelName + " - " + NewRecord.Item7);
                                }
                            }
                            string[] readText2 = File.ReadAllLines(oldestRecordPath);
                            foreach (string x in readText2)
                            {
                                var    _xlevelName      = StringBuilding.getBetweenStr(x, "Level: ", " - Name:");
                                var    _xtime           = StringBuilding.getBetweenStr(x, "Time: ", " | Date:");
                                string _xconvertedTime  = ConvertTime(_xtime);
                                var    _xdate           = StringBuilding.getBetweenStr(x, "Date: ", " |");
                                var    _xconvertedDate  = DateTime.Parse(_xdate);
                                var    _xdateDifference = (DateTime.Now.Date.Subtract(_xconvertedDate.Date));
                                topicString = topicString + _xlevelName + " - [" + _xconvertedTime + "] by " + StringBuilding.getBetweenStr(x, "Name: ", " | Time:") + " [" + _xdateDifference.Days + " days]\r\n";
                            }
                            SetTopic(topicString);
                            if (doUpdate == true)
                            {
                                doUpdate = false;
                            }
                        }
                    }
                }
                else
                {
                    if (File.Exists(oldestRecordPath))
                    {
                        File.Delete(oldestRecordPath);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Tuple <string, string, string, string, DateTime, TimeSpan, string> GetRunInfo(string rawRecord, bool newRun, string runType)
        {
            string   name;
            string   time;
            float    timeFloat;
            string   convertedTime;
            string   date;
            DateTime convertedDate;
            TimeSpan dateDifference;
            string   info;

            if (newRun == true)
            {
                if (runType == "IL")
                {
                    name           = StringBuilding.getBetweenStr(rawRecord, "\"username\":\"", "\",\"steam_id\"");
                    time           = StringBuilding.getBetweenStr(rawRecord, "\"time\":", ",\"replay\"");
                    convertedTime  = ConvertTime(time);
                    date           = StringBuilding.getBetweenStr(rawRecord, "\"update_date\":\"", "T");
                    convertedDate  = DateTime.Parse(date);
                    dateDifference = (DateTime.Now.Date.Subtract(convertedDate.Date));
                    info           = "Name: " + name + " | Time: " + time + " | Date: " + date + " |";

                    Tuple <string, string, string, string, DateTime, TimeSpan, string> returnData = Tuple.Create(name, time, convertedTime, date, convertedDate, dateDifference, info);

                    return(returnData);
                }
                else if (runType == "Speedrun")
                {
                    name           = StringBuilding.getBetweenStr(rawRecord, "\"username\":\"", "\",\"total_time\"");
                    time           = StringBuilding.getBetweenStr(rawRecord, "\"total_time\":", ",\"update_date\"");
                    timeFloat      = float.Parse(time) / 1000;
                    convertedTime  = ConvertTime(time);
                    date           = StringBuilding.getBetweenStr(rawRecord, "\"update_date\":\"", "T");
                    convertedDate  = DateTime.Parse(date);
                    dateDifference = (DateTime.Now.Date.Subtract(convertedDate.Date));
                    info           = "Name: " + name + " | Time: " + time + " | Date: " + date + " |";

                    Tuple <string, string, string, string, DateTime, TimeSpan, string> returnData = Tuple.Create(name, time, convertedTime, date, convertedDate, dateDifference, info);

                    return(returnData);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                info           = rawRecord;
                name           = StringBuilding.getBetweenStr(info, "Name: ", " | Time:");
                time           = StringBuilding.getBetweenStr(info, "Time: ", " | Date:");
                convertedTime  = ConvertTime(time);
                date           = StringBuilding.getBetweenStr(info, "Date: ", " |");
                convertedDate  = DateTime.Parse(date);
                dateDifference = (DateTime.Now.Date.Subtract(convertedDate.Date));

                Tuple <string, string, string, string, DateTime, TimeSpan, string> returnData = Tuple.Create(name, time, convertedTime, date, convertedDate, dateDifference, rawRecord);
                return(returnData);
            }
        }
Ejemplo n.º 3
0
        public static async void RefreshILLeaderboardsAsync(object source, ElapsedEventArgs e)
        {
            int            levelID   = LevelInfo[ILCounter].Item1;
            string         levelName = LevelInfo[ILCounter].Item2;
            string         levelPath = LevelInfo[ILCounter].Item3;
            DiscordChannel channel   = await Program._client.GetChannelAsync(channelID);

            string responseString = "";

            try
            {
                responseString = await ILPostLink.PostUrlEncodedAsync(new { level_id = levelID, line_count = "1", start_rank = "0" }).ReceiveString();
            }
            catch
            {
                Console.WriteLine("Could not fetch responseString");
            }

            if (responseString != "")
            {
                var NewRecord = GetRunInfo(responseString, true, "IL"); // Get new record touple (name, time, floattime, date, datetime, timespan, info)
                if (!File.Exists(levelPath))
                {
                    using (StreamWriter sw = File.CreateText(levelPath))
                    {
                        sw.WriteLine(NewRecord.Item7);
                        Console.WriteLine("Created: " + levelName + " - |" + NewRecord.Item7);
                    }
                }
                else
                {
                    var      OldRecord            = GetRunInfo(File.ReadLines(levelPath).Last(), false, "IL");
                    double   timeDifferenceDouble = Math.Round((float.Parse(OldRecord.Item2) - float.Parse(NewRecord.Item2)) / 1000, 3);
                    string   timeDifference       = timeDifferenceDouble.ToString().Replace(",", ".");
                    TimeSpan dateDifference       = (NewRecord.Item5.Date.Subtract(OldRecord.Item5.Date));
                    GetOldestRecord(levelName, responseString, false);


                    if (OldRecord.Item2 != NewRecord.Item2)
                    {
                        string[] readText = File.ReadAllLines(GeneralPath + "OldestRecord.txt");
                        foreach (string z in readText)
                        {
                            if (z.Contains(levelName))
                            {
                                string topicString = "Longest standing records:\r\n";
                                var    tempFile    = Path.GetTempFileName();
                                var    linesToKeep = File.ReadLines(GeneralPath + "OldestRecord.txt").Where(l => !l.Contains(levelName));
                                File.WriteAllLines(tempFile, linesToKeep);
                                File.Delete(GeneralPath + "OldestRecord.txt");
                                File.Move(tempFile, GeneralPath + "OldestRecord.txt");
                                Console.WriteLine("Cleared Oldest Record Entry");
                                string[] readText2 = File.ReadAllLines(GeneralPath + "OldestRecord.txt");
                                foreach (string x in readText2)
                                {
                                    var    _xlevelName      = StringBuilding.getBetweenStr(x, "Level: ", " - Name:");
                                    var    _xtime           = StringBuilding.getBetweenStr(x, "Time: ", " | Date:");
                                    string _xconvertedTime  = ConvertTime(_xtime);
                                    var    _xdate           = StringBuilding.getBetweenStr(x, "Date: ", " |");
                                    var    _xconvertedDate  = DateTime.Parse(_xdate);
                                    var    _xdateDifference = (DateTime.Now.Date.Subtract(_xconvertedDate.Date));
                                    topicString = topicString + _xlevelName + " - [" + _xconvertedTime + "s] by " + StringBuilding.getBetweenStr(x, "Name: ", " | Time:") + " [" + _xdateDifference.Days.ToString() + " days]\r\n";
                                }
                                SetTopic(topicString);
                            }
                        }

                        using (StreamWriter sw = File.AppendText(levelPath))
                        {
                            sw.WriteLine(NewRecord.Item7);
                            Console.WriteLine("Added new record to " + levelName);
                            if (OldRecord.Item1 != NewRecord.Item1)
                            {
                                await Program._client.SendMessageAsync(channel, "**" + levelName + " - " + "[" + NewRecord.Item3 + "] :trophy: " + NewRecord.Item1 + "** beat **~~" + OldRecord.Item1 + "~~**'s record by **" + timeDifference + "s** (Record stood for **" + dateDifference.TotalDays.ToString() + " days!**)", false, null);
                            }
                            else
                            {
                                await Program._client.SendMessageAsync(channel, "**" + levelName + " - " + "[" + NewRecord.Item3 + "] :trophy: " + NewRecord.Item1 + "** improved their record by **" + timeDifference + "s** (Record stood for **" + dateDifference.TotalDays.ToString() + " days!**)", false, null);
                            }
                        }
                    }
                }

                Console.WriteLine("Update complete - " + levelName + " | " + DateTime.Now);
                if (ILCounter < LevelInfo.Length - 1)
                {
                    ILCounter++;
                }
                else
                {
                    if (UpdateBot == true)
                    {
                        UpdateBot = false;
                        Console.WriteLine("Bot refresh complete!");
                    }
                    ILCounter = 0;
                }
            }
        }