Пример #1
0
        private async Task Go()
        {
            Config = Cfg.Config;

            bool d1 = bool.Parse(Config["Delete"]);
            bool o1 = bool.Parse(Config["Overwrite"]);

            if (d1 && !o1)
            {
                Console.WriteLine("Fix your configuration file.  If you delete without also overwriting, then the original comment will remain in the reddit database even though the comment is deleted, according to Reddit admins.");
                return;
            }
            rand = new Random(BitConverter.ToInt32(new Guid().ToByteArray().Take(4).ToArray()));
            AuthenticatedFixture authFixture = new AuthenticatedFixture();
            Reddit reddit = new Reddit(authFixture.WebAgent, true);

            IEnumerable <string> srs = Config.GetSection("Places:SubReddits").GetChildren().ToList().Select(x => x.Value);

            foreach (string srn in srs)
            {
                Subreddit sr = await reddit.GetSubredditAsync(srn, true);

                //by comment
                Console.WriteLine($"comments from {srn} follow");
                List <InterestingComment> interstingComments = new List <InterestingComment>();
                int junk = 0;
                IAsyncEnumerator <Comment> comments = sr.GetComments().GetEnumerator(50, -1, false);
                while (await comments.MoveNext(CancellationToken.None))
                {
                    Comment comment = comments.Current;

                    if (comment.Vote == VotableThing.VoteType.Upvote && bool.Parse(Config["UnUpVote"]))
                    {
                        try
                        {
                            await comment.ClearVote();

                            InterestingLog("un-up-vote +1 => 0  |  " + comment.AsString());
                        }
                        catch (Exception ex)
                        {
                            //can't check for archived without walking up the heirarchy...
                            //InterestingLog($"failed to un-up-vote because {ex.Message}  |  {comment.AsString()}");
                        }
                    }
                    else if (comment.Vote == VotableThing.VoteType.Downvote && bool.Parse(Config["UnDownVote"]))
                    {
                        try
                        {
                            await comment.ClearVote();

                            InterestingLog("un-down-vote -1 => 0  |  " + comment.AsString());
                        }
                        catch (Exception ex)
                        {
                            //can't check for archived without walking up the heirarchy...
                            //InterestingLog($"failed to un-down-vote because {ex.Message}  |  {comment.AsString()}");
                        }
                    }

                    if (IsInteresting(comment))
                    {
                        if (UserIsAuthor(comment))
                        {
                            try
                            {
                                InterestingComment inter = new InterestingComment()
                                {
                                    Comment = comment
                                };
                                InterestingLog(inter);
                                interstingComments.Add(inter);
                                if (bool.Parse(Config["Overwrite"]))
                                {
                                    await comment.EditTextAsync(Dust());

                                    await Task.Delay(1000); // just in case...

                                    inter.Overwritten = true;
                                    InterestingLog(inter);
                                }
                                if (bool.Parse(Config["Delete"]))
                                {
                                    await comment.DelAsync();

                                    inter.Deleted = true;
                                    await Task.Delay(1000); // just in case...

                                    InterestingLog(inter);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debugger.Break();
                            }
                        }
                        else
                        {
                            InterestingLog(new InterestingComment()
                            {
                                Comment = comment
                            });
                        }
                    }
                    else
                    {
                        JunkLog(new JunkComment()
                        {
                            Comment = comment
                        });
                        junk++;
                    }
                }

                Console.WriteLine($"done with {srn} comments, interesting: {interstingComments.Count}, junk: {junk}");
                if (interstingComments.Count > 0)
                {
                    Console.WriteLine();
                    Console.WriteLine($"Interesting comments from {srn} follow:");
                    foreach (InterestingComment inter in interstingComments)
                    {
                        Console.WriteLine(inter);
                    }
                    Console.WriteLine();
                }

                //by post
                Console.WriteLine($"posts from {srn} follow");
                List <InterestingPost> interstingPosts = new List <InterestingPost>();
                junk = 0;

                IAsyncEnumerator <Post> posts = sr.GetPosts().GetEnumerator(50, -1, false);
                while (await posts.MoveNext(CancellationToken.None))
                {
                    Post post = posts.Current;

                    if (IsInteresting(post))
                    {
                        if (UserIsAuthor(post))
                        {
                            try
                            {
                                InterestingPost inter = new InterestingPost()
                                {
                                    Post = post
                                };
                                InterestingLog(inter);
                                interstingPosts.Add(inter);
                                if (bool.Parse(Config["Overwrite"]))
                                {
                                    await post.EditTextAsync(Dust());

                                    await Task.Delay(1000); // just in case...

                                    inter.Overwritten = true;
                                    InterestingLog(inter);
                                }
                                if (bool.Parse(Config["Delete"]))
                                {
                                    await post.DelAsync();

                                    inter.Deleted = true;
                                    await Task.Delay(1000); // just in case...

                                    InterestingLog(inter);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debugger.Break();
                            }
                        }
                        else
                        {
                            InterestingLog(new InterestingPost()
                            {
                                Post = post
                            });
                        }
                    }
                    else
                    {
                        JunkLog(new JunkPost()
                        {
                            Post = post
                        });
                        junk++;
                    }
                }

                Console.WriteLine($"done with {srn} posts, interesting: {interstingPosts.Count}, junk: {junk}");
                if (interstingPosts.Count > 0)
                {
                    Console.WriteLine();
                    Console.WriteLine($"Interesting posts from {srn} follow:");
                    foreach (InterestingPost inter in interstingPosts)
                    {
                        Console.WriteLine(inter);
                    }
                    Console.WriteLine();
                }
            }
            if (bool.Parse(Config["UnDownVote"]) || bool.Parse(Config["UnUpVote"]))
            {
                RedditUser user = await RedditUser.GetUserAsync(authFixture.WebAgent, authFixture.UserName);

                if (bool.Parse(Config["UnDownVote"]))
                {
                    IAsyncEnumerator <Post> enumDisliked = user.GetDislikedPosts().GetEnumerator();
                    while (await enumDisliked.MoveNext(CancellationToken.None))
                    {
                        Post disliked = enumDisliked.Current;
                        if (!disliked.IsArchived)
                        {
                            try
                            {
                                await disliked.SetVoteAsync(VotableThing.VoteType.None);

                                InterestingLog("un-down-vote -1 => 0  |  " + disliked.AsString());
                            }
                            catch (Exception ex)
                            {
                                InterestingLog($"failed to un-down-vote because {ex.Message}  |  {disliked.AsString()}");
                            }
                        }
                    }
                }
                if (bool.Parse(Config["UnUpVote"]))
                {
                    IAsyncEnumerator <Post> enumLiked = user.GetLikedPosts().GetEnumerator();
                    while (await enumLiked.MoveNext(CancellationToken.None))
                    {
                        Post liked = enumLiked.Current;
                        if (!liked.IsArchived)
                        {
                            try
                            {
                                await liked.SetVoteAsync(VotableThing.VoteType.None);
                            }
                            catch (Exception ex)
                            {
                                InterestingLog($"failed to un-up-vote because {ex.Message}  |  {liked.AsString()}");
                            }
                            InterestingLog("un-up-vote +1 => 0  |  " + liked.AsString());
                        }
                    }
                }
            }
        }
Пример #2
0
 public override string ToString()
 {
     return($"Overwritten: {Overwritten}, Deleted: {Deleted}, {Comment.AsString()}");
 }