Exemplo n.º 1
0
        public async Task CmdResetYoutubeSongRequestList(bool hasYouTubeAuth)
        {
            try
            {
                if (!hasYouTubeAuth)
                {
                    _irc.SendPublicChatMessage("YouTube song requests have not been set up");
                    return;
                }

                // Check if user has a song request playlist, else create one
                string playlistName        = _botConfig.YouTubeBroadcasterPlaylistName;
                string defaultPlaylistName = $"Twitch Song Requests";

                if (string.IsNullOrEmpty(playlistName))
                {
                    playlistName = defaultPlaylistName;
                }

                Playlist broadcasterPlaylist = null;

                // Check for existing playlist id
                if (!string.IsNullOrEmpty(_botConfig.YouTubeBroadcasterPlaylistId))
                {
                    broadcasterPlaylist = await _youTubeClientInstance.GetBroadcasterPlaylistById(_botConfig.YouTubeBroadcasterPlaylistId);
                }

                if (broadcasterPlaylist?.Id != null)
                {
                    await _youTubeClientInstance.DeletePlaylist(broadcasterPlaylist.Id);
                }

                broadcasterPlaylist = await _youTubeClientInstance.CreatePlaylist(playlistName,
                                                                                  "Songs requested via Twitch viewers on https://twitch.tv/" + _botConfig.Broadcaster
                                                                                  + " . Playlist automatically created courtesy of https://github.com/SimpleSandman/TwitchBot");

                _botConfig.YouTubeBroadcasterPlaylistId = broadcasterPlaylist.Id;
                _appConfig.AppSettings.Settings.Remove("youTubeBroadcasterPlaylistId");
                _appConfig.AppSettings.Settings.Add("youTubeBroadcasterPlaylistId", broadcasterPlaylist.Id);
                _botConfig.YouTubeBroadcasterPlaylistName = broadcasterPlaylist.Snippet.Title;
                _appConfig.AppSettings.Settings.Remove("youTubeBroadcasterPlaylistName");
                _appConfig.AppSettings.Settings.Add("youTubeBroadcasterPlaylistName", broadcasterPlaylist.Snippet.Title);
                _appConfig.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("TwitchBotConfiguration");

                SongRequestSetting songRequestSetting = await _songRequestSetting.GetSongRequestSetting(_broadcasterInstance.DatabaseId);

                // ToDo: Make HTTP PATCH request instead of full PUT
                await _songRequestSetting.UpdateSongRequestSetting(
                    _botConfig.YouTubeBroadcasterPlaylistId, _botConfig.YouTubePersonalPlaylistId,
                    _broadcasterInstance.DatabaseId, songRequestSetting.DjMode);

                _irc.SendPublicChatMessage($"YouTube playlist has been reset @{_botConfig.Broadcaster} "
                                           + "and is now at this link https://www.youtube.com/playlist?list=" + _botConfig.YouTubeBroadcasterPlaylistId);
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdBrdCstr", "CmdResetYoutubeSongRequestList(bool)", false, "!resetytsr");
            }
        }