Updated Default TTS requests to use stores. Added a modify method for grouped save stores.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using HermesSocketServer.Store;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
@@ -7,23 +7,24 @@ namespace HermesSocketServer.Requests
|
||||
public class GetDefaultTTSVoice : IRequest
|
||||
{
|
||||
public string Name => "get_default_tts_voice";
|
||||
private Database _database;
|
||||
private ILogger _logger;
|
||||
private readonly UserStore _users;
|
||||
private readonly ServerConfiguration _configuration;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GetDefaultTTSVoice(Database database, ILogger logger)
|
||||
public GetDefaultTTSVoice(UserStore users, ServerConfiguration configuration, ILogger logger)
|
||||
{
|
||||
_database = database;
|
||||
_users = users;
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
string sql = $"SELECT \"ttsDefaultVoice\" FROM \"User\" WHERE id = @user";
|
||||
string? value = (string?)await _database.ExecuteScalar(sql, temp);
|
||||
_logger.Information($"Fetched the default TTS voice for channel [channel: {sender}]");
|
||||
return new RequestResult(true, value, notifyClientsOnAccount: false);
|
||||
var user = _users.Get(sender);
|
||||
if (user == null)
|
||||
return new RequestResult(false, "Unable to find user data.", notifyClientsOnAccount: false);
|
||||
|
||||
return new RequestResult(true, user.DefaultVoice ?? _configuration.Tts.DefaultTtsVoice, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user