2024-08-10 15:36:32 -04:00
|
|
|
using System.Text.RegularExpressions;
|
2024-06-24 18:21:59 -04:00
|
|
|
using HermesSocketLibrary.db;
|
|
|
|
using HermesSocketLibrary.Requests;
|
|
|
|
using HermesSocketLibrary.Requests.Messages;
|
|
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
|
|
|
|
namespace HermesSocketServer.Requests
|
|
|
|
{
|
|
|
|
public class GetTTSWordFilters : IRequest
|
|
|
|
{
|
|
|
|
public string Name => "get_tts_word_filters";
|
|
|
|
private readonly Database _database;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public GetTTSWordFilters(Database database, ILogger logger)
|
|
|
|
{
|
|
|
|
_database = database;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-08-10 15:36:32 -04:00
|
|
|
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
2024-06-24 18:21:59 -04:00
|
|
|
{
|
2024-08-10 15:36:32 -04:00
|
|
|
var temp = new Dictionary<string, object>() { { "user", sender } };
|
2024-06-24 18:21:59 -04:00
|
|
|
|
|
|
|
IList<TTSWordFilter> filters = new List<TTSWordFilter>();
|
|
|
|
string sql = $"SELECT id, search, replace FROM \"TtsWordFilter\" WHERE \"userId\" = @user";
|
2024-08-10 15:36:32 -04:00
|
|
|
await _database.Execute(sql, temp, (r) => filters.Add(new TTSWordFilter()
|
2024-06-24 18:21:59 -04:00
|
|
|
{
|
|
|
|
Id = r.GetString(0),
|
|
|
|
Search = r.GetString(1),
|
|
|
|
Replace = r.GetString(2)
|
|
|
|
}));
|
2024-08-10 15:36:32 -04:00
|
|
|
_logger.Information($"Fetched all word filters for channel [channel: {sender}]");
|
2024-06-24 18:21:59 -04:00
|
|
|
return new RequestResult(true, filters, notifyClientsOnAccount: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|