public MovieNotificationEngine( IMovieSearcher movieSearcher, IMovieNotifier notifier, ILogger <ChatBot> logger, MovieNotificationsRepository notificationRequestRepository) { _movieSearcher = movieSearcher; _notifier = notifier; _logger = logger; _notificationRequestRepository = notificationRequestRepository; }
public MovieNotificationEngine CreateMovieNotificationEngine(DiscordClient client, ILogger logger) { var settings = _settingsProvider.Provide(); IMovieNotifier movieNotifier = null; if (settings.NotificationMode == NotificationMode.PrivateMessage) { movieNotifier = new PrivateMessageMovieNotifier(client, logger); } else if (settings.NotificationMode == NotificationMode.Channels) { movieNotifier = new ChannelMovieNotifier(client, settings.NotificationChannels.Select(x => ulong.Parse(x)).ToArray(), logger); } else { throw new Exception($"Could not create movie notifier of type \"{settings.NotificationMode}\""); } return(new MovieNotificationEngine(GetMovieClient <IMovieSearcher>(settings), movieNotifier, logger, _notificationsRepository)); }
private async Task Connected() { try { if (_movieNotificationEngine != null) { await _movieNotificationEngine.StopAsync(); } if (_currentSettings.MovieDownloadClient != DownloadClient.Disabled && _currentSettings.NotificationMode != NotificationMode.Disabled) { IMovieNotifier movieNotifier = null; if (_currentSettings.NotificationMode == NotificationMode.PrivateMessage) { movieNotifier = new PrivateMessageMovieNotifier(_client, _logger); } else if (_currentSettings.NotificationMode == NotificationMode.Channels) { movieNotifier = new ChannelMovieNotifier(_client, _currentSettings.NotificationChannels, _logger); } else { throw new Exception($"Could not create movie notifier of type \"{_currentSettings.NotificationMode}\""); } _movieNotificationEngine = new MovieNotificationEngine(GetMovieClient <IMovieSearcher>(_currentSettings), movieNotifier, _logger, _movieNotificationRequestRepository); _movieNotificationEngine.Start(); } } catch (System.Exception ex) { _logger.LogError(ex, "Error while starting movie notification engine: " + ex.Message); } try { if (_tvShowNotificationEngine != null) { await _tvShowNotificationEngine.StopAsync(); } if (_currentSettings.TvShowDownloadClient != DownloadClient.Disabled && _currentSettings.NotificationMode != NotificationMode.Disabled) { ITvShowNotifier tvShowNotifier = null; if (_currentSettings.NotificationMode == NotificationMode.PrivateMessage) { tvShowNotifier = new PrivateMessageTvShowNotifier(_client, _logger); } else if (_currentSettings.NotificationMode == NotificationMode.Channels) { tvShowNotifier = new ChannelTvShowNotifier(_client, _currentSettings.NotificationChannels, _logger); } else { throw new Exception($"Could not create tv show notifier of type \"{_currentSettings.NotificationMode}\""); } _tvShowNotificationEngine = new TvShowNotificationEngine(GetTvShowClient <ITvShowSearcher>(_currentSettings), tvShowNotifier, _logger, _tvShowNotificationRequestRepository); _tvShowNotificationEngine.Start(); } } catch (System.Exception ex) { _logger.LogError(ex, "Error while starting tv show notification engine: " + ex.Message); } }