示例#1
0
        public async Task <SongRequestIgnore> IgnoreSong(string title, string artist, int broadcasterId)
        {
            SongRequestIgnore ignoreSong = new SongRequestIgnore
            {
                Artist        = artist,
                Title         = title,
                BroadcasterId = broadcasterId
            };

            return(await ApiBotRequest.PostExecuteAsync(_twitchBotApiLink + $"songrequestignores/create", ignoreSong));
        }
        public async Task <IActionResult> Create([FromBody] SongRequestIgnore songRequestIgnore)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.SongRequestIgnore.Add(songRequestIgnore);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { broadcasterId = songRequestIgnore.BroadcasterId, id = songRequestIgnore.Id }, songRequestIgnore));
        }
        public async Task <IActionResult> Update([FromRoute] int broadcasterId, [FromQuery] int id, [FromBody] SongRequestIgnore songRequestIgnore)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != songRequestIgnore.Id && broadcasterId != songRequestIgnore.BroadcasterId)
            {
                return(BadRequest());
            }

            _context.Entry(songRequestIgnore).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SongRequestBlacklistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(songRequestIgnore));
        }
        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 songRequestIgnore = new object();

            if (!string.IsNullOrEmpty(artist) && !string.IsNullOrEmpty(title))
            {
                SongRequestIgnore songRequestIgnoredItem = await _context.SongRequestIgnore
                                                           .SingleOrDefaultAsync(m => m.BroadcasterId == broadcasterId &&
                                                                                 m.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase) &&
                                                                                 m.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase));

                if (songRequestIgnoredItem == null)
                {
                    return(NotFound());
                }

                _context.SongRequestIgnore.Remove(songRequestIgnoredItem);

                songRequestIgnore = songRequestIgnoredItem;
            }
            else
            {
                List <SongRequestIgnore> songRequestBlacklistItems = new List <SongRequestIgnore>();

                if (!string.IsNullOrEmpty(artist))
                {
                    songRequestBlacklistItems = await _context.SongRequestIgnore
                                                .Where(m => m.BroadcasterId == broadcasterId &&
                                                       m.Artist.Equals(artist, StringComparison.CurrentCultureIgnoreCase))
                                                .ToListAsync();
                }
                else
                {
                    songRequestBlacklistItems = await _context.SongRequestIgnore
                                                .Where(m => m.BroadcasterId == broadcasterId)
                                                .ToListAsync();
                }

                if (songRequestBlacklistItems == null || songRequestBlacklistItems.Count == 0)
                {
                    return(NotFound());
                }

                _context.SongRequestIgnore.RemoveRange(songRequestBlacklistItems);

                songRequestIgnore = songRequestBlacklistItems;
            }

            await _context.SaveChangesAsync();

            return(Ok(songRequestIgnore));
        }
示例#5
0
        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 == "1") // remove blackout for any song by this artist
                {
                    // remove artist from db
                    List <SongRequestIgnore> response = await _songRequest.AllowArtist(request, _broadcasterInstance.DatabaseId);

                    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 == "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
                    SongRequestIgnore response = await _songRequest.AllowSong(songTitle, artist, _broadcasterInstance.DatabaseId);

                    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, "!delsrbl");
            }
        }
示例#6
0
        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 == "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 <SongRequestIgnore> blacklist = await _songRequest.GetSongRequestIgnore(_broadcasterInstance.DatabaseId);

                    if (blacklist.Count > 0 && blacklist.Exists(b => b.Artist.Equals(request, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        _irc.SendPublicChatMessage($"This artist/video is already on the blacklist @{_botConfig.Broadcaster}");
                        return;
                    }

                    SongRequestIgnore response = await _songRequest.IgnoreArtist(request, _broadcasterInstance.DatabaseId);

                    if (response != null)
                    {
                        _irc.SendPublicChatMessage($"The artist/video \"{response.Artist}\" has been added to the blacklist @{_botConfig.Broadcaster}");
                    }
                    else
                    {
                        _irc.SendPublicChatMessage($"I'm sorry. I'm not able to add this artist/video to the blacklist at this time @{_botConfig.Broadcaster}");
                    }
                }
                else if (requestType == "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 <SongRequestIgnore> blacklist = await _songRequest.GetSongRequestIgnore(_broadcasterInstance.DatabaseId);

                    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;
                        }
                    }

                    SongRequestIgnore response = await _songRequest.IgnoreSong(songTitle, artist, _broadcasterInstance.DatabaseId);

                    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");
            }
        }