コード例 #1
0
        /// <exception cref="DiscordWebSocketException">Thrown if the payload fails to send because of a WebSocket error.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the socket is not connected.</exception>
        public Task SendVoiceStateUpdatePayload(Snowflake guildId, Snowflake?channelId, bool isMute, bool isDeaf)
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            data.SetSnowflake("guild_id", guildId);
            data.SetSnowflake("channel_id", channelId);
            data.Set("self_mute", isMute);
            data.Set("self_deaf", isDeaf);

            return(SendPayload(GatewayOPCode.VoiceStateUpdate, data));
        }
コード例 #2
0
        /// <exception cref="DiscordWebSocketException">Thrown if the payload fails to send because of a WebSocket error.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the socket is not connected.</exception>
        public Task SendIdentifyPayload(Snowflake serverId, Snowflake userId, string sessionId, string token)
        {
            DiscordApiData data = new DiscordApiData();

            data.SetSnowflake("server_id", serverId);
            data.SetSnowflake("user_id", userId);
            data.Set("session_id", sessionId);
            data.Set("token", token);

            log.LogVerbose("[Identify] Sending payload...");
            return(SendPayload(VoiceOPCode.Identify, data));
        }
コード例 #3
0
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            data.Set("content", Content);
            data.Set("tts", TextToSpeech);
            data.SetSnowflake("nonce", Nonce);

            if (Embed != null)
            {
                data.Set("embed", Embed.Build());
            }

            if (AllowedMentions != null)
            {
                data.Set("allowed_mentions", AllowedMentions.Build());
            }

            if (MessageReference != null)
            {
                data.Set("message_reference", MessageReference.Build());
            }

            return(data);
        }
コード例 #4
0
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            if (Nickname != null)
            {
                data.Set("nick", Nickname);
            }
            if (IsServerMute.HasValue)
            {
                data.Set("mute", IsServerMute);
            }
            if (IsServerDeaf.HasValue)
            {
                data.Set("deaf", IsServerDeaf);
            }
            if (ChannelId.HasValue)
            {
                data.SetSnowflake("channel_id", ChannelId);
            }

            if (RoleIds != null)
            {
                DiscordApiData rolesArray = new DiscordApiData(DiscordApiDataType.Array);
                foreach (Snowflake roleId in RoleIds)
                {
                    rolesArray.Values.Add(new DiscordApiData(roleId));
                }

                data.Set("roles", rolesArray);
            }

            return(data);
        }
コード例 #5
0
ファイル: ModifyGuildOptions.cs プロジェクト: Perksey/Discore
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            if (Name != null)
            {
                data.Set("name", Name);
            }
            if (VoiceRegion != null)
            {
                data.Set("region", VoiceRegion);
            }
            if (VerificationLevel.HasValue)
            {
                data.Set("verification_level", VerificationLevel);
            }
            if (DefaultMessageNotifications.HasValue)
            {
                data.Set("default_message_notifications", DefaultMessageNotifications);
            }
            if (AfkChannelId.HasValue)
            {
                data.SetSnowflake("afk_channel_id", AfkChannelId);
            }
            if (AfkTimeout.HasValue)
            {
                data.Set("afk_timeout", AfkTimeout);
            }
            if (Icon != null)
            {
                data.Set("icon", Icon.ToDataUriScheme());
            }
            if (OwnerId.HasValue)
            {
                data.SetSnowflake("owner_id", OwnerId);
            }
            if (Splash != null)
            {
                data.Set("splash", Splash.ToDataUriScheme());
            }
            if (SystemChannelId.HasValue)
            {
                data.SetSnowflake("system_channel_id", SystemChannelId);
            }

            return(data);
        }
コード例 #6
0
        internal override DiscordApiData Build()
        {
            DiscordApiData data = base.Build();

            data.SetSnowflake("id", TemporaryId);

            return(data);
        }
コード例 #7
0
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            if (Name != null)
            {
                data.Set("name", Name);
            }
            if (Position.HasValue)
            {
                data.Set("position", Position.Value);
            }
            if (Topic != null)
            {
                data.Set("topic", Topic);
            }
            if (Nsfw.HasValue)
            {
                data.Set("nsfw", Nsfw.Value);
            }

            if (ParentId.HasValue)
            {
                if (ParentId.Value == Snowflake.None)
                {
                    data.SetSnowflake("parent_id", null);
                }
                else
                {
                    data.SetSnowflake("parent_id", ParentId.Value);
                }
            }

            if (PermissionOverwrites != null)
            {
                DiscordApiData permissionOverwritesArray = new DiscordApiData(DiscordApiDataType.Array);
                foreach (OverwriteOptions overwriteParam in PermissionOverwrites)
                {
                    permissionOverwritesArray.Values.Add(overwriteParam.Build());
                }

                data.Set("permission_overwrites", permissionOverwritesArray);
            }

            return(data);
        }
コード例 #8
0
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);
            data.Set("enabled", Enabled);
            data.SetSnowflake("channel_id", ChannelId);

            return data;
        }
コード例 #9
0
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            data.SetSnowflake("id", Id);
            data.Set("position", Position);

            return(data);
        }
コード例 #10
0
        /// <summary>
        /// Attaches an integration from the current bot to the specified guild.
        /// <para>Requires <see cref="DiscordPermission.ManageGuild"/>.</para>
        /// </summary>
        /// <exception cref="DiscordHttpApiException"></exception>
        public async Task CreateGuildIntegration(Snowflake guildId, Snowflake integrationId, string type)
        {
            DiscordApiData requestData = new DiscordApiData(DiscordApiDataType.Container);

            requestData.SetSnowflake("id", integrationId);
            requestData.Set("type", type);

            await rest.Post($"guilds/{guildId}/integrations",
                            $"guilds/{guildId}/integrations").ConfigureAwait(false);
        }
