Ejemplo n.º 1
0
        public static async Task <RestInviteMetadata> GetVanityInviteAsync(IGuild guild, BaseDiscordClient client,
                                                                           RequestOptions options)
        {
            var model = await client.ApiClient.GetVanityInviteAsync(guild.Id, options).ConfigureAwait(false);

            return(RestInviteMetadata.Create(client, guild, null, model));
        }
Ejemplo n.º 2
0
        //Invites
        public static async Task <IReadOnlyCollection <RestInviteMetadata> > GetInvitesAsync(IGuild guild, BaseDiscordClient client,
                                                                                             RequestOptions options)
        {
            var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false);

            return(models.Select(x => RestInviteMetadata.Create(client, guild, null, x)).ToImmutableArray());
        }
Ejemplo n.º 3
0
        public static async Task <RestInviteMetadata> CreateInviteAsync(IGuildChannel channel, BaseDiscordClient client,
                                                                        int?maxAge, int?maxUses, bool isTemporary, bool isUnique, RequestOptions options)
        {
            var args = new CreateChannelInviteParams {
                IsTemporary = isTemporary, IsUnique = isUnique
            };

            if (maxAge.HasValue)
            {
                args.MaxAge = maxAge.Value;
            }
            else
            {
                args.MaxAge = 0;
            }
            if (maxUses.HasValue)
            {
                args.MaxUses = maxUses.Value;
            }
            else
            {
                args.MaxUses = 0;
            }
            var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestInviteMetadata.Create(client, null, channel, model));
        }
Ejemplo n.º 4
0
        //Invites
        public static async Task <IReadOnlyCollection <RestInviteMetadata> > GetInvitesAsync(IGuildChannel channel, BaseDiscordClient client,
                                                                                             RequestOptions options)
        {
            IReadOnlyCollection <API.InviteMetadataJson> models = await client.ApiClient.GetChannelInvitesAsync(channel.Id, options).ConfigureAwait(false);

            return(models.Select(x => RestInviteMetadata.Create(client, null, channel, x)).ToImmutableArray());
        }
Ejemplo n.º 5
0
        public static async Task <RestInviteMetadata> GetInviteAsync(BaseDiscordClient client,
                                                                     string inviteId, RequestOptions options)
        {
            var model = await client.ApiClient.GetInviteAsync(inviteId, options).ConfigureAwait(false);

            if (model != null)
            {
                return(RestInviteMetadata.Create(client, null, null, model));
            }
            return(null);
        }
Ejemplo n.º 6
0
        public static async Task <RestInviteMetadata> GetVanityInviteAsync(IGuild guild, BaseDiscordClient client,
                                                                           RequestOptions options)
        {
            var vanityModel = await client.ApiClient.GetVanityInviteAsync(guild.Id, options).ConfigureAwait(false);

            if (vanityModel == null)
            {
                throw new InvalidOperationException("This guild does not have a vanity URL.");
            }
            var inviteModel = await client.ApiClient.GetInviteAsync(vanityModel.Code, options).ConfigureAwait(false);

            return(RestInviteMetadata.Create(client, guild, null, inviteModel));
        }
Ejemplo n.º 7
0
 /// <exception cref="ArgumentException">
 /// <paramref name="channel.Id"/> may not be equal to zero.
 /// -and-
 /// <paramref name="maxAge"/> and <paramref name="maxUses"/> must be greater than zero.
 /// -and-
 /// <paramref name="maxAge"/> must be lesser than 86400.
 /// </exception>
 public static async Task<RestInviteMetadata> CreateInviteAsync(IGuildChannel channel, BaseDiscordClient client,
     int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
 {
     var args = new API.Rest.CreateChannelInviteParams
     {
         IsTemporary = isTemporary,
         IsUnique = isUnique,
         MaxAge = maxAge ?? 0,
         MaxUses = maxUses ?? 0
     };
     var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);
     return RestInviteMetadata.Create(client, null, channel, model);
 }
Ejemplo n.º 8
0
        /// <exception cref="ArgumentException">
        /// <paramref name="channel.Id"/> may not be equal to zero.
        /// -and-
        /// <paramref name="maxAge"/> and <paramref name="maxUses"/> must be greater than zero.
        /// -and-
        /// <paramref name="maxAge"/> must be lesser than 86400.
        /// </exception>
        public static async Task <RestInviteMetadata> CreateInviteToApplicationAsync(IGuildChannel channel, BaseDiscordClient client,
                                                                                     int?maxAge, int?maxUses, bool isTemporary, bool isUnique, ulong applicationId,
                                                                                     RequestOptions options)
        {
            var args = new API.Rest.CreateChannelInviteParams
            {
                IsTemporary         = isTemporary,
                IsUnique            = isUnique,
                MaxAge              = maxAge ?? 0,
                MaxUses             = maxUses ?? 0,
                TargetType          = TargetUserType.EmbeddedApplication,
                TargetApplicationId = applicationId
            };
            var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options).ConfigureAwait(false);

            return(RestInviteMetadata.Create(client, null, channel, model));
        }