Added stores for connections. Added requests for groups, group chatters, group permissions & connections. Using TTS Voice State store.

This commit is contained in:
Tom
2025-01-17 04:32:31 +00:00
parent 422cd91db2
commit 6d955f245a
29 changed files with 759 additions and 67 deletions

View File

@@ -23,25 +23,27 @@ namespace HermesSocketServer.Requests
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
if (long.TryParse(data["chatter"].ToString(), out long chatterId))
data["chatter"] = chatterId;
data["voice"] = data["voice"].ToString()!;
data["user"] = channel.Id;
if (!long.TryParse(data["chatter"].ToString(), out long chatterId))
return RequestResult.Failed("Chatter should be an integer, representing the Twitch User Id of the chatter.");
var voiceId = 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 either non-existent or disabled on this channel.");
var result = channel.Chatters.Set(chatterId.ToString(), new ChatterVoice()
var voice = new ChatterVoice()
{
UserId = channel.Id,
ChatterId = chatterId,
VoiceId = data["voice"].ToString()!
});
VoiceId = voiceId
};
var result = channel.Chatters.Modify(chatterId.ToString(), voice);
if (result)
{
_logger.Information($"Updated chatter's [chatter: {data["chatter"]}] selected tts voice [voice: {data["voice"]}] in channel [channel: {channel.Id}]");
return RequestResult.Successful(null);
_logger.Information($"Updated chatter's selected tts voice on channel [chatter id: {chatterId}][voice id: {voiceId}][channel: {channel.Id}]");
return RequestResult.Successful(voice);
}
return RequestResult.Failed("Soemthing went wrong when updating the cache.");
}