/// <summary> /// Attempts to update an existing announcement /// </summary> /// <param name="discordService">The discord service</param> /// <param name="announcement">The target announcement</param> private static async Task UpdateAnnouncementAsync(DiscordService discordService, Announcement announcement, List <Entrant> entrants) { Logger.Info($"({announcement.Race.SrlId}) Updating announcement {announcement.Snowflake} in channel {announcement.ChannelId}: {announcement.Channel.Guild.DisplayName}/{announcement.Channel.DisplayName}."); RestUserMessage?message = await discordService.FindMessageAsync(announcement.Channel, announcement.Snowflake).ConfigureAwait(false); if (message != null) { try { await discordService.ModifyMessageAsync(message, EmbedFactory.Build(announcement.Race, entrants)).ConfigureAwait(false); announcement.MessageUpdatedAt = DateTime.UtcNow; } catch (Exception ex) { Logger.Error($"({announcement.Race.SrlId}) Exception thrown", ex); } } else { Logger.Info($"({announcement.Race.SrlId}) Failed to fetch message {announcement.Snowflake} in channel {announcement.ChannelId}: {announcement.Channel.Guild.DisplayName}/{announcement.Channel.DisplayName}."); } }
/// <summary> /// Attempts to post a new announcement /// </summary> /// <param name="discordService">The discord service</param> /// <param name="tracker">The tracker</param> /// <param name="race">The race</param> /// <returns>On Success, returns the announcement</returns> private static async Task <Announcement?> PostAnnouncementAsync(DiscordService discordService, Tracker tracker, Race race, List <Entrant> entrants) { Logger.Info($"({race.SrlId}) Posting announcement in channel {tracker.ChannelId}: {tracker.Channel.Guild.DisplayName}/{tracker.Channel.DisplayName}."); try { RestUserMessage?message = await discordService .SendEmbedAsync(tracker.Channel.Snowflake, EmbedFactory.Build(race, entrants)).ConfigureAwait(false); if (message != null) { return(new Announcement(tracker.Channel, tracker, race, message.Id) { MessageCreatedAt = DateTime.UtcNow }); } } catch (Exception ex) { Logger.Error($"({race.SrlId}) Exception thrown", ex); } return(null); }