Skip to content

Commit

Permalink
Update GuildEventScheduleService.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Twinki14 committed Nov 15, 2023
1 parent f556a9f commit 0dd2668
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down

0 comments on commit 0dd2668

Please sign in to comment.