/// <inheritdoc /> public async Task <IReadOnlyCollection <ulong> > GetLogChannelIdsAsync(ulong guildId) => (await ModerationLogChannelMappingRepository.SearchBriefsAsync(new ModerationLogChannelMappingSearchCriteria() { GuildId = guildId, IsDeleted = false })) .Select(x => x.LogChannelId) .ToArray();
/// <inheritdoc /> public async Task <IReadOnlyCollection <IMessageChannel> > GetLogChannelsAsync(IGuild guild) { var mappings = await ModerationLogChannelMappingRepository.SearchBriefsAsync(new ModerationLogChannelMappingSearchCriteria() { GuildId = guild.Id, IsDeleted = false }); return((await guild.GetChannelsAsync()) .Where(x => mappings.Any(y => y.LogChannelId == x.Id)) .Cast <IMessageChannel>() .ToArray()); }
/// <inheritdoc /> public async Task RemoveLogChannelAsync(IGuild guild, IMessageChannel logChannel) { using (var transaction = await ModerationLogChannelMappingRepository.BeginDeleteTransactionAsync()) { var deletedCount = await ModerationLogChannelMappingRepository.DeleteAsync(new ModerationLogChannelMappingSearchCriteria() { GuildId = guild.Id, LogChannelId = logChannel.Id, IsDeleted = false }, AuthorizationService.CurrentUserId.Value); if (deletedCount == 0) { throw new InvalidOperationException($"{logChannel.Name} is not currently receiving moderation log messages for {guild.Name}"); } transaction.Commit(); } }
/// <inheritdoc /> public async Task AddLogChannelAsync(IGuild guild, IMessageChannel logChannel) { using (var transaction = await ModerationLogChannelMappingRepository.BeginCreateTransactionAsync()) { if (await ModerationLogChannelMappingRepository.AnyAsync(new ModerationLogChannelMappingSearchCriteria() { GuildId = guild.Id, LogChannelId = logChannel.Id, IsDeleted = false })) { throw new InvalidOperationException($"{logChannel.Name} already receives moderation log messages for {guild.Name}"); } await ModerationLogChannelMappingRepository.CreateAsync(new ModerationLogChannelMappingCreationData() { GuildId = guild.Id, LogChannelId = logChannel.Id, CreatedById = AuthorizationService.CurrentUserId.Value }); transaction.Commit(); } }