hermes-server/Requests/UpdateTTSFilter.cs
2024-12-27 22:28:22 +00:00

45 lines
1.5 KiB
C#

using HermesSocketLibrary.Requests.Messages;
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 ChannelManager _channels;
private ILogger _logger;
public UpdateTTSFilter(ChannelManager channels, ILogger logger)
{
_channels = channels;
_logger = logger;
}
public async Task<RequestResult> Grant(string sender, 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 = sender,
Search = search,
Replace = replace,
};
var channel = _channels.Get(sender);
bool result = channel.Filters.Set(id, filter);
if (result)
{
_logger.Information($"Updated filter to channel [filter id: {id}][search: {search}][replace: {replace}][channel: {sender}]");
return RequestResult.Successful(filter);
}
return RequestResult.Failed("Something went wrong when updating the cache.");
}
}
}