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:
@@ -1,4 +1,3 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketServer.Models;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
@@ -8,28 +7,26 @@ namespace HermesSocketServer.Requests
|
||||
{
|
||||
public string Name => "create_tts_user";
|
||||
public string[] RequiredKeys => ["chatter", "voice"];
|
||||
private Database _database;
|
||||
private readonly ServerConfiguration _configuration;
|
||||
private ILogger _logger;
|
||||
|
||||
public CreateTTSUser(Database database, ServerConfiguration configuration, ILogger logger)
|
||||
public CreateTTSUser(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("Invalid Twitch user id");
|
||||
return Task.FromResult(RequestResult.Failed("Invalid Twitch user id."));
|
||||
|
||||
data["user"] = channel.Id;
|
||||
data["voice"] = data["voice"].ToString()!;
|
||||
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 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 disabled on this channel."));
|
||||
|
||||
bool result = channel.Chatters.Set(chatterId.ToString(), new ChatterVoice()
|
||||
{
|
||||
@@ -40,10 +37,10 @@ namespace HermesSocketServer.Requests
|
||||
|
||||
if (result)
|
||||
{
|
||||
_logger.Information($"Selected a tts voice [voice: {data["voice"]}] for user [chatter: {data["chatter"]}] in channel [channel: {data["user"]}]");
|
||||
return RequestResult.Successful(null);
|
||||
_logger.Information($"Selected a tts voice [voice: {voiceId}] for user [chatter: {chatterId}] in channel [channel: {channel.Id}]");
|
||||
return Task.FromResult(RequestResult.Successful(null));
|
||||
}
|
||||
return RequestResult.Failed("Something went wrong when updating the cache.");
|
||||
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user