hermes-server/Requests/GetRedeemableActions.cs

40 lines
1.6 KiB
C#
Raw Normal View History

using System.Text.Json;
using HermesSocketLibrary.db;
using HermesSocketLibrary.Requests.Messages;
2024-12-27 23:31:36 +00:00
using HermesSocketServer.Models;
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;
}
2024-12-27 23:31:36 +00:00
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
2024-12-27 23:31:36 +00:00
var temp = new Dictionary<string, object>() { { "user", channel.Id } };
var redemptions = new List<RedeemableAction>();
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<IDictionary<string, string>>(r.GetString(2), _options)!
}));
2024-12-27 23:31:36 +00:00
_logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {channel.Id}]");
return RequestResult.Successful(redemptions, notifyClientsOnAccount: false);
}
}
}