/// <inheritdoc />
 public Task <bool> AnyDesignatedChannelAsync(ulong guildId, DesignatedChannelType type)
 => DesignatedChannelMappingRepository.AnyAsync(new DesignatedChannelMappingSearchCriteria()
 {
     GuildId   = guildId,
     Type      = type,
     IsDeleted = false
 });
        public async Task AddAsync(
            [Summary("The designation to assign")]
            DesignatedChannelType designation)
        {
            await DesignatedChannelService.AddDesignatedChannelAsync(Context.Guild, Context.Channel, designation);

            await Context.AddConfirmation();
        }
        public async Task RemoveAsync(
            [Summary("The designation to be unassigned")]
            DesignatedChannelType designation)
        {
            await DesignatedChannelService.RemoveDesignatedChannelAsync(Context.Guild, Context.Channel, designation);

            await Context.AddConfirmation();
        }
        public async Task AddAsync(
            [Summary("The channel to be assigned a designation")]
            IMessageChannel channel,
            [Summary("The designation to assign")]
            DesignatedChannelType designation)
        {
            await DesignatedChannelService.AddDesignatedChannelAsync(Context.Guild, channel, designation);

            await Context.AddConfirmation();
        }
 /// <inheritdoc />
 public Task <bool> ChannelHasDesignationAsync(
     ulong guildId,
     ulong channelId,
     DesignatedChannelType designation,
     CancellationToken cancellationToken)
 => DesignatedChannelMappingRepository.AnyAsync(new DesignatedChannelMappingSearchCriteria()
 {
     GuildId   = guildId,
     Type      = designation,
     ChannelId = channelId,
     IsDeleted = false
 }, cancellationToken);
示例#6
0
 public Task Remove(
     [Summary("The designation to be unassigned")]
     DesignatedChannelType designation)
 => DesignatedChannelService.RemoveDesignatedChannelAsync(Context.Guild, Context.Channel, designation);
示例#7
0
 public Task Remove(
     [Summary("The channel whose designation is to be unassigned")]
     IMessageChannel channel,
     [Summary("The designation to be unassigned")]
     DesignatedChannelType designation)
 => DesignatedChannelService.RemoveDesignatedChannelAsync(Context.Guild, channel, designation);
示例#8
0
 public Task Add(
     [Summary("The designation to assign")]
     DesignatedChannelType designation)
 => DesignatedChannelService.AddDesignatedChannelAsync(Context.Guild, Context.Channel, designation);
示例#9
0
 public Task Add(
     [Summary("The channel to be assigned a designation")]
     IMessageChannel channel,
     [Summary("The designation to assign")]
     DesignatedChannelType designation)
 => DesignatedChannelService.AddDesignatedChannelAsync(Context.Guild, channel, designation);
示例#10
0
        /// <inheritdoc />
        public async Task <bool> ChannelHasDesignationAsync(IGuild guild, IChannel channel, DesignatedChannelType designation)
        {
            var foundChannels = await DesignatedChannelMappingRepository.SearchBriefsAsync(new DesignatedChannelMappingSearchCriteria()
            {
                GuildId   = guild.Id,
                Type      = designation,
                ChannelId = channel.Id,
                IsDeleted = false
            });

            return(foundChannels.Any());
        }
示例#11
0
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <IMessage> > SendToDesignatedChannelsAsync(IGuild guild, DesignatedChannelType designation, string text, Embed embed = null)
        {
            var channels = await GetDesignatedChannelsAsync(guild, designation);

            if (!channels.Any())
            {
                Log.Warning("Warning: Tried to send to channels assigned to designation {designation}, but none were assigned.", new { designation });
            }

            return(await Task.WhenAll(channels.Select(channel => channel.SendMessageAsync(text, false, embed))));
        }
示例#12
0
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <IMessageChannel> > GetDesignatedChannelsAsync(IGuild guild, DesignatedChannelType type)
        {
            var channelIds = await GetDesignatedChannelIdsAsync(guild.Id, type);

            if (!channelIds.Any())
            {
                throw new InvalidOperationException($"{guild.Name} has no channels assigned to {type}");
            }

            return((await Task.WhenAll(channelIds.Select(d => guild.GetChannelAsync(d))))
                   .OfType <IMessageChannel>()
                   .ToArray());
        }
示例#13
0
 /// <inheritdoc />
 public Task <IReadOnlyCollection <ulong> > GetDesignatedChannelIdsAsync(ulong guildId, DesignatedChannelType type)
 => DesignatedChannelMappingRepository.SearchChannelIdsAsync(new DesignatedChannelMappingSearchCriteria()
 {
     GuildId   = guildId,
     Type      = type,
     IsDeleted = false
 });
示例#14
0
        /// <inheritdoc />
        public async Task <int> RemoveDesignatedChannelAsync(IGuild guild, IMessageChannel logChannel, DesignatedChannelType type)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedChannelMappingDelete);

            using (var transaction = await DesignatedChannelMappingRepository.BeginDeleteTransactionAsync())
            {
                var deletedCount = await DesignatedChannelMappingRepository.DeleteAsync(new DesignatedChannelMappingSearchCriteria()
                {
                    GuildId   = guild.Id,
                    ChannelId = logChannel.Id,
                    IsDeleted = false,
                    Type      = type
                }, AuthorizationService.CurrentUserId.Value);

                if (deletedCount == 0)
                {
                    throw new InvalidOperationException($"{logChannel.Name} in {guild.Name} is not assigned to {type}");
                }

                transaction.Commit();
                return(deletedCount);
            }
        }
示例#15
0
        /// <inheritdoc />
        public async Task AddDesignatedChannelAsync(IGuild guild, IMessageChannel logChannel, DesignatedChannelType type)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedChannelMappingCreate);

            using (var transaction = await DesignatedChannelMappingRepository.BeginCreateTransactionAsync())
            {
                if (await DesignatedChannelMappingRepository.AnyAsync(new DesignatedChannelMappingSearchCriteria()
                {
                    GuildId = guild.Id,
                    ChannelId = logChannel.Id,
                    IsDeleted = false,
                    Type = type
                }))
                {
                    throw new InvalidOperationException($"{logChannel.Name} in {guild.Name} is already assigned to {type}");
                }

                await DesignatedChannelMappingRepository.CreateAsync(new DesignatedChannelMappingCreationData()
                {
                    GuildId     = guild.Id,
                    ChannelId   = logChannel.Id,
                    CreatedById = AuthorizationService.CurrentUserId.Value,
                    Type        = type
                });

                transaction.Commit();
            }
        }