hermes-server/Requests/UpdateTTSFilter.cs

43 lines
1.4 KiB
C#

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