public static void DequeueRequest(SongRequest request, bool updateUI = true) { if (request.status != RequestStatus.Wrongsong && request.status != RequestStatus.SongSearch) { RequestHistory.Songs.Insert(0, request); // Wrong song requests are not logged into history, is it possible that other status states shouldn't be moved either? } if (RequestHistory.Songs.Count > RequestBotConfig.Instance.RequestHistoryLimit) { int diff = RequestHistory.Songs.Count - RequestBotConfig.Instance.RequestHistoryLimit; RequestHistory.Songs.RemoveRange(RequestHistory.Songs.Count - diff - 1, diff); } RequestQueue.Songs.Remove(request); RequestHistory.Write(); RequestQueue.Write(); // Decrement the requestors request count, since their request is now out of the queue if (!RequestBotConfig.Instance.LimitUserRequestsToSession) { if (RequestTracker.ContainsKey(request.requestor.Id)) { RequestTracker[request.requestor.Id].numRequests--; } } if (updateUI == false) { return; } UpdateRequestUI(); _refreshQueue = true; }
private void Awake() { DontDestroyOnLoad(gameObject); Instance = this; #if UNRELEASED var startingmem = GC.GetTotalMemory(true); //var folder = Path.Combine(Environment.CurrentDirectory, "userdata","streamcore"); //List<FileInfo> files = new List<FileInfo>(); // List that will hold the files and subfiles in path //List<DirectoryInfo> folders = new List<DirectoryInfo>(); // List that hold direcotries that cannot be accessed //DirectoryInfo di = new DirectoryInfo(folder); //Dictionary<string, string> remap = new Dictionary<string, string>(); //foreach (var entry in listcollection.OpenList("all.list").list) // { // //Instance.QueueChatMessage($"Map {entry}"); // string[] remapparts = entry.Split('-'); // if (remapparts.Length == 2) // { // int o; // if (Int32.TryParse(remapparts[1], out o)) // { // try // { // remap.Add(remapparts[0], o.ToString("x")); // } // catch // { } // //Instance.QueueChatMessage($"Map {remapparts[0]} : {o.ToString("x")}"); // } // } //} //Instance.QueueChatMessage($"Scanning lists"); //FullDirList(di, "*.deck"); //void FullDirList(DirectoryInfo dir, string searchPattern) //{ // try // { // foreach (FileInfo f in dir.GetFiles(searchPattern)) // { // var List = listcollection.OpenList(f.Name).list; // for (int i=0;i<List.Count;i++) // { // if (remap.ContainsKey(List[i])) // { // //Instance.QueueChatMessage($"{List[i]} : {remap[List[i]]}"); // List[i] = remap[List[i]]; // } // } // listcollection.OpenList(f.Name).Writefile(f.Name); // } // } // catch // { // Console.WriteLine("Directory {0} \n could not be accessed!!!!", dir.FullName); // return; // } //} //NOTJSON.UNITTEST(); #endif playedfilename = Path.Combine(Plugin.DataPath, "played.dat"); // Record of all the songs played in the current session try { string filesToDelete = Path.Combine(Environment.CurrentDirectory, "FilesToDelete"); if (Directory.Exists(filesToDelete)) { EmptyDirectory(filesToDelete); } try { DateTime LastBackup; if (!DateTime.TryParse(RequestBotConfig.Instance.LastBackup, out LastBackup)) { LastBackup = DateTime.MinValue; } TimeSpan TimeSinceBackup = DateTime.Now - LastBackup; if (TimeSinceBackup > TimeSpan.FromHours(RequestBotConfig.Instance.SessionResetAfterXHours)) { Backup(); } } catch (Exception ex) { Plugin.Log(ex.ToString()); Instance.QueueChatMessage("Failed to run Backup"); } try { TimeSpan PlayedAge = GetFileAgeDifference(playedfilename); if (PlayedAge < TimeSpan.FromHours(RequestBotConfig.Instance.SessionResetAfterXHours)) { played = ReadJSON(playedfilename); // Read the songsplayed file if less than x hours have passed } } catch (Exception ex) { Plugin.Log(ex.ToString()); Instance.QueueChatMessage("Failed to clear played file"); } if (RequestBotConfig.Instance.PPSearch) { GetPPData(); // Start loading PP data } MapDatabase.LoadDatabase(); if (RequestBotConfig.Instance.LocalSearch) { MapDatabase.LoadCustomSongs(); // This is a background process } RequestQueue.Read(); // Might added the timespan check for this too. To be decided later. RequestHistory.Read(); listcollection.OpenList("banlist.unique"); #if UNRELEASED //GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; //GC.Collect(); //Instance.QueueChatMessage($"hashentries: {SongMap.hashcount} memory: {(GC.GetTotalMemory(false) - startingmem) / 1048576} MB"); #endif listcollection.ClearOldList("duplicate.list", TimeSpan.FromHours(RequestBotConfig.Instance.SessionResetAfterXHours)); UpdateRequestUI(); InitializeCommands(); //EnhancedStreamChat.ChatHandler.ChatMessageFilters += MyChatMessageHandler; // TODO: Reimplement this filter maybe? Or maybe we put it directly into EnhancedStreamChat COMMAND.CommandConfiguration(); RunStartupScripts(); ProcessRequestQueue(); RequestBotConfig.Instance.ConfigChangedEvent += OnConfigChangedEvent; } catch (Exception ex) { Plugin.Log(ex.ToString()); Instance.QueueChatMessage(ex.ToString()); } }