public int SongHistory() { string user = User.Identity.GetUserName(); SongHistory s = new SongHistory(); s.songId = int.Parse(Request.QueryString["SongId"]); s.user = user; db.sh.Add(s); db.SaveChanges(); return(s.songId); }
/// <summary> /// Adds a song to the history. /// </summary> /// <param name="song">The song that should be added.</param> public void AddSongToHistory(Song song) { if (SongHistory.Any()) { if (((SongHistory.Last().StartTime - song.StartTime) < TimeSpan.FromSeconds(1)) && !((SongHistory.Last().StartTime - song.StartTime) < TimeSpan.FromSeconds(-1))) { return; } } SongHistory.Add(song); StoreHistory(song); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// /// <summary> /// Load database /// </summary> private void LoadDatabase() { try { string l_FilePath = m_DBFilePath; if (!System.IO.File.Exists(l_FilePath)) { Logger.Instance.Error("File not found " + m_DBFilePath); return; } var l_JSON = JObject.Parse(System.IO.File.ReadAllText(l_FilePath, UTF8Encoding.UTF8)); if (l_JSON["queue"] != null) { JArray l_JSONSongs = (JArray)l_JSON["queue"]; for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++) { SongEntry l_Entry = new SongEntry(); if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key")) l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]); else { l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", ""); JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap); } if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt")) l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>()); l_Entry.RequesterName = (string)l_JSONSongs[l_SongIt]["rqn"]; if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr")) l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"]; SongQueue.Add(l_Entry); /// Start populate l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry)); } } if (l_JSON["history"] != null) { JArray l_JSONSongs = (JArray)l_JSON["history"]; for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++) { SongEntry l_Entry = new SongEntry(); if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key")) l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]); else { l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", ""); JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap); } if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt")) l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>()); l_Entry.RequesterName = (string)l_JSONSongs[l_SongIt]["rqn"]; if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr")) l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"]; SongHistory.Add(l_Entry); /// Start populate l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry)); } } if (l_JSON["blacklist"] != null) { JArray l_JSONSongs = (JArray)l_JSON["blacklist"]; for (int l_SongIt = 0; l_SongIt < l_JSONSongs.Count; l_SongIt++) { SongEntry l_Entry = new SongEntry(); if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("key")) l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, (string)l_JSONSongs[l_SongIt]["key"]); else { l_Entry.BeatMap = new BeatSaverSharp.Beatmap(m_BeatSaver, "", "", ""); JsonConvert.PopulateObject((string)l_JSONSongs[l_SongIt]["btm"], l_Entry.BeatMap); } if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("rqt")) l_Entry.RequestTime = SDK.Misc.Time.FromUnixTime(l_JSONSongs[l_SongIt]["rqt"].Value<long>()); l_Entry.RequesterName = (string)l_JSONSongs[l_SongIt]["rqn"]; if ((l_JSONSongs[l_SongIt] as JObject).ContainsKey("npr")) l_Entry.NamePrefix = (string)l_JSONSongs[l_SongIt]["npr"]; SongBlackList.Add(l_Entry); /// Start populate l_Entry.BeatMap.Populate().ContinueWith(x => OnBeatmapPopulated(x, l_Entry)); } } } catch (System.Exception p_Exception) { Logger.Instance.Critical("LoadDataBase"); Logger.Instance.Critical(p_Exception); } }
/// <summary> /// Block a song /// </summary> /// <param name="p_Service">Chat service</param> /// <param name="p_Message">Chat message</param> /// <param name="p_ID">ID of the BSR</param> private void Command_Block(IChatService p_Service, IChatMessage p_Message, string p_ID) { if (!HasPower(p_Message.Sender)) { SendChatMessage($"@{p_Message.Sender.UserName} You have no power here!"); return; } string l_Key = p_ID.ToLower(); if (!OnlyHexInString(l_Key)) { SendChatMessage($"@{p_Message.Sender.UserName} Invalid key!"); return; } lock (SongBlackList) { var l_BeatMap = SongBlackList.Where(x => x.BeatMap.Key.ToLower() == l_Key).FirstOrDefault(); if (l_BeatMap != null) { SendChatMessage($"@{p_Message.Sender.UserName} (bsr {l_BeatMap.BeatMap.Key}) {l_BeatMap.BeatMap.Metadata.SongName} / {l_BeatMap.BeatMap.Metadata.LevelAuthorName} is already blacklisted!"); return; } } /// Fetch beatmap _ = m_BeatSaver.Key(l_Key).ContinueWith(p_SongTaskResult => { try { string l_Reply = "@" + p_Message.Sender.UserName + " map " + l_Key + " not found."; if (p_SongTaskResult.Result != null) { var l_BeatMap = p_SongTaskResult.Result; l_Reply = $"@{p_Message.Sender.UserName} (bsr {l_BeatMap.Key}) {l_BeatMap.Metadata.SongName} / {l_BeatMap.Metadata.LevelAuthorName} is now blacklisted!"; lock (SongQueue) { lock (SongHistory) { lock (SongBlackList) { SongQueue.RemoveAll(x => x.BeatMap.Key == l_BeatMap.Key); SongHistory.RemoveAll(x => x.BeatMap.Key == l_BeatMap.Key); /// Add to blacklist SongBlackList.RemoveAll(x => x.BeatMap.Hash == l_BeatMap.Hash); SongBlackList.Insert(0, new SongEntry() { BeatMap = l_BeatMap, NamePrefix = "🗡", RequesterName = p_Message.Sender.DisplayName }); } } } /// Update request manager OnQueueChanged(); } SendChatMessage(l_Reply); } catch (System.Exception p_Exception) { Logger.Instance.Error("Command_Block"); Logger.Instance.Error(p_Exception); } }); }