public SpotifyFeature(IrcClient irc, TwitchBotConfigurationSection botConfig, SpotifyWebClient spotify) : base(irc, botConfig)
 {
     _spotify = spotify;
     _rolePermissions.Add("!spotifyconnect", new CommandPermission {
         General = ChatterType.Broadcaster
     });
     _rolePermissions.Add("!spotifyplay", new CommandPermission {
         General = ChatterType.Broadcaster
     });
     _rolePermissions.Add("!spotifypause", new CommandPermission {
         General = ChatterType.Broadcaster
     });
     _rolePermissions.Add("!spotifyprev", new CommandPermission {
         General = ChatterType.Broadcaster
     });
     _rolePermissions.Add("!spotifyback", new CommandPermission {
         General = ChatterType.Broadcaster
     });
     _rolePermissions.Add("!spotifynext", new CommandPermission {
         General = ChatterType.Broadcaster
     });
     _rolePermissions.Add("!spotifyskip", new CommandPermission {
         General = ChatterType.Broadcaster
     });
     _rolePermissions.Add("!spotifysong", new CommandPermission {
         General = ChatterType.Viewer
     });
     _rolePermissions.Add("!spotifylastsong", new CommandPermission {
         General = ChatterType.Viewer
     });
 }
Beispiel #2
0
 public CommandSystem(IrcClient irc, TwitchBotConfigurationSection botConfig, Configuration appConfig, BankService bank,
                      SongRequestBlacklistService songRequestBlacklist, LibVLCSharpPlayer libVLCSharpPlayer, SongRequestSettingService songRequestSetting,
                      SpotifyWebClient spotify, TwitchInfoService twitchInfo, FollowerService follower, GameDirectoryService gameDirectory, InGameUsernameService ign,
                      ManualSongRequestService manualSongRequest, QuoteService quote, PartyUpService partyUp)
 {
     _bank                     = new BankFeature(irc, botConfig, bank);
     _followerFeature          = new FollowerFeature(irc, botConfig, twitchInfo, follower, appConfig);
     _generalFeature           = new GeneralFeature(irc, botConfig, twitchInfo, appConfig);
     _inGameNameFeature        = new InGameNameFeature(irc, botConfig, twitchInfo, gameDirectory, ign);
     _joinStreamerFeature      = new JoinStreamerFeature(irc, botConfig, twitchInfo, gameDirectory);
     _libVLCSharpPlayerFeature = new LibVLCSharpPlayerFeature(irc, botConfig, appConfig, libVLCSharpPlayer);
     _miniGameFeature          = new MinigameFeature(irc, botConfig, bank, follower, twitchInfo);
     _multiLinkUserFeature     = new MultiLinkUserFeature(irc, botConfig);
     _partyUpFeature           = new PartyUpFeature(irc, botConfig, twitchInfo, gameDirectory, partyUp);
     _quoteFeature             = new QuoteFeature(irc, botConfig, quote);
     _reminderFeature          = new RefreshFeature(irc, botConfig, twitchInfo, gameDirectory);
     _songRequestFeature       = new SongRequestFeature(irc, botConfig, appConfig, songRequestBlacklist, libVLCSharpPlayer, songRequestSetting, manualSongRequest, bank, spotify);
     _spotifyFeature           = new SpotifyFeature(irc, botConfig, spotify);
     _twitchChannelFeature     = new TwitchChannelFeature(irc, botConfig, gameDirectory);
     _twitter                  = new TwitterFeature(irc, botConfig, appConfig);
 }
