Esempio n. 1
0
 /// <inheritdoc />
 public virtual Task <IRetrieveRestEntityResult <IUser> > GetCurrentUserAsync(CancellationToken ct = default)
 {
     return(_discordHttpClient.GetAsync <IUser>
            (
                "users/@me",
                ct: ct
            ));
 }
Esempio n. 2
0
 /// <inheritdoc />
 public virtual Task <IRetrieveRestEntityResult <IApplication> > GetCurrentApplicationInformationAsync
 (
     CancellationToken ct = default
 )
 {
     return(_discordHttpClient.GetAsync <IApplication>
            (
                "oauth2/applications/@me",
                ct: ct
            ));
 }
 /// <inheritdoc />
 public Task <IRetrieveRestEntityResult <IMembershipScreening> > GetGuildMembershipScreeningFormAsync
 (
     Snowflake guildID,
     CancellationToken ct = default
 )
 {
     return(_discordHttpClient.GetAsync <IMembershipScreening>
            (
                $"guilds/{guildID}/member-verification",
                ct: ct
            ));
 }
Esempio n. 4
0
 /// <inheritdoc />
 public virtual Task <IRetrieveRestEntityResult <IChannel> > GetChannelAsync
 (
     Snowflake channelID,
     CancellationToken ct = default
 )
 {
     return(_discordHttpClient.GetAsync <IChannel>
            (
                $"channels/{channelID}",
                ct: ct
            ));
 }
Esempio n. 5
0
 /// <inheritdoc />
 public virtual Task <Result <IReadOnlyList <IEmoji> > > ListGuildEmojisAsync
 (
     Snowflake guildID,
     CancellationToken ct = default
 )
 {
     return(_discordHttpClient.GetAsync <IReadOnlyList <IEmoji> >
            (
                $"guilds/{guildID}/emojis",
                ct: ct
            ));
 }
 /// <inheritdoc />
 public virtual Task <Result <ITemplate> > GetTemplateAsync
 (
     string templateCode,
     CancellationToken ct = default
 )
 {
     return(_discordHttpClient.GetAsync <ITemplate>
            (
                $"guilds/templates/{templateCode}",
                ct: ct
            ));
 }
 /// <inheritdoc />
 public virtual Task <Result <IReadOnlyList <IApplicationCommand> > > GetGlobalApplicationCommandsAsync
 (
     Snowflake applicationID,
     CancellationToken ct
 )
 {
     return(_discordHttpClient.GetAsync <IReadOnlyList <IApplicationCommand> >
            (
                $"applications/{applicationID}/commands",
                ct: ct
            ));
 }
 /// <inheritdoc />
 public virtual Task <IRetrieveRestEntityResult <IReadOnlyList <IWebhook> > > GetChannelWebhooksAsync
 (
     Snowflake channelID,
     CancellationToken ct = default
 )
 {
     return(_discordHttpClient.GetAsync <IReadOnlyList <IWebhook> >
            (
                $"channels/{channelID}/webhooks",
                ct: ct
            ));
 }
Esempio n. 9
0
            public Task <List <Channel> > GetChannels()
            {
                // TODO: Handle additional channels being added after bots first pass through
                if (Channels.Count > 0)
                {
                    return(Task.Run(() => Channels));
                }

                Task <HttpResponseMessage> httpResponseTask = DiscordHttpClient.GetAsync($"guilds/{Id}/channels");

                Task <List <Channel> > channelDataTask = new Task <List <Channel> >(() =>
                {
                    HttpResponseMessage httpResponse = httpResponseTask.Result;
                    if (httpResponse.IsSuccessStatusCode == false)
                    {
                        return(new List <Channel>());
                    }

                    string response         = httpResponse.Content.ReadAsStringAsync().Result;
                    List <Channel> channels = JsonConvert.DeserializeObject <List <Channel> >(response);
                    Channels = channels;
                    return(channels);
                });

                channelDataTask.Start();
                return(channelDataTask);
            }
Esempio n. 10
0
        /// <inheritdoc />
        public virtual Task <Result <IInvite> > GetInviteAsync
        (
            string inviteCode,
            Optional <bool> withCounts     = default,
            Optional <bool> withExpiration = default,
            CancellationToken ct           = default
        )
        {
            return(_discordHttpClient.GetAsync <IInvite>
                   (
                       $"invite/{inviteCode}",
                       b =>
            {
                if (withCounts.HasValue)
                {
                    b.AddQueryParameter("with_counts", withCounts.Value.ToString());
                }

                if (withExpiration.HasValue)
                {
                    b.AddQueryParameter("with_expiration", withExpiration.Value.ToString());
                }
            },
                       ct: ct
                   ));
        }
