From 219fb9fe7d5e807ec9286d1b9456ece5674ea9a3 Mon Sep 17 00:00:00 2001 From: Twinki Date: Fri, 17 Nov 2023 23:53:46 -0500 Subject: [PATCH] Update GuildEventScheduleService.cs --- .../Hosted/GuildEventScheduleService.cs | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs b/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs index 54fe815..0415603 100644 --- a/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs +++ b/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs @@ -178,36 +178,44 @@ private async Task PostWeeklyScheduleAsync() postedHeader = true; } + _logger.LogInformation("{DateTime}", day.ToLocalDate().AtStartOfDayInZone(_easternStandardZonedClock.GetTzdbTimeZone()).ToInstant().ToUnixTimeSeconds()); description.AppendLine("### " + day.ToString("dddd") + " - " + day.ToLocalDate().AtStartOfDayInZone(_easternStandardZonedClock.GetTzdbTimeZone()).ToInstant().ToDiscordTimestamp(TimestampTagStyles.ShortDate)); - - foreach (var guildEvent in events.OrderBy(e => e.StartTime)) - { - var location = guildEvent.Location ?? "Unknown"; - var url = $"https://discord.com/events/{guildEvent.Guild.Id}/{guildEvent.Id}"; - - if (location is "Unknown" && guildEvent.ChannelId is not null) - { - location = "Discord"; - } - - description.AppendLine($"- [{location} - {guildEvent.Name}]({url})"); - - description.Append($" - {guildEvent.StartTime.ToDiscordTimestamp(TimestampTagStyles.ShortTime)}"); - if (guildEvent.Status is GuildScheduledEventStatus.Active) - { - description.AppendLine(" - Happening now!"); - } - else - { - description.AppendLine($" - {guildEvent.StartTime.ToDiscordTimestamp(TimestampTagStyles.Relative)}"); - } - if (guildEvent.Creator is not null) + if (!events.Any()) + { + description.AppendLine("*No events scheduled*"); + } + else + { + foreach (var guildEvent in events.OrderBy(e => e.StartTime)) { - description.AppendLine($" - Hosted by {guildEvent.Creator.Mention}"); + var location = guildEvent.Location ?? "Unknown"; + var url = $"https://discord.com/events/{guildEvent.Guild.Id}/{guildEvent.Id}"; + + if (location is "Unknown" && guildEvent.ChannelId is not null) + { + location = "Discord"; + } + + description.AppendLine($"- [{location} - {guildEvent.Name}]({url})"); + + description.Append($" - {guildEvent.StartTime.ToDiscordTimestamp(TimestampTagStyles.ShortTime)}"); + if (guildEvent.Status is GuildScheduledEventStatus.Active) + { + description.AppendLine(" - Happening now!"); + } + else + { + description.AppendLine($" - {guildEvent.StartTime.ToDiscordTimestamp(TimestampTagStyles.Relative)}"); + } + + if (guildEvent.Creator is not null) + { + description.AppendLine($" - Hosted by {guildEvent.Creator.Mention}"); + } } } - + embed.WithFooter(day.ToString("dddd")); if (!postedFooter && day == eventsByDay.Last().Key)