using System.Text.Json; using HermesSocketLibrary.db; using HermesSocketLibrary.Requests.Messages; using ILogger = Serilog.ILogger; namespace HermesSocketServer.Requests { public class GetRedeemableActions : IRequest { public string Name => "get_redeemable_actions"; public string[] RequiredKeys => []; private readonly JsonSerializerOptions _options; private readonly Database _database; private readonly ILogger _logger; public GetRedeemableActions(JsonSerializerOptions options, Database database, ILogger logger) { _options = options; _database = database; _logger = logger; } public async Task Grant(string sender, IDictionary? data) { var temp = new Dictionary() { { "user", sender } }; var redemptions = new List(); string sql = $"SELECT name, type, data FROM \"Action\" WHERE \"userId\" = @user"; await _database.Execute(sql, temp, (r) => redemptions.Add(new RedeemableAction() { Name = r.GetString(0), Type = r.GetString(1), Data = JsonSerializer.Deserialize>(r.GetString(2), _options)! })); _logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {sender}]"); return RequestResult.Successful(redemptions, notifyClientsOnAccount: false); } } }