Exemple #1
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Starting reddit bot");

            if ((_config.GetValue("bot:REDDIT_CLIENT_ID", string.Empty) == string.Empty) ||
                (_config.GetValue("bot:REDDIT_REFRESH_TOKEN", string.Empty) == string.Empty) ||
                (_config.GetValue("bot:REDDIT_CLIENT_SECRET", string.Empty) == string.Empty))
            {
                _logger.LogWarning("Missing configuration entries for reddit");
                return(Task.CompletedTask);
            }

            if ((_config.GetValue("bot:REDDIT_SUBREDDIT", string.Empty) == string.Empty))
            {
                _logger.LogWarning("Missing configuration entry bot:REDDIT_SUBREDDIT");
                return(Task.CompletedTask);
            }

            _redditHelper = new RedditHelper(_config["DATACORE_WEB"], _logger, _searcher.Searcher, _crewData.BotHelper);

            _reddit = new RedditAPI(_config.GetValue <string>("bot:REDDIT_CLIENT_ID"), _config.GetValue <string>("bot:REDDIT_REFRESH_TOKEN"), _config.GetValue <string>("bot:REDDIT_CLIENT_SECRET"));

            _subReddit = _reddit.Subreddit(_config.GetValue <string>("bot:REDDIT_SUBREDDIT")).About();

            _subReddit.Posts.GetNew();
            _subReddit.Posts.MonitorNew();
            _subReddit.Posts.NewUpdated += c_NewPostAdded;

            return(Task.CompletedTask);
        }
Exemple #2
0
        public Task StopAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Stopping reddit bot");

            if (_subReddit != null)
            {
                _subReddit.Posts.MonitorNew();
                _subReddit.Posts.NewUpdated -= c_NewPostAdded;
                _subReddit    = null;
                _reddit       = null;
                _redditHelper = null;
            }

            return(Task.CompletedTask);
        }