Beispiel #3
0
        public async Task RunAsync()
        {
            try
            {
                // ToDo: Check version number of application
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error Message: {ex.Message}");
                Console.WriteLine();
                Console.WriteLine("Cannot connect to database to verify the correct version of myself");
                Console.WriteLine("Local troubleshooting needed by author of this bot");
                Console.WriteLine();
                Console.WriteLine("Shutting down now...");
                Thread.Sleep(5000);
                Environment.Exit(1);
            }

            try
            {
                // Configure error handler singleton class
                ErrorHandler.Configure(_broadcasterInstance.DatabaseId, _irc, _botConfig);

                // Get broadcaster ID so the user can only see their data from the db
                await SetBroadcasterIdsAsync();

                if (_broadcasterInstance.DatabaseId == 0 || string.IsNullOrEmpty(_broadcasterInstance.TwitchId))
                {
                    Console.WriteLine("Cannot find a broadcaster ID for you. "
                                      + "Please contact the author with a detailed description of the issue");
                    Console.WriteLine();
                    Console.WriteLine("Shutting down now...");
                    Thread.Sleep(5000);
                    Environment.Exit(1);
                }

                // Configure error handler singleton class
                ErrorHandler.Configure(_broadcasterInstance.DatabaseId, _irc, _botConfig);

                /* Connect to local Spotify client */
                _spotify = new SpotifyWebClient(_botConfig);
                await _spotify.ConnectAsync();

                /* Load command classes */
                _commandSystem = new CommandSystem(_irc, _botConfig, _appConfig, _bank, _songRequestBlacklist,
                                                   _libVLCSharpPlayer, _songRequestSetting, _spotify, _twitchInfo, _follower, _gameDirectory,
                                                   _ign, _manualSongRequest, _quote, _partyUp);

                /* Whisper broadcaster bot settings */
                Console.WriteLine();
                Console.WriteLine("---> Extra Bot Settings <---");
                Console.WriteLine($"Currency type: {_botConfig.CurrencyType}");
                Console.WriteLine($"Enable Auto Tweets: {_botConfig.EnableTweets}");
                Console.WriteLine($"Enable Auto Display Songs: {_botConfig.EnableDisplaySong}");
                Console.WriteLine($"Stream latency: {_botConfig.StreamLatency} second(s)");
                Console.WriteLine($"Regular follower hours: {_botConfig.RegularFollowerHours}");
                Console.WriteLine();

                /* Configure YouTube song request from user's YT account (request permission if needed) */
                await GetYouTubeAuthAsync();

                /* Start listening for delayed messages */
                DelayMessage delayMsg = new DelayMessage(_irc);
                delayMsg.Start();

                /* Grab list of chatters from channel */
                _twitchChatterListener.Start();

                /* Get the status of the Twitch stream */
                _twitchStreamStatus = new TwitchStreamStatus(_irc, _twitchInfo, _botConfig.Broadcaster);
                await _twitchStreamStatus.LoadChannelInfoAsync();

                _twitchStreamStatus.Start();

                /* Pull list of followers and check experience points for stream leveling */
                _followerSubscriberListener.Start(_irc, _broadcasterInstance.DatabaseId);

                /* Load/create settings and start the queue for the heist */
                await _bankHeistInstance.LoadSettings(_broadcasterInstance.DatabaseId, _botConfig.TwitchBotApiLink);

                _bankHeist.Start(_irc, _broadcasterInstance.DatabaseId);

                if (string.IsNullOrEmpty(TwitchStreamStatus.CurrentCategory))
                {
                    _irc.SendPublicChatMessage("WARNING: I cannot see the name of the game. It's currently set to either NULL or EMPTY. "
                                               + "Please have the chat verify that the game has been set for this stream. "
                                               + $"If the error persists, please have @{_botConfig.Broadcaster.ToLower()} retype the game in their Twitch Live Dashboard. "
                                               + "If this error shows up again and your chat can see the game set for the stream, please contact my master with !support in this chat");
                }

                // Grab game id in order to find party member
                TwitchGameCategory game = await _gameDirectory.GetGameIdAsync(TwitchStreamStatus.CurrentCategory);

                /* Load/create settings and start the queue for the boss fight */
                await _bossFightInstance.LoadSettings(_broadcasterInstance.DatabaseId, game?.Id, _botConfig.TwitchBotApiLink);

                _bossFight.Start(_irc, _broadcasterInstance.DatabaseId);

                /* Ping to twitch server to prevent auto-disconnect */
                PingSender ping = new PingSender(_irc);
                ping.Start();

                /* Send reminders of certain events */
                ChatReminder chatReminder = new ChatReminder(_irc, _broadcasterInstance.DatabaseId, _botConfig.TwitchBotApiLink, _twitchInfo, _gameDirectory);
                chatReminder.Start();

                /* Load in Twitch users that have bot moderation privileges (separate from channel moderators) */
                await _botModeratorInstance.LoadExistingModerators(_botConfig.TwitchBotApiLink, _broadcasterInstance.DatabaseId);

                /* Load in custom commands */
                await _customCommandInstance.LoadCustomCommands(_botConfig.TwitchBotApiLink, _broadcasterInstance.DatabaseId);

                /* Authenticate to Twitter if possible */
                GetTwitterAuth();

                Console.WriteLine("===== Time to get to work! =====");
                Console.WriteLine();

                /* Finished setup, time to start */
                await GetChatBoxAsync();
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "TwitchBotApplication", "RunAsync()", true);
            }
        }
        /// <summary>
        /// Displays the current song being played from Spotify
        /// </summary>
        /// <param name="chatter">User that sent the message</param>
        public static async Task <string> SpotifyCurrentSongAsync(TwitchChatter chatter, SpotifyWebClient spotify)
        {
            PlaybackContext playbackContext = await spotify.GetPlaybackAsync();

            if (playbackContext != null && playbackContext.IsPlaying)
            {
                string artistName = "";

                foreach (SimpleArtist simpleArtist in playbackContext.Item.Artists)
                {
                    artistName += $"{simpleArtist.Name}, ";
                }

                artistName = artistName.ReplaceLastOccurrence(", ", "");

                TimeSpan progressTimeSpan = TimeSpan.FromMilliseconds(playbackContext.ProgressMs);
                TimeSpan durationTimeSpan = TimeSpan.FromMilliseconds(playbackContext.Item.DurationMs);

                return($"@{chatter.DisplayName} <-- Now playing from Spotify: \"{playbackContext.Item.Name}\" by {artistName} "
                       + "https://open.spotify.com/track/" + playbackContext.Item.Id + " "
                       + $"Currently playing at {progressTimeSpan.ReformatTimeSpan()} of {durationTimeSpan.ReformatTimeSpan()}");
            }
            else
            {
                return($"Nothing is playing at the moment @{chatter.DisplayName}");
            }
        }
        /// <summary>
        /// Displays the last song played from Spotify
        /// </summary>
        /// <param name="chatter">User that sent the message</param>
        public static async Task <string> SpotifyLastPlayedSongAsync(TwitchChatter chatter, SpotifyWebClient spotify)
        {
            SimpleTrack simpleTrack = await spotify.GetLastPlayedSongAsync();

            if (simpleTrack != null)
            {
                string artistName = "";

                foreach (SimpleArtist simpleArtist in simpleTrack.Artists)
                {
                    artistName += $"{simpleArtist.Name}, ";
                }

                artistName = artistName.ReplaceLastOccurrence(", ", "");

                return($"@{chatter.DisplayName} <-- Last played from Spotify: \"{simpleTrack.Name}\" by {artistName} "
                       + "https://open.spotify.com/track/" + simpleTrack.Id + " WARNING: This is currently a feature in BETA --> "
                       + "https://developer.spotify.com/documentation/web-api/reference/player/get-recently-played/");
            }
            else
            {
                return($"Nothing was played recently @{chatter.DisplayName}");
            }
        }