45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using HermesSocketLibrary.Requests.Messages;
|
|
using HermesSocketServer.Services;
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
namespace HermesSocketServer.Requests
|
|
{
|
|
public class CreateTTSFilter : IRequest
|
|
{
|
|
public string Name => "create_tts_filter";
|
|
public string[] RequiredKeys => ["search", "replace"];
|
|
private ChannelManager _channels;
|
|
private ILogger _logger;
|
|
|
|
public CreateTTSFilter(ChannelManager channels, ILogger logger)
|
|
{
|
|
_channels = channels;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<RequestResult> Grant(string sender, 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 = sender,
|
|
Search = search,
|
|
Replace = replace,
|
|
};
|
|
|
|
var channel = _channels.Get(sender);
|
|
bool result = channel.Filters.Set(id.ToString(), filter);
|
|
|
|
if (result)
|
|
{
|
|
_logger.Information($"Added 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.");
|
|
}
|
|
}
|
|
} |