Cleaned up request acks. Added internal service bus for internal messaging.
This commit is contained in:
47
Hermes/Socket/Requests/CreateTTSVoiceAck.cs
Normal file
47
Hermes/Socket/Requests/CreateTTSVoiceAck.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Serilog;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class CreateTTSVoiceAck : IRequestAck
|
||||
{
|
||||
public string Name => "create_tts_voice";
|
||||
private readonly User _user;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public CreateTTSVoiceAck(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;
|
||||
}
|
||||
|
||||
var voice = requestData["voice"].ToString()!;
|
||||
var voiceId = json;
|
||||
if (string.IsNullOrEmpty(voice))
|
||||
{
|
||||
_logger.Warning("Voice name 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 already exists [voice id: {voiceId}][voice name: {voiceName}]");
|
||||
return;
|
||||
}
|
||||
|
||||
_user.VoicesAvailable.Add(voiceId, voice);
|
||||
_logger.Information($"Created a new tts voice [voice: {voice}][id: {voiceId}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user