Skip to content

Commit

Permalink
Added a (hopefully) temporary workaround for duplicate comments #70
Browse files Browse the repository at this point in the history
  • Loading branch information
derekantrican committed Jan 19, 2022
1 parent 1237bc9 commit ef9c50d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions MountainProjectBot/BotFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ public static class BotFunctions
public static ConcurrentDictionary<string, ApprovalRequest> PostsPendingApproval { get; set; } = new ConcurrentDictionary<string, ApprovalRequest>();
public static bool DryRun { get; set; }

public static ConcurrentBag<string> ParentsWithDuplicates { get; set; } = new ConcurrentBag<string>(); //TEMP (see below workaround block)
public static async Task CheckMonitoredComments()
{
monitoredComments.RemoveAll(c => c.Age.TotalHours > c.ExpirationHours); //Remove any old monitors


//-------- TEMPORARY WORKAROUND (https://github.com/derekantrican/MountainProject/issues/70)
List<Comment> recentBotComments = await RedditHelper.GetOwnComments();
foreach (IGrouping<string, Comment> duplicateComments in recentBotComments.GroupBy(c => c.ParentId).Where(g => g.Count() > 1 && !ParentsWithDuplicates.Contains(g.Key)))
{
VotableThing parent = await RedditHelper.GetThing(duplicateComments.Key) as VotableThing;
BotUtilities.SendDiscordMessage($"There seem to be multiple replies ({duplicateComments.Count()}) to this parent: {RedditHelper.GetFullLink(parent.Permalink)}");
ParentsWithDuplicates.Add(duplicateComments.Key);
//Todo: if this is found to be decently reliable, we should delete the duplicates automatically
}
//--------


for (int i = monitoredComments.Count - 1; i >= 0; i--)
{
CommentMonitor monitor = monitoredComments[i];
Expand Down
11 changes: 11 additions & 0 deletions MountainProjectBot/RedditHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ public async Task<Dictionary<Subreddit, List<Comment>>> GetRecentComments()
return subredditsAndRecentComments;
}

public async Task<List<Comment>> GetOwnComments()
{
RedditUser botUser = await redditService.GetUserAsync("MountainProjectBot");
return await botUser.GetComments(100).ToListAsync();
}

public async Task<Thing> GetThing(string id)
{
return await redditService.GetThingByFullnameAsync(id);
}

public async Task<Comment> GetComment(Uri commentPermalink)
{
return await redditService.GetCommentAsync(new Uri(REDDITBASEURL + commentPermalink));
Expand Down

0 comments on commit ef9c50d

Please sign in to comment.