diff --git a/MountainProjectBot/BotFunctions.cs b/MountainProjectBot/BotFunctions.cs index a3ceeee..6b18271 100644 --- a/MountainProjectBot/BotFunctions.cs +++ b/MountainProjectBot/BotFunctions.cs @@ -23,10 +23,24 @@ public static class BotFunctions public static ConcurrentDictionary PostsPendingApproval { get; set; } = new ConcurrentDictionary(); public static bool DryRun { get; set; } + public static ConcurrentBag ParentsWithDuplicates { get; set; } = new ConcurrentBag(); //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 recentBotComments = await RedditHelper.GetOwnComments(); + foreach (IGrouping 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]; diff --git a/MountainProjectBot/RedditHelper.cs b/MountainProjectBot/RedditHelper.cs index 4de1027..bdaf7a2 100644 --- a/MountainProjectBot/RedditHelper.cs +++ b/MountainProjectBot/RedditHelper.cs @@ -87,6 +87,17 @@ public async Task>> GetRecentComments() return subredditsAndRecentComments; } + public async Task> GetOwnComments() + { + RedditUser botUser = await redditService.GetUserAsync("MountainProjectBot"); + return await botUser.GetComments(100).ToListAsync(); + } + + public async Task GetThing(string id) + { + return await redditService.GetThingByFullnameAsync(id); + } + public async Task GetComment(Uri commentPermalink) { return await redditService.GetCommentAsync(new Uri(REDDITBASEURL + commentPermalink));