Updated to use new outgoing message format

This commit is contained in:
RogueException
2015-12-23 21:07:48 -04:00
parent 7a2c9db21a
commit 33b79de116
5 changed files with 9 additions and 24 deletions

View File

@@ -15,8 +15,6 @@ namespace Discord.API.Client.Rest
[JsonProperty("content")]
public string Content { get; set; }
[JsonProperty("mentions"), JsonConverter(typeof(LongStringArrayConverter))]
public ulong[] MentionedUserIds { get; set; }
[JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)]
public string Nonce { get; set; }
[JsonProperty("tts")]

View File

@@ -16,8 +16,6 @@ namespace Discord.API.Client.Rest
[JsonProperty("content")]
public string Content { get; set; } = "";
[JsonProperty("mentions"), JsonConverter(typeof(LongStringArrayConverter))]
public ulong[] MentionedUserIds { get; set; } = new ulong[0];
public UpdateMessageRequest(ulong channelId, ulong messageId)
{

View File

@@ -13,15 +13,13 @@ namespace Discord.Net
{
public readonly ulong Id, ChannelId;
public readonly string Text;
public readonly ulong[] MentionedUsers;
public readonly bool IsTTS;
public MessageQueueItem(ulong id, ulong channelId, string text, ulong[] userIds, bool isTTS)
public MessageQueueItem(ulong id, ulong channelId, string text, bool isTTS)
{
Id = id;
ChannelId = channelId;
Text = text;
MentionedUsers = userIds;
IsTTS = isTTS;
}
}
@@ -37,13 +35,13 @@ namespace Discord.Net
_pending = new ConcurrentQueue<MessageQueueItem>();
}
public void QueueSend(ulong channelId, string text, ulong[] userIds, bool isTTS)
public void QueueSend(ulong channelId, string text, bool isTTS)
{
_pending.Enqueue(new MessageQueueItem(0, channelId, text, userIds, isTTS));
_pending.Enqueue(new MessageQueueItem(0, channelId, text, isTTS));
}
public void QueueEdit(ulong channelId, ulong messageId, string text, ulong[] userIds)
public void QueueEdit(ulong channelId, ulong messageId, string text)
{
_pending.Enqueue(new MessageQueueItem(channelId, messageId, text, userIds, false));
_pending.Enqueue(new MessageQueueItem(channelId, messageId, text, false));
}
internal Task Run(CancellationToken cancelToken, int interval)
@@ -64,7 +62,6 @@ namespace Discord.Net
var request = new SendMessageRequest(queuedMessage.ChannelId)
{
Content = queuedMessage.Text,
MentionedUserIds = queuedMessage.MentionedUsers,
Nonce = GenerateNonce().ToIdString(),
IsTTS = queuedMessage.IsTTS
};
@@ -74,8 +71,7 @@ namespace Discord.Net
{
var request = new UpdateMessageRequest(queuedMessage.ChannelId, queuedMessage.Id)
{
Content = queuedMessage.Text,
MentionedUserIds = queuedMessage.MentionedUsers
Content = queuedMessage.Text
};
await _client.ClientAPI.Send(request).ConfigureAwait(false);
}

View File

@@ -333,19 +333,16 @@ namespace Discord
private async Task<Message> SendMessageInternal(string text, bool isTTS)
{
Message msg = null;
var mentionedUsers = new List<User>();
text = Message.CleanUserMentions(this, text, mentionedUsers);
if (text.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentOutOfRangeException(nameof(text), $"Message must be {DiscordConfig.MaxMessageSize} characters or less.");
if (Client.Config.UseMessageQueue)
Client.MessageQueue.QueueSend(Id, text, mentionedUsers.Select(x => x.Id).ToArray(), isTTS);
Client.MessageQueue.QueueSend(Id, text, isTTS);
else
{
var request = new SendMessageRequest(Id)
{
Content = text,
MentionedUserIds = mentionedUsers.Select(x => x.Id).ToArray(),
Nonce = null,
IsTTS = isTTS
};

View File

@@ -314,21 +314,17 @@ namespace Discord
if (text == null) throw new ArgumentNullException(nameof(text));
var channel = Channel;
var mentionedUsers = new List<User>();
if (!channel.IsPrivate)
text = CleanUserMentions(channel, text, mentionedUsers);
if (text.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentOutOfRangeException(nameof(text), $"Message must be {DiscordConfig.MaxMessageSize} characters or less.");
if (Client.Config.UseMessageQueue)
Client.MessageQueue.QueueEdit(channel.Id, Id, text, mentionedUsers.Select(x => x.Id).ToArray());
Client.MessageQueue.QueueEdit(channel.Id, Id, text);
else
{
var request = new UpdateMessageRequest(Channel.Id, Id)
{
Content = text,
MentionedUserIds = mentionedUsers.Select(x => x.Id).ToArray()
Content = text
};
await Client.ClientAPI.Send(request).ConfigureAwait(false);
}