示例#1
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <ulong> > GetLogChannelIdsAsync(ulong guildId)
 => (await ModerationLogChannelMappingRepository.SearchBriefsAsync(new ModerationLogChannelMappingSearchCriteria()
 {
     GuildId = guildId,
     IsDeleted = false
 }))
 .Select(x => x.LogChannelId)
 .ToArray();
示例#2
0
        /// <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());
        }
示例#3
0
        /// <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();
            }
        }
示例#4
0
        /// <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();
            }
        }