Example #1
0
 public CommentService(IUnitOfWorkFactory uowFactory, IRepositoryFactory repositoryFactory, ILogFactory logFactory)
 {
     _unitOfWorkFactory = uowFactory;
     _repositoryFactory = repositoryFactory;
     _commentBuilder    = new CommentBuilder();
     _logger            = logFactory.CreateLogger(GetType());
 }
Example #2
0
 internal PostRepository(IUnitOfWork uow)
 {
     UnitOfWork          = uow;
     _commentBuilder     = new CommentBuilder();
     _postBuilder        = new PostBuilder();
     _commentRepository  = new CommentRepository(uow);
     _categoryRepository = new CategoryRepository(uow);
 }
Example #3
0
 public CommentValidator(AppConfiguration appConfiguration,
                         IDB4Repository db4Repository,
                         ICommentBuilder commentBuilder)
 {
     _appConfiguration = appConfiguration;
     _db4Repository    = db4Repository;
     _commentBuilder   = commentBuilder;
 }
 public StickyCommentEditor(ICommentBuilder commentBuilder,
                            ICommentDetector commentDetector,
                            ICommentReplier commentReplier,
                            IDB4Repository repository)
 {
     _commentBuilder  = commentBuilder;
     _commentDetector = commentDetector;
     _commentReplier  = commentReplier;
     _repository      = repository;
 }
 public ModDeleteDeltaPMHandler(AppConfiguration appConfiguration,
                                IRedditService redditService,
                                ICommentDetector commentDetector,
                                ICommentBuilder commentBuilder,
                                ICommentReplier replier,
                                IDeltaAwarder deltaAwarder)
 {
     _appConfiguration = appConfiguration;
     _redditService    = redditService;
     _commentDetector  = commentDetector;
     _commentBuilder   = commentBuilder;
     _replier          = replier;
     _deltaAwarder     = deltaAwarder;
 }
Example #6
0
 public BlogService(
     IPostRepository postRepository,
     ICommentRepository commentRepository,
     IPostBuilder postBuilder,
     ICommentBuilder commentBuilder,
     IEmailService emailService,
     INotificationBuilder notificationBuilder,
     BlogOptions options,
     ILogger <BlogService> logger)
 {
     _postRepository      = postRepository;
     _commentRepository   = commentRepository;
     _postBuilder         = postBuilder;
     _commentBuilder      = commentBuilder;
     _emailService        = emailService;
     _notificationBuilder = notificationBuilder;
     _options             = options;
     _logger = logger;
 }
Example #7
0
 public PrivateMessageHandlerFactory(AppConfiguration appConfiguration,
                                     IDB4Repository db4Repository,
                                     IRedditService redditService,
                                     ISubredditService subredditService,
                                     ICommentDetector commentDetector,
                                     ICommentBuilder commentBuilder,
                                     ICommentReplier replier,
                                     IDeltaAwarder deltaAwarder,
                                     IStickyCommentEditor stickyCommentEditor)
 {
     _appConfiguration    = appConfiguration;
     _db4Repository       = db4Repository;
     _redditService       = redditService;
     _subredditService    = subredditService;
     _commentDetector     = commentDetector;
     _commentBuilder      = commentBuilder;
     _replier             = replier;
     _deltaAwarder        = deltaAwarder;
     _stickyCommentEditor = stickyCommentEditor;
 }
Example #8
0
        public void Run(
            IBotSettings settings,
            ISetlistAgent setlistAgent,
            ICommentBuilder commentBuilder,
            ICommentRepository commentRepository)
        {
            // todo arg null checks

            TelemetryClient telemetry = new TelemetryClient();

            try
            {
                string          subredditName = string.Format("/r/{0}", settings.Subreddit);
                DateParser      dateParser    = new DateParser();
                List <ISetlist> setlists      = new List <ISetlist>();

                BotWebAgent webAgent = new BotWebAgent(settings.Username, settings.Password, settings.Key, settings.Secret, "http://127.0.0.1");
                Reddit      reddit   = new Reddit(webAgent, true);
                reddit.RateLimit = WebAgent.RateLimitMode.Pace;

                Subreddit subreddit = reddit.GetSubreddit(subredditName);

                IEnumerable <Comment> comments = subreddit.Comments.Take(settings.MaxComments);

                foreach (Comment comment in comments)
                {
                    if (!comment.Body.ToLower().Contains(settings.Username))
                    {
                        continue;
                    }

                    if (commentRepository.CommentExists(comment.Id))
                    {
                        continue;
                    }

                    setlists.Clear();
                    string reply = string.Empty;

                    List <DateTime> dates = dateParser.ParseDates(comment.Body);
                    foreach (DateTime date in dates)
                    {
                        setlists.AddRange(setlistAgent.GetSetlists(date.Year, date.Month, date.Day));
                    }

                    if (setlists.Count > 1)
                    {
                        reply = commentBuilder.Build(setlists);
                    }
                    else if (setlists.Count == 1)
                    {
                        reply = commentBuilder.Build(setlists.First());
                    }

                    if (reply.Length > 0)
                    {
                        comment.Reply(reply);
                        commentRepository.SaveComment(comment.Id, comment.Body, reply);
                    }
                }
            }
            catch (RateLimitException rle)
            {
                // cool it down for 3 minutes
                telemetry.TrackException(rle);
                Thread.Sleep(180 * 1000);
            }
            catch (Exception ex)
            {
                telemetry.TrackException(ex);
            }
        }
 internal CommentRepository(IUnitOfWork uow)
 {
     UnitOfWork          = uow;
     _commentBuilder     = new CommentBuilder();
     _blogUserRepository = new BlogUserRepository(uow);
 }