Moved Requests classes to here. Added some checks to requests.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using HermesSocketLibrary.Requests;
|
||||
using HermesSocketServer.Store;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
@@ -7,6 +6,7 @@ namespace HermesSocketServer.Requests
|
||||
public class UpdateDefaultTTSVoice : IRequest
|
||||
{
|
||||
public string Name => "update_default_tts_voice";
|
||||
public string[] RequiredKeys => ["user", "voice"];
|
||||
private UserStore _users;
|
||||
private ILogger _logger;
|
||||
|
||||
@@ -18,21 +18,15 @@ namespace HermesSocketServer.Requests
|
||||
|
||||
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();
|
||||
|
||||
var success = _users.Modify(data["user"].ToString(), (user) => user.DefaultVoice = data["voice"].ToString()!);
|
||||
if (!success)
|
||||
return new RequestResult(false, "Unable to find user data.", notifyClientsOnAccount: false);
|
||||
return RequestResult.Failed("Unable to find user data.", notifyClientsOnAccount: false);
|
||||
|
||||
_logger.Information($"Updated default TTS voice for channel [channel: {sender}][voice: {data["voice"]}]");
|
||||
return new RequestResult(true, null);
|
||||
return RequestResult.Successful(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user