From 0dd26689001cedd7af94f7a0d7cb0e555e199af4 Mon Sep 17 00:00:00 2001 From: Twinki Date: Wed, 15 Nov 2023 15:33:47 -0500 Subject: [PATCH] Update GuildEventScheduleService.cs --- .../Hosted/GuildEventScheduleService.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs b/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs index 1d2ae4c..5d2463b 100644 --- a/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs +++ b/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs @@ -92,8 +92,6 @@ private async Task PostWeeklyScheduleAsync() _logger.LogDebug("Guild doesn't have a configured weekly schedule channel"); return; } - - _logger.LogInformation("Trying to post weekly schedule"); var eventsThisWeekResult = await _scheduledEventService.GetScheduledWeeklyEventsAsync(guild.Id, _easternStandardZonedClock.GetCurrentDate()); var eventsThisWeek = eventsThisWeekResult.Value; @@ -130,6 +128,19 @@ private async Task PostWeeklyScheduleAsync() eventsByDay[day].Add(guildScheduledEvent); } + _logger.LogInformation("Wiping weekly schedule messages"); + + var messages = await weeklyScheduleChannel + .GetMessagesAsync(50) + .FlattenAsync(); + + foreach (var message in messages.Where(m => m.Author.Id == _client.CurrentUser.Id)) + { + await message.DeleteAsync(); + } + + _logger.LogInformation("Posting weekly schedule"); + var postedHeader = false; var postedFooter = false; @@ -140,8 +151,10 @@ private async Task PostWeeklyScheduleAsync() if (!postedHeader && day == eventsByDay.First().Key) { - embed.WithAuthor(string.Empty, _client.CurrentUser.GetAvatarUrl()); - description.AppendLine("# Weekly event schedule"); + embed + .WithThumbnailUrl(_client.CurrentUser.GetAvatarUrl()) + .WithAuthor(author => author.WithIconUrl(_client.CurrentUser.GetAvatarUrl())); + description.AppendLine("## Weekly event schedule"); postedHeader = true; }