Added checks for non-user foreign keys in stores. Load/Saving stores' order is now based on table dependencies. Added ability to use chat message when using redemption.

This commit is contained in:
Tom
2025-01-28 19:12:14 +00:00
parent 6d955f245a
commit 3e717522c2
18 changed files with 146 additions and 102 deletions

View File

@ -8,7 +8,7 @@ namespace HermesSocketServer.Requests
public class CreateRedeemableAction : IRequest
{
public string Name => "create_redeemable_action";
public string[] RequiredKeys => ["name", "data", "type"];
public string[] RequiredKeys => ["name", "has_message", "type", "data"];
private ILogger _logger;
public CreateRedeemableAction(ILogger logger)
@ -19,8 +19,9 @@ namespace HermesSocketServer.Requests
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
string name = data["name"].ToString()!;
string d = data["data"].ToString()!;
string type = data["type"].ToString()!;
bool hasMessage = data["has_message"].ToString()!.ToLower() == "true";
string d = data["data"].ToString()!;
IDictionary<string, string> dict = new Dictionary<string, string>();
try
@ -29,7 +30,7 @@ namespace HermesSocketServer.Requests
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to parse data on redeemable action while creating action [name: {name}][type: {type}][data: {d}]");
_logger.Error(ex, $"Failed to parse data on redeemable action while creating action [name: {name}][type: {type}][has message: {hasMessage}][data: {d}]");
return Task.FromResult(RequestResult.Failed("Could not parse the data on this action."));
}
@ -37,14 +38,15 @@ namespace HermesSocketServer.Requests
{
UserId = channel.Id,
Name = name,
Data = dict,
Type = type,
HasMessage = hasMessage,
Data = dict,
};
bool result = channel.Actions.Set(name, action);
if (result)
{
_logger.Information($"Added redeemable action to channel [name: {name}][type: {type}][channel: {channel.Id}]");
_logger.Information($"Added redeemable action to channel [name: {name}][type: {type}][has message: {hasMessage}][channel: {channel.Id}]");
return Task.FromResult(RequestResult.Successful(action));
}
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));