Commit 12b5fee0 authored by Robert Rudman's avatar Robert Rudman

Handle the start of burns. Pin link to rodgort progress in observation room

parent 1d28b627
......@@ -46,6 +46,7 @@ namespace Rodgort.Services
private class NewFeature
{
public int MetaQuestionId { get; set; }
public string MetaUrl { get; set; }
public List<string> Tags { get; set; }
}
......@@ -55,6 +56,12 @@ namespace Rodgort.Services
public string Tag { get; set; }
}
private class BurnStarted
{
public string MetaUrl { get; set; }
public List<string> Tags { get; set; }
}
public void CrawlMetaSync()
{
CrawlMeta().Wait();
......@@ -78,6 +85,7 @@ namespace Rodgort.Services
{
var newFeatures = new List<NewFeature>();
var finishedBurns = new List<BurnFinished>();
var burnsStarted = new List<BurnStarted>();
_logger.LogInformation("Starting meta crawl");
......@@ -145,10 +153,14 @@ namespace Rodgort.Services
if (tag == DbMetaTag.STATUS_FEATURED)
{
dbMetaQuestion.FeaturedStarted = utcNow;
newFeatures.Add(new NewFeature { MetaUrl = metaQuestion.Link, Tags = trackedTags.Select(t => t.TagName).ToList() });
newFeatures.Add(new NewFeature { MetaQuestionId = metaQuestion.QuestionId.Value, MetaUrl = metaQuestion.Link, Tags = trackedTags.Select(t => t.TagName).ToList() });
}
if (tag == DbMetaTag.STATUS_PLANNED)
{
dbMetaQuestion.BurnStarted = utcNow;
burnsStarted.Add(new BurnStarted { MetaUrl = metaQuestion.Link, Tags = trackedTags.Select(t => t.TagName).ToList() });
}
}
}
......@@ -232,20 +244,10 @@ namespace Rodgort.Services
await _newBurninationService.StopBurn(finishedBurn.Tag);
foreach (var newFeature in newFeatures.GroupBy(g => g.MetaUrl).Select(g => g.First()))
{
if (!newFeature.Tags.Any())
{
await _newBurninationService.AnnounceNoTrackedTags(newFeature.MetaUrl);
}
else if (newFeature.Tags.Count > 1)
{
await _newBurninationService.AnnounceMultipleTrackedTags(newFeature.MetaUrl, newFeature.Tags);
}
else
{
await _newBurninationService.CreateRoomForBurn(newFeature.Tags.First(), newFeature.MetaUrl);
}
}
await _newBurninationService.NewTagsFeatured(newFeature.MetaUrl, newFeature.Tags);
foreach (var burnStarted in burnsStarted.GroupBy(g => g.MetaUrl).Select(g => g.First()))
await _newBurninationService.NewBurnStarted(burnStarted.MetaUrl, burnStarted.Tags);
_logger.LogInformation("Meta crawl completed");
RecurringJob.Trigger(BurninationTagGuessingService.SERVICE_NAME);
......
......@@ -31,7 +31,7 @@ namespace Rodgort.Services
_enabled = hasCookies || hasCredentials;
}
public async Task AnnounceMultipleTrackedTags(string metaPostUrl, IEnumerable<string> trackedTags)
private async Task AnnounceFeaturedMultipleTrackedTags(string metaPostUrl, IEnumerable<string> trackedTags)
{
if (!_enabled)
return;
......@@ -39,7 +39,7 @@ namespace Rodgort.Services
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"Discussion for the burnination of {metaPostUrl} started, but there are multiple tracked tags: {string.Join(", ", trackedTags)}");
}
public async Task AnnounceNoTrackedTags(string metaPostUrl)
private async Task AnnounceFeaturedNoTrackedTags(string metaPostUrl)
{
if (!_enabled)
return;
......@@ -47,6 +47,30 @@ namespace Rodgort.Services
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"Discussion for the burnination of {metaPostUrl} started, but there are no tracked tags");
}
private async Task AnnounceBurningMultipleTrackedTags(string metaPostUrl, IEnumerable<string> trackedTags)
{
if (!_enabled)
return;
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"The burn of {metaPostUrl} started, but there are multiple tracked tags: {string.Join(", ", trackedTags)}");
}
private async Task AnnounceBurningNoTrackedTags(string metaPostUrl)
{
if (!_enabled)
return;
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, $"The burn of {metaPostUrl} started, but there are no tracked tags");
}
private async Task AnnounceBurningMultipleRooms(string metaPostUrl, List<int> roomIds)
{
if (!_enabled)
return;
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)
{
if (!_enabled)
......@@ -63,24 +87,96 @@ namespace Rodgort.Services
_rodgortContext.SaveChanges();
}
public async Task CreateRoomForBurn(string tag, string metaPostUrl)
public async Task NewBurnStarted(string metaPostUrl, List<string> tags)
{
if (!_enabled)
return;
var roomName = $"Observation room for [{tag}] burnination";
if (!tags.Any())
{
await AnnounceBurningNoTrackedTags(metaPostUrl);
return;
}
if (tags.Count > 1)
{
await AnnounceBurningMultipleTrackedTags(metaPostUrl, tags);
return;
}
var tag = tags.First();
var observationRooms =
_rodgortContext.BurnakiFollows
.Where(b => b.BurnakiId == 8300708 && !b.FollowEnded.HasValue && b.Tag == tag)
.Select(bf => bf.RoomId)
.Distinct()
.ToList();
if (observationRooms.Count > 1)
{
await AnnounceBurningMultipleRooms(metaPostUrl, observationRooms);
return;
}
var roomId = observationRooms.FirstOrDefault();
if (roomId == 0)
roomId = await CreateBurnRoom(tag);
else
await RenameObservationRoom(roomId);
var burninationMessage = $"The burnination of [tag:{tag}] has STARTED! [Meta post]({metaPostUrl}). [Burnination progress room](https://chat.stackoverflow.com/rooms/{roomId}).";
await _chatClient.SendMessageAndPin(ChatSite.StackOverflow, ChatRooms.TROGDOR, burninationMessage);
}
private async Task RenameObservationRoom(int roomId)
{
await Task.CompletedTask;
}
private async Task<int> CreateBurnRoom(string tag)
{
var roomName = $"Burnination progress for the [{tag}] tag";
var roomId = await _chatClient.CreateRoom(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, roomName, string.Empty);
var gemmyMessage = $"@Gemmy start tag [{tag}] {roomId} https://chat.stackoverflow.com/rooms/{roomId}";
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, gemmyMessage);
return roomId;
}
var burninationMessage = $"The burnination of [tag:{tag}] is now being discussed {metaPostUrl}";
public async Task NewTagsFeatured(int metaQuestionId, string metaPostUrl, List<string> tags)
{
if (!_enabled)
return;
if (!tags.Any())
{
await AnnounceFeaturedNoTrackedTags(metaPostUrl);
return;
}
if (tags.Count > 1)
{
await AnnounceFeaturedMultipleTrackedTags(metaPostUrl, tags);
return;
}
var tag = tags.First();
var roomName = $"Observation room for [{tag}] burnination";
var roomId = await _chatClient.CreateRoom(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, roomName, string.Empty);
await _chatClient.SendMessageAndPin(ChatSite.StackOverflow, roomId, $"[Rodgort tag progress](https://rodgort.sobotics.org/progress?metaQuestionId={metaQuestionId})");
var gemmyMessage = $"@Gemmy start tag [{tag}] {roomId} https://chat.stackoverflow.com/rooms/{roomId}";
await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, gemmyMessage);
var burninationMessageId = await _chatClient.SendMessage(ChatSite.StackOverflow, ChatRooms.TROGDOR, burninationMessage);
await _chatClient.PinMessage(ChatSite.StackOverflow, ChatRooms.SO_BOTICS_WORKSHOP, burninationMessageId);
var burninationMessage = $"The burnination of [tag:{tag}] is now being discussed. [Meta post]({metaPostUrl}). [Observation room](https://chat.stackoverflow.com/rooms/{roomId}).";
await _chatClient.SendMessageAndPin(ChatSite.StackOverflow, ChatRooms.TROGDOR, burninationMessage);
var burnakiFollow = new DbBurnakiFollow
{
BurnakiId = 8300708,
......
......@@ -26,7 +26,7 @@ namespace Rodgort.Services
SyncTrogdorRoomOwners().Wait();
}
public async Task SyncTrogdorRoomOwners()
private async Task SyncTrogdorRoomOwners()
{
var restClient = new RestClient(STACKOVERFLOW_CHAT_URL);
var request = new RestRequest(TROGDOR_ROOM_INFO_PAGE_PATH);
......
......@@ -141,20 +141,20 @@ namespace Rodgort
RecurringJob.AddOrUpdate<MetaCrawlerService>(MetaCrawlerService.SERVICE_NAME, service => service.CrawlMetaSync(), "0 * * * *");
// Every hour
RecurringJob.AddOrUpdate<TagCountService>(TagCountService.ALL_TAGS, service => service.GetQuestionCountForApprovedTags(), "5 * * * *");
RecurringJob.AddOrUpdate<TagCountService>(TagCountService.ALL_TAGS, service => service.GetQuestionCountForApprovedTagsSync(), "5 * * * *");
// Every day
RecurringJob.AddOrUpdate<UserDisplayNameService>(UserDisplayNameService.SYNC_ALL_USERS, service => service.SyncAllUsers(), "10 0 * * *");
RecurringJob.AddOrUpdate<UserDisplayNameService>(UserDisplayNameService.SYNC_ALL_USERS, service => service.SyncAllUsersSync(), "10 0 * * *");
// Every day
RecurringJob.AddOrUpdate<TrogdorRoomOwnerService>(TrogdorRoomOwnerService.SERVICE_NAME, service => service.SyncTrogdorRoomOwners(), "15 0 * * *");
RecurringJob.AddOrUpdate<TrogdorRoomOwnerService>(TrogdorRoomOwnerService.SERVICE_NAME, service => service.SyncTrogdorRoomOwnersSync(), "15 0 * * *");
RecurringJob.AddOrUpdate<BurnCatchupService>(BurnCatchupService.SERVICE_NAME, service => service.Catchup(), "20 0 * * *");
RecurringJob.AddOrUpdate<BurnCatchupService>(BurnCatchupService.SERVICE_NAME, service => service.CatchupSync(), "20 0 * * *");
// I don't really want this to automatically execute, but the 'never' crontab expression doesn't work for hangfire.
// So, we'll just execute once a year - the first of January at 0:10
RecurringJob.AddOrUpdate<BurninationTagGuessingService>(BurninationTagGuessingService.SERVICE_NAME, service => service.GuessTags(), "20 0 1 1 *");
RecurringJob.AddOrUpdate<UserDisplayNameService>(UserDisplayNameService.SYNC_USERS_NO_NAME, service => service.SyncUsersWithNoName(), "25 0 1 1 *");
RecurringJob.AddOrUpdate<UserDisplayNameService>(UserDisplayNameService.SYNC_USERS_NO_NAME, service => service.SyncUsersWithNoNameSync(), "25 0 1 1 *");
}
public class NoAuthorizationFilter : IDashboardAuthorizationFilter
......
......@@ -26,6 +26,13 @@ namespace StackExchangeChat
_httpClient = httpClient;
}
public async Task<int> SendMessageAndPin(ChatSite chatSite, int roomId, string message)
{
var messageId = await SendMessage(chatSite, roomId, message);
await PinMessage(chatSite, roomId, messageId);
return messageId;
}
public async Task<int> SendMessage(ChatSite chatSite, int roomId, string message)
{
var backoffRegex = new Regex(@"You can perform this action again in (\d+) seconds?");
......
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