Beispiel #1
0
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
        public static async Task <RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                          string name, RequestOptions options, Action <TextChannelProperties> func = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(paramName: nameof(name));
            }

            var props = new TextChannelProperties();

            func?.Invoke(props);

            var args = new CreateGuildChannelParams(name, ChannelType.Text)
            {
                CategoryId       = props.CategoryId,
                Topic            = props.Topic,
                IsNsfw           = props.IsNsfw,
                Position         = props.Position,
                SlowModeInterval = props.SlowModeInterval,
                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(RestTextChannel.Create(client, guild, model));
        }
 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),
     });
Beispiel #3
0
        public static async Task <RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                          string name, RequestOptions options)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

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

            return(RestTextChannel.Create(client, guild, model));
        }
        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));
            }
        }
Beispiel #6
0
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
        public static async Task <RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client,
                                                                          string name, RequestOptions options, Action <TextChannelProperties> func = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(paramName: nameof(name));
            }

            var props = new TextChannelProperties();

            func?.Invoke(props);

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

            return(RestTextChannel.Create(client, guild, model));
        }