Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
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 <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));
        }
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 <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));
        }
Exemplo n.º 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)
 {
 }
Exemplo n.º 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);
Exemplo n.º 10
0
 /// <inheritdoc />
 public Task SyncPermissionsAsync(RequestOptions options = null)
 => RestTextChannel.SyncPermissionsAsync(options);
Exemplo n.º 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();
Exemplo n.º 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();
Exemplo n.º 13
0
 /// <inheritdoc />
 public IDisposable EnterTypingState(RequestOptions options = null)
 => RestTextChannel.EnterTypingState(options);
Exemplo n.º 14
0
 /// <inheritdoc />
 public Task DeleteMessageAsync(IMessage message, RequestOptions options = null)
 => RestTextChannel.DeleteMessageAsync(message, options);
Exemplo n.º 15
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> ModifyMessageAsync(ulong messageId, Action <MessageProperties> func, RequestOptions options = null)
 => (IRestUserMessage)(await RestTextChannel.ModifyMessageAsync(messageId, func, options))
 ?.Abstract();
Exemplo n.º 16
0
 /// <inheritdoc />
 public IAsyncEnumerable <IReadOnlyCollection <IRestGuildUser> > GetUsersAsync(RequestOptions options = null)
 => RestTextChannel.GetUsersAsync(options)
 .Select(x => x
         .Select(RestGuildUserAbstractionExtensions.Abstract)
         .ToArray());
Exemplo n.º 17
0
 /// <inheritdoc />
 public async Task <IRestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
 => (await RestTextChannel.GetUserAsync(id, options))
 ?.Abstract();
Exemplo n.º 18
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IRestMessage> > GetPinnedMessagesAsync(RequestOptions options = null)
 => (await RestTextChannel.GetPinnedMessagesAsync(options))
 .Select(RestMessageAbstractionExtensions.Abstract)
 .ToArray();
Exemplo n.º 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());
Exemplo n.º 20
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IInviteMetadata> > GetInvitesAsync(RequestOptions options = null)
 => (await RestTextChannel.GetInvitesAsync(options))
 .Select(InviteMetadataAbstractionExtensions.Abstract)
 .ToArray();
Exemplo n.º 21
0
 /// <inheritdoc />
 public async Task <ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
 => (await RestTextChannel.GetCategoryAsync(options))
 .Abstract();
Exemplo n.º 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();
Exemplo n.º 23
0
 /// <inheritdoc />
 public async Task <IRestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
 => (await RestTextChannel.CreateWebhookAsync(name, avatar, options))
 .Abstract();
Exemplo n.º 24
0
 /// <inheritdoc />
 public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
 => RestTextChannel.DeleteMessageAsync(messageId, options);
Exemplo n.º 25
0
 /// <inheritdoc />
 public Task ModifyAsync(Action <TextChannelProperties> func, RequestOptions options = null)
 => RestTextChannel.ModifyAsync(func, options);
Exemplo n.º 26
0
 /// <inheritdoc />
 public Task DeleteMessagesAsync(IEnumerable <ulong> messageIds, RequestOptions options = null)
 => RestTextChannel.DeleteMessagesAsync(messageIds, options);
Exemplo n.º 27
0
 /// <inheritdoc />
 public async Task <IRestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
 => (await RestTextChannel.GetWebhookAsync(id, options))
 ?.Abstract();
Exemplo n.º 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();
Exemplo n.º 29
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IRestWebhook> > GetWebhooksAsync(RequestOptions options = null)
 => (await RestTextChannel.GetWebhooksAsync(options))
 .Select(RestWebhookAbstractionExtensions.Abstract)
 .ToArray();
Exemplo n.º 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();