/// <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);
public Task Remove( [Summary("The designation to be unassigned")] DesignatedChannelType designation) => DesignatedChannelService.RemoveDesignatedChannelAsync(Context.Guild, Context.Channel, designation);
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);
public Task Add( [Summary("The designation to assign")] DesignatedChannelType designation) => DesignatedChannelService.AddDesignatedChannelAsync(Context.Guild, Context.Channel, designation);
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);
/// <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()); }
/// <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)))); }
/// <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()); }
/// <inheritdoc /> public Task <IReadOnlyCollection <ulong> > GetDesignatedChannelIdsAsync(ulong guildId, DesignatedChannelType type) => DesignatedChannelMappingRepository.SearchChannelIdsAsync(new DesignatedChannelMappingSearchCriteria() { GuildId = guildId, Type = type, IsDeleted = false });
/// <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); } }
/// <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(); } }