public SubredditEvent(ulong server, ulong channel, SubredditSubmission submission)
 {
     Server        = server;
     ServerChannel = channel;
     Submission    = submission;
     IsRemoval     = false;
 }
Beispiel #2
0
        private IEnumerable <SubredditSubmission> GetNewestSubmissions(JObject jobj)
        {
            ulong tempNewestTime = 0;
            var   newSubmissions = new List <SubredditSubmission>();

            foreach (var submission in jobj["data"]["children"])
            {
                var submissionTime = ulong.Parse(submission["data"]["created_utc"].ToString());

                // if the submission is newer than the newest one we saw last poll
                if (submissionTime > _newestSubmissionTime)
                {
                    Locator.Instance.Fetch <ILogger>().LogLine("Found a new post in /r/" + _subConfig.TargetSubreddit);

                    //Add it to the cache first
                    var cacheitem = new SubredditSubmission();
                    cacheitem.Id        = submission["data"]["id"].ToString();
                    cacheitem.PermaLink = submission["data"]["permalink"].ToString();
                    SubredditPostCache.Add(cacheitem);

                    // Then create the message
                    var builder = new StringBuilder();
                    builder.AppendLine(submission["data"]["title"].ToString() + ": " + submission["data"]["url"]);
                    builder.Append("Comments: " + Constants.RedditURL + submission["data"]["permalink"]);
                    cacheitem.Message = builder.ToString();

                    // Add it to the results output
                    newSubmissions.Add(cacheitem);
                }

                // if the current submission is newer, update the temp time
                if (tempNewestTime < submissionTime)
                {
                    tempNewestTime = submissionTime;
                }
            }

            _newestSubmissionTime = tempNewestTime;

            return(newSubmissions);
        }
 public SubredditEvent(ulong server, ulong channel, SubredditSubmission submission, bool isRemoval) : this(server, channel, submission)
 {
     IsRemoval = isRemoval;
 }