hermes-server/Requests/CreateTTSFilter.cs
2024-12-28 17:24:02 +00:00

41 lines
1.3 KiB
C#

using HermesSocketLibrary.Requests.Messages;
using HermesSocketServer.Models;
using ILogger = Serilog.ILogger;
namespace HermesSocketServer.Requests
{
public class CreateTTSFilter : IRequest
{
public string Name => "create_tts_filter";
public string[] RequiredKeys => ["search", "replace"];
private ILogger _logger;
public CreateTTSFilter(ILogger logger)
{
_logger = logger;
}
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
var id = Guid.NewGuid();
string search = data["search"].ToString()!;
string replace = data["replace"].ToString()!;
var filter = new TTSWordFilter()
{
Id = id.ToString(),
UserId = channel.Id,
Search = search,
Replace = replace,
};
bool result = channel.Filters.Set(id.ToString(), filter);
if (result)
{
_logger.Information($"Added filter to channel [filter id: {id}][search: {search}][replace: {replace}][channel: {channel.Id}]");
return Task.FromResult(RequestResult.Successful(filter));
}
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
}
}
}