コード例 #11
0
        /// <exception cref="DiscordWebSocketException">Thrown if the payload fails to send because of a WebSocket error.</exception>
        /// <exception cref="InvalidOperationException">Thrown if the socket is not connected.</exception>
        public Task SendRequestGuildMembersPayload(Snowflake guildId, string query, int limit)
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            data.SetSnowflake("guild_id", guildId);
            data.Set("query", query);
            data.Set("limit", limit);

            return(SendPayload(GatewayOPCode.RequestGuildMembers, data));
        }
コード例 #12
0
        /// <summary>
        /// Opens a DM channel with the specified user.
        /// </summary>
        /// <exception cref="DiscordHttpApiException"></exception>
        public async Task <DiscordDMChannel> CreateDM(Snowflake recipientId)
        {
            DiscordApiData requestData = new DiscordApiData(DiscordApiDataType.Container);

            requestData.SetSnowflake("recipient_id", recipientId);

            DiscordApiData returnData = await rest.Post("users/@me/channels", requestData,
                                                        "users/@me/channels").ConfigureAwait(false);

            return(new DiscordDMChannel(this, returnData));
        }
コード例 #13
0
ファイル: OverwriteOptions.cs プロジェクト: Perksey/Discore
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            data.SetSnowflake("id", Id);
            data.Set("type", Type.ToString().ToLower());
            data.Set("allow", (int)Allow);
            data.Set("deny", (int)Deny);

            return(data);
        }
コード例 #14
0
        internal DiscordApiData Build()
        {
            DiscordApiData data = new DiscordApiData(DiscordApiDataType.Container);

            data.SetSnowflake("message_id", MessageId);

            if (FailIfNotExists != null)
            {
                data.Set("fail_if_not_exists", FailIfNotExists.Value);
            }

            return(data);
        }
コード例 #15
0
        /// <exception cref="ArgumentNullException"></exception>
        async Task <DiscordMessage> CreateMessage(Snowflake channelId, HttpContent fileContent, string fileName,
                                                  CreateMessageOptions options)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                // Technically this is also handled when setting the field on the multipart form data
                throw new ArgumentNullException(nameof(fileName));
            }

            DiscordApiData returnData = await rest.Send(() =>
            {
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,
                                                                    $"{RestClient.BASE_URL}/channels/{channelId}/messages");

                MultipartFormDataContent data = new MultipartFormDataContent();
                data.Add(fileContent, "file", fileName);

                if (options != null)
                {
                    DiscordApiData payloadJson = new DiscordApiData();
                    payloadJson.Set("content", options.Content);
                    payloadJson.Set("tts", options.TextToSpeech);
                    payloadJson.SetSnowflake("nonce", options.Nonce);

                    if (options.Embed != null)
                    {
                        payloadJson.Set("embed", options.Embed.Build());
                    }

                    data.Add(new StringContent(payloadJson.SerializeToJson()), "payload_json");
                }

                request.Content = data;

                return(request);
            }, $"channels/{channelId}/messages").ConfigureAwait(false);

            return(new DiscordMessage(this, returnData));
        }
コード例 #16
0
        /// <summary>
        /// Posts a message to a text channel.
        /// <para>Note: Bot user accounts must connect to the Gateway at least once before being able to send messages.</para>
        /// <para>Requires <see cref="DiscordPermission.SendMessages"/>.</para>
        /// <para>Requires <see cref="DiscordPermission.SendTtsMessages"/> if TTS is enabled on the message.</para>
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="options"/> is null.</exception>
        /// <exception cref="DiscordHttpApiException"></exception>
        public async Task <DiscordMessage> CreateMessage(Snowflake channelId, CreateMessageOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            DiscordApiData requestData = new DiscordApiData(DiscordApiDataType.Container);

            requestData.Set("content", options.Content);
            requestData.Set("tts", options.TextToSpeech);
            requestData.SetSnowflake("nonce", options.Nonce);

            if (options.Embed != null)
            {
                requestData.Set("embed", options.Embed.Build());
            }

            DiscordApiData returnData = await rest.Post($"channels/{channelId}/messages", requestData,
                                                        $"channels/{channelId}/messages").ConfigureAwait(false);

            return(new DiscordMessage(this, returnData));
        }
コード例 #17
0
        /// <summary>
        /// Modifies an existing webhook.
        /// <para>Requires <see cref="DiscordPermission.ManageWebhooks"/>.</para>
        /// </summary>
        /// <param name="channelId">The ID of the text channel to move the webhook to (or null to not move).</param>
        /// <exception cref="DiscordHttpApiException"></exception>
        public async Task <DiscordWebhook> ModifyWebhook(Snowflake webhookId,
                                                         string name = null, DiscordImageData avatar = null, Snowflake?channelId = null)
        {
            DiscordApiData postData = DiscordApiData.CreateContainer();

            if (name != null)
            {
                postData.Set("name", name);
            }
            if (avatar != null)
            {
                postData.Set("avatar", avatar);
            }
            if (channelId.HasValue)
            {
                postData.SetSnowflake("channel_id", channelId.Value);
            }

            DiscordApiData apiData = await rest.Patch($"webhooks/{webhookId}", postData,
                                                      $"webhooks/{webhookId}").ConfigureAwait(false);

            return(new DiscordWebhook(this, apiData));
        }