hermes-server/Requests/UpdateTTSFilter.cs

45 lines
1.5 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 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;
}
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 = data["id"].ToString()!;
string search = data["search"].ToString()!;
string replace = data["replace"].ToString()!;
var filter = new TTSWordFilter()
{
Id = id,
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, filter);
if (result)
{
2024-12-27 23:31:36 +00:00
_logger.Information($"Updated 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.");
}
}
}