Пример #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));
        }
Пример #2
0
        internal new static RestTextChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
        {
            var entity = new RestTextChannel(discord, guild, model.Id);

            entity.Update(model);
            return(entity);
        }
Пример #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),
     });
Пример #4
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));
        }
Пример #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));
            }
        }
Пример #7
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));
        }
Пример #8
0
 /// <summary>
 /// Constructs a new <see cref="RestTextChannelAbstraction"/> around an existing <see cref="Rest.RestTextChannel"/>.
 /// </summary>
 /// <param name="restTextChannel">The value to use for <see cref="Rest.RestTextChannel"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="restTextChannel"/>.</exception>
 public RestTextChannelAbstraction(RestTextChannel restTextChannel)
     : base(restTextChannel)
 {
 }
Пример #9
0
 /// <summary>
 /// Converts an existing <see cref="RestTextChannel"/> to an abstracted <see cref="IRestTextChannel"/> value.
 /// </summary>
 /// <param name="restTextChannel">The existing <see cref="RestTextChannel"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="restTextChannel"/>.</exception>
 /// <returns>An <see cref="IRestTextChannel"/> that abstracts <paramref name="restTextChannel"/>.</returns>
 public static IRestTextChannel Abstract(this RestTextChannel restTextChannel)
 => new RestTextChannelAbstraction(restTextChannel);
Пример #10
0
 /// <inheritdoc />
 public Task SyncPermissionsAsync(RequestOptions options = null)
 => RestTextChannel.SyncPermissionsAsync(options);
Пример #11
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null)
 => (await RestTextChannel.SendMessageAsync(text, isTTS, embed, options))
 .Abstract();
Пример #12
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false)
 => (await RestTextChannel.SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler))
 .Abstract();
Пример #13
0
 /// <inheritdoc />
 public IDisposable EnterTypingState(RequestOptions options = null)
 => RestTextChannel.EnterTypingState(options);
Пример #14
0
 /// <inheritdoc />
 public Task DeleteMessageAsync(IMessage message, RequestOptions options = null)
 => RestTextChannel.DeleteMessageAsync(message, options);
Пример #15
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> ModifyMessageAsync(ulong messageId, Action <MessageProperties> func, RequestOptions options = null)
 => (IRestUserMessage)(await RestTextChannel.ModifyMessageAsync(messageId, func, options))
 ?.Abstract();
Пример #16
0
 /// <inheritdoc />
 public IAsyncEnumerable <IReadOnlyCollection <IRestGuildUser> > GetUsersAsync(RequestOptions options = null)
 => RestTextChannel.GetUsersAsync(options)
 .Select(x => x
         .Select(RestGuildUserAbstractionExtensions.Abstract)
         .ToArray());
Пример #17
0
 /// <inheritdoc />
 public async Task <IRestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
 => (await RestTextChannel.GetUserAsync(id, options))
 ?.Abstract();
Пример #18
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IRestMessage> > GetPinnedMessagesAsync(RequestOptions options = null)
 => (await RestTextChannel.GetPinnedMessagesAsync(options))
 .Select(RestMessageAbstractionExtensions.Abstract)
 .ToArray();
Пример #19
0
 /// <inheritdoc />
 public IAsyncEnumerable <IReadOnlyCollection <IRestMessage> > GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null)
 => RestTextChannel.GetMessagesAsync(fromMessage, dir, limit, options)
 .Select(x => x
         .Select(RestMessageAbstractionExtensions.Abstract)
         .ToArray());
Пример #20
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IInviteMetadata> > GetInvitesAsync(RequestOptions options = null)
 => (await RestTextChannel.GetInvitesAsync(options))
 .Select(InviteMetadataAbstractionExtensions.Abstract)
 .ToArray();
Пример #21
0
 /// <inheritdoc />
 public async Task <ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
 => (await RestTextChannel.GetCategoryAsync(options))
 .Abstract();
Пример #22
0
 /// <inheritdoc />
 public async Task <IInviteMetadata> CreateInviteAsync(int?maxAge = 86400, int?maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
 => (await RestTextChannel.CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options))
 .Abstract();
Пример #23
0
 /// <inheritdoc />
 public async Task <IRestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
 => (await RestTextChannel.CreateWebhookAsync(name, avatar, options))
 .Abstract();
Пример #24
0
 /// <inheritdoc />
 public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
 => RestTextChannel.DeleteMessageAsync(messageId, options);
Пример #25
0
 /// <inheritdoc />
 public Task ModifyAsync(Action <TextChannelProperties> func, RequestOptions options = null)
 => RestTextChannel.ModifyAsync(func, options);
Пример #26
0
 /// <inheritdoc />
 public Task DeleteMessagesAsync(IEnumerable <ulong> messageIds, RequestOptions options = null)
 => RestTextChannel.DeleteMessagesAsync(messageIds, options);
Пример #27
0
 /// <inheritdoc />
 public async Task <IRestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
 => (await RestTextChannel.GetWebhookAsync(id, options))
 ?.Abstract();
Пример #28
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
 => (await RestTextChannel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference))
 .Abstract();
Пример #29
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IRestWebhook> > GetWebhooksAsync(RequestOptions options = null)
 => (await RestTextChannel.GetWebhooksAsync(options))
 .Select(RestWebhookAbstractionExtensions.Abstract)
 .ToArray();
Пример #30
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null)
 => (await RestTextChannel.SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions))
 .Abstract();