Added several request messages. Added redemptions. Added life TTS voice changes. A bunch of stuffs.
This commit is contained in:
@ -1,34 +0,0 @@
|
||||
// using System.Text.Json;
|
||||
// using HermesSocketLibrary.db;
|
||||
// using HermesSocketLibrary.Requests;
|
||||
|
||||
// namespace HermesSocketServer.Requests
|
||||
// {
|
||||
// public class BanTTSUser : IRequest
|
||||
// {
|
||||
// public string Name => "ban_tts_user";
|
||||
// private Database _database;
|
||||
// private ILogger _logger;
|
||||
|
||||
// public BanTTSUser(Database database, ILogger logger)
|
||||
// {
|
||||
// _database = database;
|
||||
// _logger = logger;
|
||||
// }
|
||||
|
||||
// public async Task<RequestResult> Grant(IDictionary<string, object> data)
|
||||
// {
|
||||
// // if (long.TryParse(data["user"].ToString(), out long user))
|
||||
// // data["user"] = user;
|
||||
// // if (data["broadcaster"] is JsonElement b)
|
||||
// // data["broadcaster"] = b.ToString();
|
||||
// // if (data["voice"] is JsonElement v)
|
||||
// // data["voice"] = v.ToString();
|
||||
|
||||
// // string sql = "UPDATE \"TtsChatVoice\" (\"broadcasterId\", \"chatterId\", \"ttsVoiceId\") VALUES (@broadcaster, @user, @voice)";
|
||||
// // var result = await _database.Execute(sql, data);
|
||||
// // _logger.Information($"Selected a tts voice for {data["user"]} in channel {data["broadcaster"]}: {data["voice"]}");
|
||||
// return new RequestResult(1 == 1, null);
|
||||
// }
|
||||
// }
|
||||
// }
|
@ -17,8 +17,14 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Data received from request is null. Ignoring it.");
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
if (long.TryParse(data["chatter"].ToString(), out long chatter))
|
||||
data["chatter"] = chatter;
|
||||
if (data["voice"] is JsonElement v)
|
||||
@ -26,13 +32,12 @@ namespace HermesSocketServer.Requests
|
||||
data["user"] = sender;
|
||||
|
||||
var check = await _database.ExecuteScalar("SELECT state FROM \"TtsVoiceState\" WHERE \"userId\" = @user AND \"ttsVoiceId\" = @voice", data) ?? false;
|
||||
if (check is not bool state || !state){
|
||||
if (check is not bool state || !state)
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
|
||||
string sql = "INSERT INTO \"TtsChatVoice\" (\"userId\", \"chatterId\", \"ttsVoiceId\") VALUES (@user, @chatter, @voice)";
|
||||
var result = await _database.Execute(sql, data);
|
||||
_logger.Information($"Selected a tts voice for {data["chatter"]} in channel {data["user"]}: {data["voice"]}");
|
||||
_logger.Information($"Selected a tts voice [voice: {data["voice"]}] for user [chatter: {data["chatter"]}] in channel [channel: {data["user"]}]");
|
||||
return new RequestResult(result == 1, null);
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,14 @@ namespace HermesSocketServer.Requests
|
||||
}
|
||||
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Data received from request is null. Ignoring it.");
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
string id = RandomString(25);
|
||||
data.Add("idd", id);
|
||||
|
||||
@ -30,7 +36,7 @@ namespace HermesSocketServer.Requests
|
||||
|
||||
string sql = "INSERT INTO \"TtsVoice\" (id, name) VALUES (@idd, @voice)";
|
||||
var result = await _database.Execute(sql, data);
|
||||
_logger.Information($"Added a new voice: {data["voice"]} (id: {data["idd"]})");
|
||||
_logger.Information($"Added a new voice [voice: {data["voice"]}][voice id: {data["idd"]}]");
|
||||
|
||||
data.Remove("idd");
|
||||
return new RequestResult(result == 1, id);
|
||||
|
@ -17,14 +17,20 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Data received from request is null. Ignoring it.");
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
if (data["voice"] is JsonElement v)
|
||||
data["voice"] = v.ToString();
|
||||
|
||||
string sql = "DELETE FROM \"TtsVoice\" WHERE id = @voice";
|
||||
var result = await _database.Execute(sql, data);
|
||||
_logger.Information($"Deleted a voice by id: {data["voice"]}");
|
||||
_logger.Information($"Deleted a voice by id [voice id: {data["voice"]}]");
|
||||
return new RequestResult(result == 1, null);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using ILogger = Serilog.ILogger;
|
||||
@ -17,12 +16,12 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
IList<long> ids = new List<long>();
|
||||
string sql = $"SELECT id FROM \"Chatter\"";
|
||||
await _database.Execute(sql, data, (r) => ids.Add(r.GetInt64(0)));
|
||||
_logger.Information($"Fetched all chatters.");
|
||||
await _database.Execute(sql, (IDictionary<string, object>?) null, (r) => ids.Add(r.GetInt64(0)));
|
||||
_logger.Information($"Fetched all chatters for channel [channel: {sender}]");
|
||||
return new RequestResult(true, ids, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
|
29
Requests/GetDefaultTTSVoice.cs
Normal file
29
Requests/GetDefaultTTSVoice.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class GetDefaultTTSVoice : IRequest
|
||||
{
|
||||
public string Name => "get_default_tts_voice";
|
||||
private Database _database;
|
||||
private ILogger _logger;
|
||||
|
||||
public GetDefaultTTSVoice(Database database, ILogger logger)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
string sql = $"SELECT \"ttsDefaultVoice\" FROM \"User\" WHERE id = @user";
|
||||
string? value = (string?)await _database.ExecuteScalar(sql, temp);
|
||||
_logger.Information($"Fetched the default TTS voice for channel [channel: {sender}]");
|
||||
return new RequestResult(true, value, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
}
|
@ -18,16 +18,16 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
IList<EmoteInfo> emotes = new List<EmoteInfo>();
|
||||
string sql = $"SELECT id, name FROM \"Emote\"";
|
||||
await _database.Execute(sql, data, (r) => emotes.Add(new EmoteInfo()
|
||||
await _database.Execute(sql, (IDictionary<string, object>?) null, (r) => emotes.Add(new EmoteInfo()
|
||||
{
|
||||
Id = r.GetString(0),
|
||||
Name = r.GetString(1)
|
||||
}));
|
||||
_logger.Information($"Fetched all emotes.");
|
||||
_logger.Information($"Fetched all emotes for channel [channel: {sender}]");
|
||||
return new RequestResult(true, emotes, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
|
33
Requests/GetEnabledTTSVoices.cs
Normal file
33
Requests/GetEnabledTTSVoices.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class GetEnabledTTSVoices : IRequest
|
||||
{
|
||||
public string Name => "get_enabled_tts_voices";
|
||||
|
||||
private readonly Database _database;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GetEnabledTTSVoices(Database database, ILogger logger)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
var voices = new List<string>();
|
||||
string sql = $"SELECT v.name FROM \"TtsVoiceState\" s "
|
||||
+ "INNER JOIN \"TtsVoice\" v ON s.\"ttsVoiceId\" = v.id "
|
||||
+ "WHERE \"userId\" = @user AND state = true";
|
||||
await _database.Execute(sql, temp, (r) => voices.Add(r.GetString(0)));
|
||||
_logger.Information($"Fetched all enabled TTS voice for channel [channel: {sender}]");
|
||||
return new RequestResult(true, voices, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
}
|
62
Requests/GetPermissions.cs
Normal file
62
Requests/GetPermissions.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class GetPermissions : IRequest
|
||||
{
|
||||
public string Name => "get_permissions";
|
||||
|
||||
private readonly Database _database;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GetPermissions(Database database, ILogger logger)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
var groups = new List<Group>();
|
||||
string sql = $"SELECT id, name, priority FROM \"Group\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, temp, (r) => groups.Add(new Group()
|
||||
{
|
||||
Id = r.GetGuid(0).ToString("D"),
|
||||
Name = r.GetString(1),
|
||||
Priority = r.GetInt32(2)
|
||||
}));
|
||||
|
||||
var groupChatters = new List<GroupChatter>();
|
||||
sql = $"SELECT \"groupId\", \"chatterId\", \"chatterId\" FROM \"ChatterGroup\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, temp, (r) => groupChatters.Add(new GroupChatter()
|
||||
{
|
||||
GroupId = r.GetGuid(0).ToString("D"),
|
||||
ChatterId = r.GetInt32(1)
|
||||
}));
|
||||
|
||||
var groupPermissions = new List<GroupPermission>();
|
||||
sql = $"SELECT id, \"groupId\", \"path\", \"allow\" FROM \"GroupPermission\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, temp, (r) => groupPermissions.Add(new GroupPermission()
|
||||
{
|
||||
Id = r.GetGuid(0).ToString("D"),
|
||||
GroupId = r.GetGuid(1).ToString("D"),
|
||||
Path = r.GetString(2),
|
||||
Allow = r.GetBoolean(3)
|
||||
}));
|
||||
_logger.Information($"Fetched all redemptions for channel [channel: {sender}]");
|
||||
|
||||
var info = new GroupInfo()
|
||||
{
|
||||
Groups = groups,
|
||||
GroupChatters = groupChatters,
|
||||
GroupPermissions = groupPermissions
|
||||
};
|
||||
return new RequestResult(true, info, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
}
|
40
Requests/GetRedeemableActions.cs
Normal file
40
Requests/GetRedeemableActions.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class GetRedeemableActions : IRequest
|
||||
{
|
||||
public string Name => "get_redeemable_actions";
|
||||
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly Database _database;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GetRedeemableActions(JsonSerializerOptions options, Database database, ILogger logger)
|
||||
{
|
||||
_options = options;
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
var redemptions = new List<RedeemableAction>();
|
||||
string sql = $"SELECT name, type, data FROM \"Action\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, temp, (r) => redemptions.Add(new RedeemableAction()
|
||||
{
|
||||
Name = r.GetString(0),
|
||||
Type = r.GetString(1),
|
||||
Data = JsonSerializer.Deserialize<IDictionary<string, string>>(r.GetString(2), _options)!
|
||||
}));
|
||||
_logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {sender}]");
|
||||
return new RequestResult(true, redemptions, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
}
|
39
Requests/GetRedemptions.cs
Normal file
39
Requests/GetRedemptions.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class GetRedemptions : IRequest
|
||||
{
|
||||
public string Name => "get_redemptions";
|
||||
|
||||
private readonly Database _database;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GetRedemptions(Database database, ILogger logger)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
var redemptions = new List<Redemption>();
|
||||
string sql = $"SELECT id, \"redemptionId\", \"actionName\", \"order\", state FROM \"Redemption\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, temp, (r) => redemptions.Add(new Redemption()
|
||||
{
|
||||
Id = r.GetGuid(0).ToString("D"),
|
||||
RedemptionId = r.GetString(1),
|
||||
ActionName = r.GetString(2),
|
||||
Order = r.GetInt32(3),
|
||||
State = r.GetBoolean(4)
|
||||
}));
|
||||
_logger.Information($"Fetched all redemptions for channel [channel: {sender}]");
|
||||
return new RequestResult(true, redemptions, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using ILogger = Serilog.ILogger;
|
||||
@ -17,14 +16,14 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
data["user"] = sender;
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
IDictionary<long, string> users = new Dictionary<long, string>();
|
||||
string sql = $"SELECT \"ttsVoiceId\", \"chatterId\" FROM \"TtsChatVoice\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, data, (r) => users.Add(r.GetInt64(1), r.GetString(0)));
|
||||
_logger.Information($"Fetched all chatters' selected tts voice for channel {data["user"]}.");
|
||||
await _database.Execute(sql, temp, (r) => users.Add(r.GetInt64(1), r.GetString(0)));
|
||||
_logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {sender}]");
|
||||
return new RequestResult(true, users, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
|
@ -17,16 +17,16 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
IList<VoiceDetails> voices = new List<VoiceDetails>();
|
||||
string sql = "SELECT id, name FROM \"TtsVoice\"";
|
||||
await _database.Execute(sql, data, (r) => voices.Add(new VoiceDetails()
|
||||
await _database.Execute(sql, (IDictionary<string, object>?) null, (r) => voices.Add(new VoiceDetails()
|
||||
{
|
||||
Id = r.GetString(0),
|
||||
Name = r.GetString(1)
|
||||
}));
|
||||
_logger.Information("Fetched all TTS voices.");
|
||||
_logger.Information($"Fetched all TTS voices for channel [channel: {sender}]");
|
||||
return new RequestResult(true, voices, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
@ -18,18 +18,19 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
data["user"] = sender;
|
||||
var temp = new Dictionary<string, object>() { { "user", sender } };
|
||||
|
||||
IList<TTSWordFilter> filters = new List<TTSWordFilter>();
|
||||
string sql = $"SELECT id, search, replace FROM \"TtsWordFilter\" WHERE \"userId\" = @user";
|
||||
await _database.Execute(sql, data, (r) => filters.Add(new TTSWordFilter()
|
||||
await _database.Execute(sql, temp, (r) => filters.Add(new TTSWordFilter()
|
||||
{
|
||||
Id = r.GetString(0),
|
||||
Search = r.GetString(1),
|
||||
Replace = r.GetString(2)
|
||||
}));
|
||||
_logger.Information($"Fetched all word filters for channel [channel: {sender}]");
|
||||
return new RequestResult(true, filters, notifyClientsOnAccount: false);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
using HermesSocketLibrary.Requests;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer
|
||||
{
|
||||
public class ServerRequestManager : RequestManager
|
||||
{
|
||||
public ServerRequestManager(IServiceProvider serviceProvider, ILogger logger) : base(serviceProvider, logger)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string AssemblyName => "SocketServer";
|
||||
}
|
||||
}
|
36
Requests/UpdateDefaultTTSVoice.cs
Normal file
36
Requests/UpdateDefaultTTSVoice.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using HermesSocketLibrary.db;
|
||||
using HermesSocketLibrary.Requests;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace HermesSocketServer.Requests
|
||||
{
|
||||
public class UpdateDefaultTTSVoice : IRequest
|
||||
{
|
||||
public string Name => "update_default_tts_voice";
|
||||
private Database _database;
|
||||
private ILogger _logger;
|
||||
|
||||
public UpdateDefaultTTSVoice(Database database, ILogger logger)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Data received from request is null. Ignoring it.");
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
data["user"] = data["user"].ToString();
|
||||
data["voice"] = data["voice"].ToString();
|
||||
|
||||
string sql = $"UPDATE \"User\" SET ttsDefaultVoice = @voice WHERE id = @user";
|
||||
await _database.Execute(sql, data);
|
||||
_logger.Information($"Updated default TTS voice for channel [channel: {sender}][voice: {data["voice"]}]");
|
||||
return new RequestResult(true, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,17 +8,26 @@ namespace HermesSocketServer.Requests
|
||||
public class UpdateTTSUser : IRequest
|
||||
{
|
||||
public string Name => "update_tts_user";
|
||||
|
||||
private readonly ServerConfiguration _configuration;
|
||||
private readonly Database _database;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public UpdateTTSUser(Database database, ILogger logger)
|
||||
public UpdateTTSUser(ServerConfiguration configuration, Database database, ILogger logger)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Data received from request is null. Ignoring it.");
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
if (long.TryParse(data["chatter"].ToString(), out long chatterId))
|
||||
data["chatter"] = chatterId;
|
||||
if (data["voice"] is JsonElement v)
|
||||
@ -26,14 +35,14 @@ namespace HermesSocketServer.Requests
|
||||
data["user"] = sender;
|
||||
|
||||
var check = await _database.ExecuteScalar("SELECT state FROM \"TtsVoiceState\" WHERE \"userId\" = @user AND \"ttsVoiceId\" = @voice", data) ?? false;
|
||||
if (check is not bool state || !state)
|
||||
if ((check is not bool state || !state) && chatterId != _configuration.OwnerId)
|
||||
{
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
string sql = "UPDATE \"TtsChatVoice\" SET \"ttsVoiceId\" = @voice WHERE \"userId\" = @user AND \"chatterId\" = @chatter";
|
||||
var result = await _database.Execute(sql, data);
|
||||
_logger.Information($"Updated {data["chatter"]}'s selected tts voice to {data["voice"]} in channel {data["user"]}.");
|
||||
_logger.Information($"Updated chatter's [chatter: {data["chatter"]}] selected tts voice [voice: {data["voice"]}] in channel [channel: {sender}]");
|
||||
return new RequestResult(result == 1, null);
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,14 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Data received from request is null. Ignoring it.");
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
if (data["voice"] is JsonElement v)
|
||||
data["voice"] = v.ToString();
|
||||
if (data["voiceid"] is JsonElement id)
|
||||
@ -26,7 +32,7 @@ namespace HermesSocketServer.Requests
|
||||
|
||||
string sql = "UPDATE \"TtsVoice\" SET name = @voice WHERE id = @voiceid";
|
||||
var result = await _database.Execute(sql, data);
|
||||
_logger.Information($"Updated voice {data["voiceid"]}'s name to {data["voice"]}.");
|
||||
_logger.Information($"Updated voice's [voice id: {data["voiceid"]}] name [new name: {data["voice"]}]");
|
||||
return new RequestResult(result == 1, null);
|
||||
}
|
||||
}
|
||||
|
@ -17,18 +17,23 @@ namespace HermesSocketServer.Requests
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object> data)
|
||||
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Data received from request is null. Ignoring it.");
|
||||
return new RequestResult(false, null);
|
||||
}
|
||||
|
||||
if (data["voice"] is JsonElement voice)
|
||||
data["voice"] = voice.ToString();
|
||||
if (data["state"] is JsonElement state)
|
||||
data["state"] = state.ToString() == "True";
|
||||
data["user"] = sender;
|
||||
|
||||
//string sql = "UPDATE \"TtsVoiceState\" SET state = @state WHERE \"userId\" = @user AND \"ttsVoiceId\" = @voice";
|
||||
string sql = "INSERT INTO \"TtsVoiceState\" (\"userId\", \"ttsVoiceId\", state) VALUES (@user, @voice, @state) ON CONFLICT (\"userId\", \"ttsVoiceId\") DO UPDATE SET state = @state";
|
||||
var result = await _database.Execute(sql, data);
|
||||
_logger.Information($"Updated voice {data["voice"]}'s state (from {data["user"]}) to {data["state"]}.");
|
||||
_logger.Information($"Updated voice's [voice id: {data["voice"]}] state [new state: {data["state"]}][channel: {data["user"]}]");
|
||||
return new RequestResult(result == 1, null);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user