hermes-server/Requests/CreateTTSFilter.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2024-12-27 22:28:22 +00:00
using HermesSocketLibrary.Requests.Messages;
2024-12-27 23:31:36 +00:00
using HermesSocketServer.Models;
2024-12-27 22:28:22 +00:00
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;
2024-12-27 23:31:36 +00:00
public CreateTTSFilter(ILogger logger)
2024-12-27 22:28:22 +00:00
{
_logger = logger;
}
2024-12-27 23:31:36 +00:00
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
2024-12-27 22:28:22 +00:00
{
var id = Guid.NewGuid();
string search = data["search"].ToString()!;
string replace = data["replace"].ToString()!;
var filter = new TTSWordFilter()
{
Id = id.ToString(),
2024-12-27 23:31:36 +00:00
UserId = channel.Id,
2024-12-27 22:28:22 +00:00
Search = search,
Replace = replace,
};
bool result = channel.Filters.Set(id.ToString(), filter);
if (result)
{
2024-12-27 23:31:36 +00:00
_logger.Information($"Added filter to channel [filter id: {id}][search: {search}][replace: {replace}][channel: {channel.Id}]");
2024-12-27 22:28:22 +00:00
return RequestResult.Successful(filter);
}
return RequestResult.Failed("Something went wrong when updating the cache.");
}
}
}