using Serilog; namespace TwitchChatTTS.Hermes.Socket.Requests { public class CreateTTSUserAck : IRequestAck { public string Name => "create_tts_user"; private readonly User _user; private readonly ILogger _logger; public CreateTTSUserAck(User user, ILogger logger) { _user = user; _logger = logger; } public void Acknowledge(string requestId, string json, IDictionary? 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 [chatter id: {chatterId}]"); 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 [voice id: {voiceId}]"); return; } _user.VoicesSelected.Add(chatterId, voiceId); _logger.Information($"Created a new TTS user [user id: {userId}][voice id: {voiceId}][voice name: {voiceName}]."); } } }