private async Task CreateMessagesInChannel(DiscordChannelId channelID, ExpectedChannelMessages messages) { if (!_channelSemaphores.TryGetValue(channelID, out var semaphore)) { semaphore = new SemaphoreSlim(1, 1); _channelSemaphores.Add(channelID, semaphore); } var channelLocationAndName = DiscordAccess.GetChannelLocationAndName(channelID); try { _logger.LogInformation("{Channel} - Waiting for channel-edit-semaphore ...", channelLocationAndName); await semaphore.WaitAsync(); _logger.LogInformation("{Channel} - Got channel-edit-semaphore.", channelLocationAndName); _logger.LogInformation("{Channel} - Deleting existing bot messages in the channel ...", channelLocationAndName); await DiscordAccess.DeleteBotMessagesInChannel(channelID); _logger.LogInformation("{Channel} - Creating new messages in the channel ...", channelLocationAndName); await DiscordAccess.CreateBotMessagesInChannelAsync(channelID, messages.ToArray()); } catch (Exception e) { _logger.LogError(e, "{Channel} - Failed to create all messages for channel.", channelLocationAndName); } finally { _logger.LogInformation("{Channel} - Releasing channel-edit-semaphore ...", channelLocationAndName); semaphore.Release(); _logger.LogInformation("{Channel} - Channel-edit-semaphore released.", channelLocationAndName); } }
public bool Equals(DiscordChannelId other) { return(Id == other.Id); }
public ChannelNotFoundException(DiscordChannelId channelId) : base($"Couldn't find channel with the ID '{channelId}'.") { }