Fixed issues with TTS voice changes. Added proper handling for slave clients. Fixed several stores. Fixed database saving to safely save foreign keys.

This commit is contained in:
Tom
2025-03-06 16:11:36 +00:00
parent 3e717522c2
commit fd0bca5c7c
13 changed files with 139 additions and 96 deletions

View File

@@ -1,6 +1,4 @@
using HermesSocketLibrary.db;
using HermesSocketServer.Models;
using HermesSocketServer.Services;
using ILogger = Serilog.ILogger;
namespace HermesSocketServer.Requests
@@ -9,28 +7,27 @@ namespace HermesSocketServer.Requests
{
public string Name => "update_tts_user";
public string[] RequiredKeys => ["chatter", "voice"];
private Database _database;
private readonly ServerConfiguration _configuration;
private ILogger _logger;
public UpdateTTSUser(Database database, ServerConfiguration configuration, ILogger logger)
public UpdateTTSUser(ServerConfiguration configuration, ILogger logger)
{
_database = database;
_configuration = configuration;
_logger = logger;
}
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
if (!long.TryParse(data["chatter"].ToString(), out long chatterId))
return RequestResult.Failed("Chatter should be an integer, representing the Twitch User Id of the chatter.");
return Task.FromResult(RequestResult.Failed("Invalid Twitch user id."));
data["user"] = channel.Id;
var voiceId = data["voice"].ToString()!;
var check = await _database.ExecuteScalar("SELECT state FROM \"TtsVoiceState\" WHERE \"userId\" = @user AND \"ttsVoiceId\" = @voice", data) ?? false;
if ((check is not bool state || !state) && chatterId != _configuration.Tts.OwnerId)
return RequestResult.Failed("Voice is either non-existent or disabled on this channel.");
var check = channel.VoiceStates.Get(voiceId)?.Enabled ?? false;
if (!check && chatterId != _configuration.Tts.OwnerId)
return Task.FromResult(RequestResult.Failed("Voice is either non-existent or disabled on this channel."));
var voice = new ChatterVoice()
{
@@ -43,9 +40,9 @@ namespace HermesSocketServer.Requests
if (result)
{
_logger.Information($"Updated chatter's selected tts voice on channel [chatter id: {chatterId}][voice id: {voiceId}][channel: {channel.Id}]");
return RequestResult.Successful(voice);
return Task.FromResult(RequestResult.Successful(voice));
}
return RequestResult.Failed("Soemthing went wrong when updating the cache.");
return Task.FromResult(RequestResult.Failed("Soemthing went wrong when updating the cache."));
}
}
}