diff --git a/Discord.Net/API/DiscordAPI.cs b/Discord.Net/API/DiscordAPI.cs index e3f356508..49ec14c74 100644 --- a/Discord.Net/API/DiscordAPI.cs +++ b/Discord.Net/API/DiscordAPI.cs @@ -77,10 +77,10 @@ namespace Discord.API } //Chat - public static Task SendMessage(string channelId, string message, string[] mentions, HttpOptions options) + public static Task SendMessage(string channelId, string message, string[] mentions, HttpOptions options) { var request = new APIRequests.SendMessage { Content = message, Mentions = mentions }; - return Http.Post(Endpoints.ChannelMessages(channelId), request, options); + return Http.Post(Endpoints.ChannelMessages(channelId), request, options); } public static Task SendIsTyping(string channelId, HttpOptions options) { diff --git a/Discord.Net/API/Models/APIResponses.cs b/Discord.Net/API/Models/APIResponses.cs index 70447f4e8..c57b132ba 100644 --- a/Discord.Net/API/Models/APIResponses.cs +++ b/Discord.Net/API/Models/APIResponses.cs @@ -56,6 +56,7 @@ namespace Discord.API.Models } public class AcceptInvite : GetInvite { } + public class SendMessage : Message { } public class GetMessages : Message { } public class GetRegions diff --git a/Discord.Net/DiscordClient.cs b/Discord.Net/DiscordClient.cs index 7656dacf4..ed53eee62 100644 --- a/Discord.Net/DiscordClient.cs +++ b/Discord.Net/DiscordClient.cs @@ -521,14 +521,18 @@ namespace Discord { CheckReady(); if (text.Length <= 2000) - await DiscordAPI.SendMessage(channelId, text, mentions, _httpOptions); + { + var msg = await DiscordAPI.SendMessage(channelId, text, mentions, _httpOptions); + _messages.Update(msg.Id, msg); + } else { int blockCount = (int)Math.Ceiling(text.Length / (double)MaxMessageSize); for (int i = 0; i < blockCount; i++) { int index = i * MaxMessageSize; - await DiscordAPI.SendMessage(channelId, text.Substring(index, Math.Min(2000, text.Length - index)), mentions, _httpOptions); + var msg = await DiscordAPI.SendMessage(channelId, text.Substring(index, Math.Min(2000, text.Length - index)), mentions, _httpOptions); + _messages.Update(msg.Id, msg); await Task.Delay(1000); } } diff --git a/Discord.Net/Helpers/Http.cs b/Discord.Net/Helpers/Http.cs index acd99f8cb..8a799534c 100644 --- a/Discord.Net/Helpers/Http.cs +++ b/Discord.Net/Helpers/Http.cs @@ -31,11 +31,6 @@ namespace Discord.Helpers private const bool _isDebug = false; #endif - internal static Task Get(string path, object data, HttpOptions options) - where ResponseT : class - => Send("GET", path, data, options); - internal static Task Get(string path, object data, HttpOptions options) - => Send("GET", path, data, options); internal static Task Get(string path, HttpOptions options) where ResponseT : class => Send("GET", path, null, options); @@ -89,7 +84,7 @@ namespace Discord.Helpers internal static async Task Send(string method, string path, object data, HttpOptions options) where ResponseT : class { - string requestJson = JsonConvert.SerializeObject(data); + string requestJson = data != null ? JsonConvert.SerializeObject(data) : null; string responseJson = await SendRequest(method, path, requestJson, options, true); var response = JsonConvert.DeserializeObject(responseJson); #if DEBUG @@ -99,31 +94,13 @@ namespace Discord.Helpers } internal static async Task Send(string method, string path, object data, HttpOptions options) { - string requestJson = JsonConvert.SerializeObject(data); + string requestJson = data != null ? JsonConvert.SerializeObject(data) : null; string responseJson = await SendRequest(method, path, requestJson, options, _isDebug); #if DEBUG CheckEmptyResponse(responseJson); #endif return responseJson; } - internal static async Task Send(string method, string path, HttpOptions options) - where ResponseT : class - { - string responseJson = await SendRequest(method, path, null, options, true); - var response = JsonConvert.DeserializeObject(responseJson); -#if DEBUG - CheckResponse(responseJson, response); -#endif - return response; - } - internal static async Task Send(string method, string path, HttpOptions options) - { - string responseJson = await SendRequest(method, path, null, options, _isDebug); -#if DEBUG - CheckEmptyResponse(responseJson); -#endif - return responseJson; - } private static async Task SendRequest(string method, string path, string data, HttpOptions options, bool hasResponse) {