Added database table data into configuration. Store saves is auto-handled. Added Action & Redemption stores.
This commit is contained in:
53
Store/ActionStore.cs
Normal file
53
Store/ActionStore.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user