public async Task <SongRequestBlacklist> AddSongToBlacklist(string title, string artist, int broadcasterId) { SongRequestBlacklist blacklistedSong = new SongRequestBlacklist { Artist = artist, Title = title, Broadcaster = broadcasterId }; return(await ApiBotRequest.PostExecuteTaskAsync(_twitchBotApiLink + $"songrequestblacklists/create", blacklistedSong)); }
public async Task <IActionResult> Create([FromBody] SongRequestBlacklist songRequestBlacklist) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.SongRequestBlacklist.Add(songRequestBlacklist); await _context.SaveChangesAsync(); return(CreatedAtAction("Get", new { broadcasterId = songRequestBlacklist.Broadcaster, id = songRequestBlacklist.Id }, songRequestBlacklist)); }
public async Task CmdRemoveSongRequestBlacklist(string message) { try { int requestIndex = message.GetNthCharIndex(' ', 2); if (requestIndex == -1) { _irc.SendPublicChatMessage($"Please enter a request @{_botConfig.Broadcaster}"); return; } string requestType = message.Substring(message.IndexOf(" ") + 1, 1); string request = message.Substring(requestIndex + 1); // Check if request is based on an artist or just a song by an artist if (requestType.Equals("1")) // remove blackout for any song by this artist { // remove artist from db List <SongRequestBlacklist> response = await _songRequest.DeleteArtistFromBlacklist(request, _broadcasterId); if (response != null) { _irc.SendPublicChatMessage($"The artist \"{request}\" can now be requested @{_botConfig.Broadcaster}"); } else { _irc.SendPublicChatMessage($"Couldn't find the requested artist for blacklist-removal @{_botConfig.Broadcaster}"); } } else if (requestType.Equals("2")) // remove blackout for a song by an artist { if (request.Count(c => c == '"') < 2 || request.Count(c => c == '<') != 1 || request.Count(c => c == '>') != 1) { _irc.SendPublicChatMessage($"Please surround the song title with \" (quotation marks) " + $"and the artist with \"<\" and \">\" @{_botConfig.Broadcaster}"); return; } int songTitleStartIndex = message.IndexOf('"'); int songTitleEndIndex = message.LastIndexOf('"'); int artistStartIndex = message.IndexOf('<'); int artistEndIndex = message.IndexOf('>'); string songTitle = message.Substring(songTitleStartIndex + 1, songTitleEndIndex - songTitleStartIndex - 1); string artist = message.Substring(artistStartIndex + 1, artistEndIndex - artistStartIndex - 1); // remove artist from db SongRequestBlacklist response = await _songRequest.DeleteSongFromBlacklist(songTitle, artist, _broadcasterId); if (response != null) { _irc.SendPublicChatMessage($"The song \"{response.Title} by {response.Artist}\" can now requested @{_botConfig.Broadcaster}"); } else { _irc.SendPublicChatMessage($"Couldn't find the requested song for blacklist-removal @{_botConfig.Broadcaster}"); } } else { _irc.SendPublicChatMessage($"Please insert request type (1 = artist/2 = song) @{_botConfig.Broadcaster}"); return; } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdRemoveSongRequestBlacklist(string)", false, "!removesrbl"); } }
public async Task CmdAddSongRequestBlacklist(string message) { try { int requestIndex = message.GetNthCharIndex(' ', 2); if (requestIndex == -1) { _irc.SendPublicChatMessage($"Please enter a request @{_botConfig.Broadcaster}"); return; } string requestType = message.Substring(message.IndexOf(" ") + 1, 1); string request = message.Substring(requestIndex + 1); // Check if request is based on an artist or just a song by an artist if (requestType.Equals("1")) // blackout any song by this artist { // check if song-specific request is being used for artist blackout if (request.Count(c => c == '"') == 2 || request.Count(c => c == '<') == 1 || request.Count(c => c == '>') == 1) { _irc.SendPublicChatMessage($"Please use request type 2 for song-specific blacklist-restrictions @{_botConfig.Broadcaster}"); return; } List <SongRequestBlacklist> blacklist = await _songRequest.GetSongRequestBlackList(_broadcasterId); if (blacklist.Count > 0 && blacklist.Exists(b => b.Artist.Equals(request, StringComparison.CurrentCultureIgnoreCase))) { _irc.SendPublicChatMessage($"This song is already on the blacklist @{_botConfig.Broadcaster}"); return; } SongRequestBlacklist response = await _songRequest.AddArtistToBlacklist(request, _broadcasterId); if (response != null) { _irc.SendPublicChatMessage($"The artist \"{response.Artist}\" has been added to the blacklist @{_botConfig.Broadcaster}"); } else { _irc.SendPublicChatMessage($"I'm sorry. I'm not able to add this artist to the blacklist at this time @{_botConfig.Broadcaster}"); } } else if (requestType.Equals("2")) // blackout a song by an artist { if (request.Count(c => c == '"') < 2 || request.Count(c => c == '<') != 1 || request.Count(c => c == '>') != 1) { _irc.SendPublicChatMessage($"Please surround the song title with \" (quotation marks) " + $"and the artist with \"<\" and \">\" @{_botConfig.Broadcaster}"); return; } int songTitleStartIndex = message.IndexOf('"'); int songTitleEndIndex = message.LastIndexOf('"'); int artistStartIndex = message.IndexOf('<'); int artistEndIndex = message.IndexOf('>'); string songTitle = message.Substring(songTitleStartIndex + 1, songTitleEndIndex - songTitleStartIndex - 1); string artist = message.Substring(artistStartIndex + 1, artistEndIndex - artistStartIndex - 1); // check if the request's exact song or artist-wide blackout-restriction has already been added List <SongRequestBlacklist> blacklist = await _songRequest.GetSongRequestBlackList(_broadcasterId); if (blacklist.Count > 0) { if (blacklist.Exists(b => b.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase) && b.Title.Equals(songTitle, StringComparison.CurrentCultureIgnoreCase))) { _irc.SendPublicChatMessage($"This song is already on the blacklist @{_botConfig.Broadcaster}"); return; } else if (blacklist.Exists(b => b.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase))) { _irc.SendPublicChatMessage($"This song's artist is already on the blacklist @{_botConfig.Broadcaster}"); return; } } SongRequestBlacklist response = await _songRequest.AddSongToBlacklist(songTitle, artist, _broadcasterId); if (response != null) { _irc.SendPublicChatMessage($"The song \"{response.Title} by {response.Artist}\" has been added to the blacklist @{_botConfig.Broadcaster}"); } else { _irc.SendPublicChatMessage($"I'm sorry. I'm not able to add this song to the blacklist at this time @{_botConfig.Broadcaster}"); } } else { _irc.SendPublicChatMessage($"Please insert request type (1 = artist/2 = song) @{_botConfig.Broadcaster}"); return; } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdAddSongRequestBlacklist(string)", false, "!srbl"); } }
public async Task <IActionResult> Update([FromRoute] int broadcasterId, [FromQuery] int id, [FromBody] SongRequestBlacklist songRequestBlacklist) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != songRequestBlacklist.Id && broadcasterId != songRequestBlacklist.Broadcaster) { return(BadRequest()); } _context.Entry(songRequestBlacklist).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SongRequestBlacklistExists(id)) { return(NotFound()); } else { throw; } } return(Ok(songRequestBlacklist)); }
public async Task <IActionResult> Delete([FromRoute] int broadcasterId, [FromQuery] string artist = "", [FromQuery] string title = "") { // don't accept an invalid model state or a request with just the title if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else if (string.IsNullOrEmpty(artist) && !string.IsNullOrEmpty(title)) { return(BadRequest()); } var songRequestBlacklist = new object(); if (!string.IsNullOrEmpty(artist) && !string.IsNullOrEmpty(title)) { SongRequestBlacklist songRequestBlacklistItem = await _context.SongRequestBlacklist .SingleOrDefaultAsync(m => m.Broadcaster == broadcasterId && m.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase) && m.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase)); if (songRequestBlacklistItem == null) { return(NotFound()); } _context.SongRequestBlacklist.Remove(songRequestBlacklistItem); songRequestBlacklist = songRequestBlacklistItem; } else { List <SongRequestBlacklist> songRequestBlacklistItems = new List <SongRequestBlacklist>(); if (!string.IsNullOrEmpty(artist)) { songRequestBlacklistItems = await _context.SongRequestBlacklist .Where(m => m.Broadcaster == broadcasterId && m.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase)) .ToListAsync(); } else { songRequestBlacklistItems = await _context.SongRequestBlacklist .Where(m => m.Broadcaster == broadcasterId) .ToListAsync(); } if (songRequestBlacklistItems == null || songRequestBlacklistItems.Count == 0) { return(NotFound()); } _context.SongRequestBlacklist.RemoveRange(songRequestBlacklistItems); songRequestBlacklist = songRequestBlacklistItems; } await _context.SaveChangesAsync(); return(Ok(songRequestBlacklist)); }