hermes-client/Hermes/Socket/Requests/UpdateTTSUserAck.cs

58 lines
1.8 KiB
C#

using Serilog;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class UpdateTTSUserAck : IRequestAck
{
public string Name => "update_tts_user";
private readonly User _user;
private readonly ILogger _logger;
public UpdateTTSUserAck(User user, ILogger logger)
{
_user = user;
_logger = logger;
}
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
{
if (requestData == null)
{
_logger.Warning("Request data is null.");
return;
}
if (!long.TryParse(requestData["chatter"].ToString(), out long chatterId))
{
_logger.Warning($"Failed to parse chatter id [chatter id: {requestData["chatter"]}]");
return;
}
if (chatterId <= 0)
{
_logger.Warning("Chatter Id is invalid.");
return;
}
var userId = requestData["user"].ToString();
var voiceId = requestData["voice"].ToString();
if (string.IsNullOrEmpty(userId))
{
_logger.Warning("User Id is invalid.");
return;
}
if (string.IsNullOrEmpty(voiceId))
{
_logger.Warning("Voice Id is invalid.");
return;
}
if (!_user.VoicesAvailable.TryGetValue(voiceId, out var voiceName))
{
_logger.Warning("Voice Id does not exist.");
return;
}
_user.VoicesSelected[chatterId] = voiceId;
_logger.Information($"Updated a TTS user's voice [user id: {userId}][voice: {voiceId}][voice name: {voiceName}]");
}
}
}