Changed sender parameter to channel.

This commit is contained in:
Tom
2024-12-27 23:31:36 +00:00
parent 06bfe110bb
commit 8277ea0154
27 changed files with 113 additions and 134 deletions

View File

@@ -1,6 +1,5 @@
using HermesSocketLibrary.db;
using HermesSocketServer.Models;
using HermesSocketServer.Services;
using ILogger = Serilog.ILogger;
namespace HermesSocketServer.Requests
@@ -9,37 +8,32 @@ namespace HermesSocketServer.Requests
{
public string Name => "create_tts_user";
public string[] RequiredKeys => ["chatter", "voice"];
private ChannelManager _channels;
private Database _database;
private readonly ServerConfiguration _configuration;
private ILogger _logger;
public CreateTTSUser(ChannelManager channels, Database database, ServerConfiguration configuration, ILogger logger)
public CreateTTSUser(Database database, ServerConfiguration configuration, ILogger logger)
{
_database = database;
_channels = channels;
_configuration = configuration;
_logger = logger;
}
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
if (data == null)
return RequestResult.Failed("Data received from client is null.");
if (!long.TryParse(data["chatter"].ToString(), out long chatterId))
return RequestResult.Failed("Invalid Twitch user id");
data["user"] = sender;
data["voice"] = data["voice"].ToString();
data["user"] = channel.Id;
data["voice"] = data["voice"].ToString()!;
var check = await _database.ExecuteScalar("SELECT state FROM \"TtsVoiceState\" WHERE \"userId\" = @user AND \"ttsVoiceId\" = @voice", data) ?? false;
if ((check is not bool state || !state) && chatterId != _configuration.Tts.OwnerId)
return RequestResult.Failed("Voice is disabled on this channel.");
var channel = _channels.Get(sender);
bool result = channel.Chatters.Set(chatterId.ToString(), new ChatterVoice()
{
UserId = sender,
UserId = channel.Id,
ChatterId = chatterId,
VoiceId = data["voice"].ToString()!
});