Added database table data into configuration. Store saves is auto-handled. Added Action & Redemption stores.
This commit is contained in:
55
Store/VoiceStateStore.cs
Normal file
55
Store/VoiceStateStore.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using HermesSocketServer.Store.Internal;
|
||||
using HermesSocketServer.Validators;
|
||||
|
||||
namespace HermesSocketServer.Store
|
||||
{
|
||||
public class VoiceStateStore : AutoSavedStore<string, TTSVoiceState>
|
||||
{
|
||||
private readonly string _userId;
|
||||
private readonly VoiceIdValidator _idValidator;
|
||||
private readonly Database _database;
|
||||
private readonly Serilog.ILogger _logger;
|
||||
|
||||
|
||||
public VoiceStateStore(string userId, VoiceIdValidator voiceIdValidator, DatabaseTable table, Database database, Serilog.ILogger logger)
|
||||
: base(table, database, logger)
|
||||
{
|
||||
_userId = userId;
|
||||
_idValidator = voiceIdValidator;
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override async Task Load()
|
||||
{
|
||||
var data = new Dictionary<string, object>() { { "user", _userId } };
|
||||
string sql = "SELECT \"ttsVoiceId\", state FROM \"TtsVoiceState\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, data, (reader) =>
|
||||
{
|
||||
string id = reader.GetString(0);
|
||||
_store.Add(id, new TTSVoiceState()
|
||||
{
|
||||
Id = id,
|
||||
Enabled = reader.GetBoolean(1),
|
||||
UserId = _userId,
|
||||
});
|
||||
});
|
||||
_logger.Information($"Loaded {_store.Count} TTS voice states from database.");
|
||||
}
|
||||
|
||||
protected override void OnInitialAdd(string key, TTSVoiceState value)
|
||||
{
|
||||
_idValidator.Check(value.Id);
|
||||
}
|
||||
|
||||
protected override void OnInitialModify(string key, TTSVoiceState value)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnInitialRemove(string key)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user