Esempio n. 11
0
            public Task <List <Message> > GetNewMessages()
            {
                // Do not want the after query before we have populated lastRecieved as it will start fetching messages from the beginning of time
                string query = _lastRecievedMessageId != "0" ? $"?after={_lastRecievedMessageId}" : "";
                Task <HttpResponseMessage> httpResponseTask = DiscordHttpClient.GetAsync($"channels/{Id}/messages{query}");

                Task <List <Message> > messagesDataTask = new Task <List <Message> >(() =>
                {
                    HttpResponseMessage httpResponse = httpResponseTask.Result;
                    if (httpResponse.IsSuccessStatusCode == false)
                    {
                        return(new List <Message>());
                    }

                    string response         = httpResponse.Content.ReadAsStringAsync().Result;
                    List <Message> messages = JsonConvert.DeserializeObject <List <Message> >(response);
                    messages.ForEach((message) => message.Channel = this);

                    //Response always ordered with recent at top. So can take ID from first item
                    if (messages.Count > 0)
                    {
                        _lastRecievedMessageId = messages[0].Id;
                    }
                    return(messages);
                });

                messagesDataTask.Start();
                return(messagesDataTask);
            }
 /// <inheritdoc />
 public Task <Result <IStageInstance> > GetStageInstanceAsync(Snowflake channelID, CancellationToken ct = default)
 {
     return(_discordHttpClient.GetAsync <IStageInstance>
            (
                $"stage-instances/{channelID}",
                ct: ct
            ));
 }
Esempio n. 13
0
 /// <inheritdoc />
 public virtual Task <Result <IGuild> > GetGuildAsync
 (
     Snowflake guildID,
     Optional <bool> withCounts = default,
     CancellationToken ct       = default
 )
 {
     return(_discordHttpClient.GetAsync <IGuild>
            (
                $"guilds/{guildID}",
                b =>
     {
         if (withCounts.HasValue)
         {
             b.AddQueryParameter("with_counts", withCounts.Value.ToString());
         }
     },
                ct: ct
            ));
 }
Esempio n. 14
0
 /// <inheritdoc />
 public virtual Task <IRetrieveRestEntityResult <IReadOnlyList <IVoiceRegion> > > ListVoiceRegionsAsync
 (
     CancellationToken ct = default
 )
 {
     return(_discordHttpClient.GetAsync <IReadOnlyList <IVoiceRegion> >
            (
                "voice/regions",
                ct: ct
            ));
 }
        /// <inheritdoc />
        public virtual async Task <IRetrieveRestEntityResult <IAuditLog> > GetAuditLogAsync
        (
            Snowflake guildID,
            Optional <Snowflake> userID         = default,
            Optional <AuditLogEvent> actionType = default,
            Optional <Snowflake> before         = default,
            Optional <byte> limit = default,
            CancellationToken ct  = default
        )
        {
            if (limit.HasValue && (limit.Value > 100 || limit.Value == 0))
            {
                return(RetrieveRestEntityResult <IAuditLog> .FromError
                       (
                           $"Invalid value for {nameof(limit)}; only values between 1 and 100 are allowed."
                       ));
            }

            return(await _discordHttpClient.GetAsync <IAuditLog>
                   (
                       $"guilds/{guildID}/audit-logs",
                       b =>
            {
                if (userID.HasValue)
                {
                    b.AddQueryParameter("user_id", userID.Value.ToString());
                }

                if (actionType.HasValue)
                {
                    b.AddQueryParameter("action_type", ((int)actionType.Value).ToString());
                }

                if (before.HasValue)
                {
                    b.AddQueryParameter("before", before.Value.ToString());
                }

                if (limit.HasValue)
                {
                    b.AddQueryParameter("limit", limit.Value.ToString());
                }
            },
                       ct : ct
                   ));
        }
Esempio n. 16
0
            public Task <List <Guild> > GetCurrentUserGuilds()
            {
                Task <HttpResponseMessage> httpResponseTask = DiscordHttpClient.GetAsync("users/@me/guilds");

                Task <List <Guild> > guildDataTask = new Task <List <Guild> >(() =>
                {
                    HttpResponseMessage httpResponse = httpResponseTask.Result;
                    if (httpResponse.IsSuccessStatusCode == false)
                    {
                        return(new List <Guild>());
                    }

                    string response = httpResponse.Content.ReadAsStringAsync().Result;
                    return(JsonConvert.DeserializeObject <List <Guild> >(response));
                });

                guildDataTask.Start();
                return(guildDataTask);
            }
Esempio n. 17
0
 /// <inheritdoc />
 public virtual Task <IRetrieveRestEntityResult <IGatewayEndpoint> > GetGatewayAsync(CancellationToken ct = default)
 {
     return(_discordHttpClient.GetAsync <IGatewayEndpoint>("gateway", ct: ct));
 }