53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
|
using System.Text.Json;
|
||
|
using HermesSocketLibrary.db;
|
||
|
using HermesSocketLibrary.Requests.Messages;
|
||
|
using HermesSocketServer.Store.Internal;
|
||
|
|
||
|
namespace HermesSocketServer.Store
|
||
|
{
|
||
|
public class ActionStore : AutoSavedStore<string, RedeemableAction>
|
||
|
{
|
||
|
private readonly string _userId;
|
||
|
private readonly Database _database;
|
||
|
private readonly Serilog.ILogger _logger;
|
||
|
|
||
|
|
||
|
public ActionStore(string userId, DatabaseTable table, Database database, Serilog.ILogger logger)
|
||
|
: base(table, database, logger)
|
||
|
{
|
||
|
_userId = userId;
|
||
|
_database = database;
|
||
|
_logger = logger;
|
||
|
}
|
||
|
|
||
|
public override async Task Load()
|
||
|
{
|
||
|
var data = new Dictionary<string, object>() { { "user", _userId } };
|
||
|
string sql = $"SELECT name, type, data FROM \"Action\" WHERE \"userId\" = @user";
|
||
|
await _database.Execute(sql, data, (reader) =>
|
||
|
{
|
||
|
var name = reader.GetString(0);
|
||
|
_store.Add(name.ToString(), new RedeemableAction()
|
||
|
{
|
||
|
UserId = _userId,
|
||
|
Name = name,
|
||
|
Type = reader.GetString(1),
|
||
|
Data = JsonSerializer.Deserialize<IDictionary<string, string>>(reader.GetString(2))!
|
||
|
});
|
||
|
});
|
||
|
_logger.Information($"Loaded {_store.Count} TTS chatter voices from database.");
|
||
|
}
|
||
|
|
||
|
protected override void OnInitialAdd(string key, RedeemableAction value)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
protected override void OnInitialModify(string key, RedeemableAction value)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
protected override void OnInitialRemove(string key)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|