Some Http fixes, added SendMessage response
This commit is contained in:
@@ -77,10 +77,10 @@ namespace Discord.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Chat
|
//Chat
|
||||||
public static Task SendMessage(string channelId, string message, string[] mentions, HttpOptions options)
|
public static Task<APIResponses.SendMessage> SendMessage(string channelId, string message, string[] mentions, HttpOptions options)
|
||||||
{
|
{
|
||||||
var request = new APIRequests.SendMessage { Content = message, Mentions = mentions };
|
var request = new APIRequests.SendMessage { Content = message, Mentions = mentions };
|
||||||
return Http.Post(Endpoints.ChannelMessages(channelId), request, options);
|
return Http.Post<APIResponses.SendMessage>(Endpoints.ChannelMessages(channelId), request, options);
|
||||||
}
|
}
|
||||||
public static Task SendIsTyping(string channelId, HttpOptions options)
|
public static Task SendIsTyping(string channelId, HttpOptions options)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ namespace Discord.API.Models
|
|||||||
}
|
}
|
||||||
public class AcceptInvite : GetInvite { }
|
public class AcceptInvite : GetInvite { }
|
||||||
|
|
||||||
|
public class SendMessage : Message { }
|
||||||
public class GetMessages : Message { }
|
public class GetMessages : Message { }
|
||||||
|
|
||||||
public class GetRegions
|
public class GetRegions
|
||||||
|
|||||||
@@ -521,14 +521,18 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
CheckReady();
|
CheckReady();
|
||||||
if (text.Length <= 2000)
|
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
|
else
|
||||||
{
|
{
|
||||||
int blockCount = (int)Math.Ceiling(text.Length / (double)MaxMessageSize);
|
int blockCount = (int)Math.Ceiling(text.Length / (double)MaxMessageSize);
|
||||||
for (int i = 0; i < blockCount; i++)
|
for (int i = 0; i < blockCount; i++)
|
||||||
{
|
{
|
||||||
int index = i * MaxMessageSize;
|
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);
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,6 @@ namespace Discord.Helpers
|
|||||||
private const bool _isDebug = false;
|
private const bool _isDebug = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal static Task<ResponseT> Get<ResponseT>(string path, object data, HttpOptions options)
|
|
||||||
where ResponseT : class
|
|
||||||
=> Send<ResponseT>("GET", path, data, options);
|
|
||||||
internal static Task<string> Get(string path, object data, HttpOptions options)
|
|
||||||
=> Send("GET", path, data, options);
|
|
||||||
internal static Task<ResponseT> Get<ResponseT>(string path, HttpOptions options)
|
internal static Task<ResponseT> Get<ResponseT>(string path, HttpOptions options)
|
||||||
where ResponseT : class
|
where ResponseT : class
|
||||||
=> Send<ResponseT>("GET", path, null, options);
|
=> Send<ResponseT>("GET", path, null, options);
|
||||||
@@ -89,7 +84,7 @@ namespace Discord.Helpers
|
|||||||
internal static async Task<ResponseT> Send<ResponseT>(string method, string path, object data, HttpOptions options)
|
internal static async Task<ResponseT> Send<ResponseT>(string method, string path, object data, HttpOptions options)
|
||||||
where ResponseT : class
|
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);
|
string responseJson = await SendRequest(method, path, requestJson, options, true);
|
||||||
var response = JsonConvert.DeserializeObject<ResponseT>(responseJson);
|
var response = JsonConvert.DeserializeObject<ResponseT>(responseJson);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@@ -99,31 +94,13 @@ namespace Discord.Helpers
|
|||||||
}
|
}
|
||||||
internal static async Task<string> Send(string method, string path, object data, HttpOptions options)
|
internal static async Task<string> 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);
|
string responseJson = await SendRequest(method, path, requestJson, options, _isDebug);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
CheckEmptyResponse(responseJson);
|
CheckEmptyResponse(responseJson);
|
||||||
#endif
|
#endif
|
||||||
return responseJson;
|
return responseJson;
|
||||||
}
|
}
|
||||||
internal static async Task<ResponseT> Send<ResponseT>(string method, string path, HttpOptions options)
|
|
||||||
where ResponseT : class
|
|
||||||
{
|
|
||||||
string responseJson = await SendRequest(method, path, null, options, true);
|
|
||||||
var response = JsonConvert.DeserializeObject<ResponseT>(responseJson);
|
|
||||||
#if DEBUG
|
|
||||||
CheckResponse(responseJson, response);
|
|
||||||
#endif
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
internal static async Task<string> 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<string> SendRequest(string method, string path, string data, HttpOptions options, bool hasResponse)
|
private static async Task<string> SendRequest(string method, string path, string data, HttpOptions options, bool hasResponse)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user