public UserFlairContextFactory(BerbotConnectionFactory connectionFactory) { this.connectionFactory = connectionFactory; this.auditClient = connectionFactory.CreateAuditClient(); this.modRedditClient = connectionFactory.CreateModRedditClient(); this.subreddit = modRedditClient.Subreddit(BerbotConfiguration.RedditSubredditName); }
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); }
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); }
private static Post GetNewPost(Subreddit subreddit, FeedType feedType, ICollection <string> seenPosts = null) { switch (feedType) { case FeedType.Hot: return(subreddit.Posts.Hot.SkipWhile(post => seenPosts == null || seenPosts.Contains(post.Fullname)).First()); case FeedType.New: return(subreddit.Posts.New.SkipWhile(post => seenPosts == null || seenPosts.Contains(post.Fullname)).First()); case FeedType.Rising: return(subreddit.Posts.Rising.SkipWhile(post => seenPosts == null || seenPosts.Contains(post.Fullname)).First()); case FeedType.Controversial: return(subreddit.Posts.Controversial.SkipWhile(post => seenPosts == null || seenPosts.Contains(post.Fullname)).First()); case FeedType.Top: return(subreddit.Posts.Top.SkipWhile(post => seenPosts == null || seenPosts.Contains(post.Fullname)).First()); default: return(subreddit.Posts.Best.SkipWhile(post => seenPosts == null || seenPosts.Contains(post.Fullname)).First()); } }