Added TTS support
This commit is contained in:
@@ -245,7 +245,7 @@ namespace Discord
|
||||
=> SendMessage(channel?.Id, text, mentions);
|
||||
/// <summary> Sends a message to the provided channel, mentioning certain users. </summary>
|
||||
/// <remarks> While not required, it is recommended to include a mention reference in the text (see User.Mention). </remarks>
|
||||
public async Task<Message[]> SendMessage(string channelId, string text, string[] mentions)
|
||||
public async Task<Message[]> SendMessage(string channelId, string text, string[] mentions, bool isTextToSpeech = false)
|
||||
{
|
||||
CheckReady();
|
||||
if (channelId == null) throw new ArgumentNullException(nameof(channelId));
|
||||
@@ -267,7 +267,8 @@ namespace Discord
|
||||
Content = blockText,
|
||||
Timestamp = DateTime.UtcNow,
|
||||
Author = new UserReference { Avatar = _currentUser.AvatarId, Discriminator = _currentUser.Discriminator, Id = _currentUser.Id, Username = _currentUser.Name },
|
||||
ChannelId = channelId
|
||||
ChannelId = channelId,
|
||||
IsTextToSpeech = isTextToSpeech
|
||||
});
|
||||
msg.IsQueued = true;
|
||||
msg.Nonce = nonce;
|
||||
@@ -276,11 +277,11 @@ namespace Discord
|
||||
}
|
||||
else
|
||||
{
|
||||
var model = await _api.SendMessage(channelId, blockText, mentions, nonce).ConfigureAwait(false);
|
||||
var model = await _api.SendMessage(channelId, blockText, mentions, nonce, isTextToSpeech).ConfigureAwait(false);
|
||||
var msg = _messages.GetOrAdd(model.Id, channelId, model.Author.Id);
|
||||
msg.Update(model);
|
||||
RaiseMessageSent(msg);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -791,7 +791,7 @@ namespace Discord
|
||||
Responses.SendMessage response = null;
|
||||
try
|
||||
{
|
||||
response = await _api.SendMessage(msg.ChannelId, msg.RawText, msg.MentionIds, msg.Nonce).ConfigureAwait(false);
|
||||
response = await _api.SendMessage(msg.ChannelId, msg.RawText, msg.MentionIds, msg.Nonce, msg.IsTTS).ConfigureAwait(false);
|
||||
}
|
||||
catch (WebException) { break; }
|
||||
catch (HttpException) { hasFailed = true; }
|
||||
|
||||
@@ -125,9 +125,9 @@ namespace Discord.Net.API
|
||||
}
|
||||
|
||||
//Chat
|
||||
public Task<Responses.SendMessage> SendMessage(string channelId, string message, string[] mentions, string nonce)
|
||||
public Task<Responses.SendMessage> SendMessage(string channelId, string message, string[] mentions, string nonce, bool isTTS)
|
||||
{
|
||||
var request = new Requests.SendMessage { Content = message, Mentions = mentions, Nonce = nonce };
|
||||
var request = new Requests.SendMessage { Content = message, Mentions = mentions, Nonce = nonce, IsTTS = isTTS };
|
||||
return _rest.Post<Responses.SendMessage>(Endpoints.ChannelMessages(channelId), request);
|
||||
}
|
||||
public Task<Responses.EditMessage> EditMessage(string messageId, string channelId, string message, string[] mentions)
|
||||
|
||||
@@ -69,6 +69,8 @@ namespace Discord.Net.API
|
||||
public string[] Mentions;
|
||||
[JsonProperty(PropertyName = "nonce")]
|
||||
public string Nonce;
|
||||
[JsonProperty(PropertyName = "tts")]
|
||||
public bool IsTTS;
|
||||
}
|
||||
public sealed class EditMessage
|
||||
{
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Discord.Net.WebSockets
|
||||
|
||||
try
|
||||
{
|
||||
result = await _webSocket.ReceiveAsync(buffer, cancelToken).ConfigureAwait(false);
|
||||
result = await _webSocket.ReceiveAsync(buffer, cancelToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Win32Exception ex) when (ex.HResult == HR_TIMEOUT)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user