Commit bd3f84e8 authored by Robert Rudman's avatar Robert Rudman

Don't automatically clean up burns

parent ed9b333e
......@@ -54,7 +54,9 @@ namespace Rodgort.Services
public class BurnFinished
{
public string Tag { get; set; }
public int MetaQuestionId { get; set; }
public string MetaQuestionName { get; set; }
public List<string> Tags { get; set; }
}
public class BurnStarted
......@@ -63,11 +65,6 @@ namespace Rodgort.Services
public List<string> Tags { get; set; }
}
public class BurnDeclined
{
public string Tag { get; set; }
}
public void CrawlMetaSync()
{
CrawlMeta().Wait();
......@@ -92,7 +89,7 @@ namespace Rodgort.Services
var newFeatures = new List<NewFeature>();
var finishedBurns = new List<BurnFinished>();
var burnsStarted = new List<BurnStarted>();
var burnsDeclined = new List<BurnDeclined>();
var burnsDeclined = new List<BurnFinished>();
_logger.LogInformation("Starting meta crawl");
......@@ -127,10 +124,10 @@ namespace Rodgort.Services
await PostProcessQuestions(questions, processQuestionsResult.FinishedBurns, processQuestionsResult.NewFeatures, processQuestionsResult.BurnsStarted, processQuestionsResult.BurnsDeclined);
}
public async Task PostProcessQuestions(List<BaseQuestion> questions, IEnumerable<BurnFinished> finishedBurns, IReadOnlyCollection<NewFeature> newFeatures, IReadOnlyCollection<BurnStarted> burnsStarted, IReadOnlyCollection<BurnDeclined> burnsDeclined)
public async Task PostProcessQuestions(List<BaseQuestion> questions, IEnumerable<BurnFinished> finishedBurns, IReadOnlyCollection<NewFeature> newFeatures, IReadOnlyCollection<BurnStarted> burnsStarted, IReadOnlyCollection<BurnFinished> burnsDeclined)
{
foreach (var tag in finishedBurns.Select(b => b.Tag).Distinct())
await _newBurninationService.StopBurn(tag);
foreach (var finishedBurn in finishedBurns)
await _newBurninationService.AnnounceBurnEnded(finishedBurn.MetaQuestionName, finishedBurn.MetaQuestionId, finishedBurn.Tags.Distinct());
foreach (var newFeature in newFeatures.GroupBy(g => g.MetaUrl).Select(g => g.First()))
await _newBurninationService.NewTagsFeatured(newFeature.MetaQuestionId, newFeature.MetaUrl, newFeature.Tags);
......@@ -138,8 +135,8 @@ namespace Rodgort.Services
foreach (var burnStarted in burnsStarted.GroupBy(g => g.MetaUrl).Select(g => g.First()))
await _newBurninationService.NewBurnStarted(burnStarted.MetaUrl, burnStarted.Tags);
foreach (var tag in burnsDeclined.Select(b => b.Tag).Distinct())
await _newBurninationService.BurnDeclined(tag);
foreach (var declinedBurn in burnsDeclined)
await _newBurninationService.AnnounceBurnDeclined(declinedBurn.MetaQuestionName, declinedBurn.MetaQuestionId, declinedBurn.Tags.Distinct());
_logger.LogTrace("Meta crawl completed");
......@@ -154,7 +151,7 @@ namespace Rodgort.Services
public List<NewFeature> NewFeatures { get; set; }
public List<BurnFinished> FinishedBurns { get; set; }
public List<BurnStarted> BurnsStarted { get; set; }
public List<BurnDeclined> BurnsDeclined { get; set; }
public List<BurnFinished> BurnsDeclined { get; set; }
}
public ProcessQuestionsResult ProcessQuestions(List<BaseQuestion> questions, bool isFullSet)
......@@ -162,7 +159,7 @@ namespace Rodgort.Services
var newFeatures = new List<NewFeature>();
var finishedBurns = new List<BurnFinished>();
var burnsStarted = new List<BurnStarted>();
var burnsDeclined = new List<BurnDeclined>();
var burnsDeclined = new List<BurnFinished>();
var questionIds = questions.Select(q => q.QuestionId).Distinct().ToList();
......@@ -253,8 +250,7 @@ namespace Rodgort.Services
{
if (isBurnRequest && dbMetaQuestion.FeaturedStarted.HasValue)
{
foreach (var trackedTag in trackedTags)
burnsDeclined.Add(new BurnDeclined { Tag = trackedTag.TagName });
burnsDeclined.Add(new BurnFinished { MetaQuestionName = dbMetaQuestion.Title, MetaQuestionId = dbMetaQuestion.Id, Tags = trackedTags.Select(t => t.TagName).ToList() });
}
}
}
......@@ -278,8 +274,7 @@ namespace Rodgort.Services
if (isBurnRequest)
{
dbMetaQuestion.BurnEnded = utcNow;
foreach (var trackedTag in trackedTags)
finishedBurns.Add(new BurnFinished {Tag = trackedTag.TagName});
finishedBurns.Add(new BurnFinished { MetaQuestionName = dbMetaQuestion.Title, MetaQuestionId = dbMetaQuestion.Id, Tags = trackedTags.Select(t => t.TagName).ToList() });
}
}
}
......
......@@ -74,56 +74,20 @@ namespace Rodgort.Services
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"The burn of {metaPostUrl} started, but there are multiple observation rooms: {string.Join(", ", roomIds)}");
}
public async Task StopBurn(string tag)
public async Task AnnounceBurnEnded(string metaQuestionName, int metaQuestionId, IEnumerable<string> tags)
{
if (!_enabled)
return;
var follows = _rodgortContext.BurnakiFollows.Where(bf =>
bf.BurnakiId == ChatUserIds.GEMMY
&& bf.Tag == tag
&& !bf.FollowEnded.HasValue
).ToList();
if (!follows.Any())
return;
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, $"@Gemmy stop tag {tag}");
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"The burnination of [tag:{tag}] has finished!");
foreach (var follow in follows)
{
await _chatClient.SendMessage(ChatSite.StackOverflow, follow.RoomId, "@Gemmy stop");
follow.FollowEnded = _dateService.UtcNow;
}
_rodgortContext.SaveChanges();
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"The burnination of [{metaQuestionName}](https://meta.stackoverflow.com/q/{metaQuestionId}) {string.Join(", ", tags.Select(t => $"[tag:{t}]"))} has finished!");
}
public async Task BurnDeclined(string tag)
public async Task AnnounceBurnDeclined(string metaQuestionName, int metaQuestionId, IEnumerable<string> tags)
{
if (!_enabled)
return;
var follows = _rodgortContext.BurnakiFollows.Where(bf =>
bf.BurnakiId == ChatUserIds.GEMMY
&& bf.Tag == tag
&& !bf.FollowEnded.HasValue
).ToList();
if (!follows.Any())
return;
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, $"@Gemmy stop tag {tag}");
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"The request for the burnination of [tag:{tag}] has been declined");
foreach (var follow in follows)
{
await _chatClient.SendMessage(ChatSite.StackOverflow, follow.RoomId, "@Gemmy stop");
follow.FollowEnded = _dateService.UtcNow;
}
_rodgortContext.SaveChanges();
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"The request for the burnination [{metaQuestionName}](https://meta.stackoverflow.com/q/{metaQuestionId}) {string.Join(", ", tags.Select(t => $"[tag:{t}]"))} has been declined");
}
public async Task NewBurnStarted(string metaPostUrl, List<string> tags)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment