Exemplo n.º 1
0
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
        public static async Task <RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                            string name, RequestOptions options, Action <VoiceChannelProperties> func = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(paramName: nameof(name));
            }

            var props = new VoiceChannelProperties();

            func?.Invoke(props);

            var args = new CreateGuildChannelParams(name, ChannelType.Voice)
            {
                CategoryId = props.CategoryId,
                Bitrate    = props.Bitrate,
                UserLimit  = props.UserLimit,
                Position   = props.Position,
                Overwrites = props.PermissionOverwrites.IsSpecified
                    ? props.PermissionOverwrites.Value.Select(overwrite => new API.Overwrite
                {
                    TargetId   = overwrite.TargetId,
                    TargetType = overwrite.TargetType,
                    Allow      = overwrite.Permissions.AllowValue.ToString(),
                    Deny       = overwrite.Permissions.DenyValue.ToString()
                }).ToArray()
                    : Optional.Create <API.Overwrite[]>(),
            };
            var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestVoiceChannel.Create(client, guild, model));
        }
Exemplo n.º 2
0
        internal new static RestVoiceChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            var entity = new RestVoiceChannel(discord, guild, model.Id);

            entity.Update(model);
            return(entity);
        }
Exemplo n.º 3
0
 internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
 {
     return(model.Type switch
     {
         ChannelType.News => RestNewsChannel.Create(discord, guild, model),
         ChannelType.Text => RestTextChannel.Create(discord, guild, model),
         ChannelType.Voice => RestVoiceChannel.Create(discord, guild, model),
         ChannelType.Stage => RestStageChannel.Create(discord, guild, model),
         ChannelType.Category => RestCategoryChannel.Create(discord, guild, model),
         ChannelType.PublicThread or ChannelType.PrivateThread or ChannelType.NewsThread => RestThreadChannel.Create(discord, guild, model),
         _ => new RestGuildChannel(discord, guild, model.Id),
     });
Exemplo n.º 4
0
        public static async Task <RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                            string name, RequestOptions options)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var args  = new CreateGuildChannelParams(name, ChannelType.Voice);
            var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestVoiceChannel.Create(client, guild, model));
        }
Exemplo n.º 5
0
        internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
                return(RestTextChannel.Create(discord, guild, model));

            case ChannelType.Voice:
                return(RestVoiceChannel.Create(discord, guild, model));

            default:
                throw new InvalidOperationException("Unknown guild channel type");
            }
        }
        internal static RestGuildChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
                return(RestTextChannel.Create(discord, guild, model));

            case ChannelType.Voice:
                return(RestVoiceChannel.Create(discord, guild, model));

            default:
                // TODO: Channel categories
                return(new RestGuildChannel(discord, guild, model.Id));
            }
        }
Exemplo n.º 7
0
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
        public static async Task <RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                            string name, RequestOptions options, Action <VoiceChannelProperties> func = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(paramName: nameof(name));
            }

            var props = new VoiceChannelProperties();

            func?.Invoke(props);

            var args = new CreateGuildChannelParams(name, ChannelType.Voice)
            {
                CategoryId = props.CategoryId,
                Bitrate    = props.Bitrate,
                UserLimit  = props.UserLimit
            };
            var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);

            return(RestVoiceChannel.Create(client, guild, model));
        }
Exemplo n.º 8
0
 /// <inheritdoc />
 public Task SyncPermissionsAsync(RequestOptions options = null)
 => RestVoiceChannel.SyncPermissionsAsync(options);
Exemplo n.º 9
0
 /// <summary>
 /// Converts an existing <see cref="RestVoiceChannel"/> to an abstracted <see cref="IRestVoiceChannel"/> value.
 /// </summary>
 /// <param name="restVoiceChannel">The existing <see cref="RestVoiceChannel"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="restVoiceChannel"/>.</exception>
 /// <returns>An <see cref="IRestVoiceChannel"/> that abstracts <paramref name="restVoiceChannel"/>.</returns>
 public static IRestVoiceChannel Abstract(this RestVoiceChannel restVoiceChannel)
 => new RestVoiceChannelAbstraction(restVoiceChannel);
Exemplo n.º 10
0
 /// <inheritdoc />
 public Task ModifyAsync(Action <VoiceChannelProperties> func, RequestOptions options = null)
 => RestVoiceChannel.ModifyAsync(func, options);
Exemplo n.º 11
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IInviteMetadata> > GetInvitesAsync(RequestOptions options = null)
 => (await RestVoiceChannel.GetInvitesAsync(options))
 .Select(InviteMetadataAbstractionExtensions.Abstract)
 .ToArray();
Exemplo n.º 12
0
 /// <inheritdoc />
 public async Task <ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
 => (await RestVoiceChannel.GetCategoryAsync(options))
 .Abstract();
Exemplo n.º 13
0
 /// <inheritdoc />
 public async Task <IInviteMetadata> CreateInviteAsync(int?maxAge = 86400, int?maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
 => (await RestVoiceChannel.CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options))
 .Abstract();
Exemplo n.º 14
0
 /// <summary>
 /// Constructs a new <see cref="RestVoiceChannelAbstraction"/> around an existing <see cref="Rest.RestVoiceChannel"/>.
 /// </summary>
 /// <param name="restVoiceChannel">The value to use for <see cref="Rest.RestVoiceChannel"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="restVoiceChannel"/>.</exception>
 public RestVoiceChannelAbstraction(RestVoiceChannel restVoiceChannel)
     : base(restVoiceChannel)
 {
 }