Added stores for connections. Added requests for groups, group chatters, group permissions & connections. Using TTS Voice State store.
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user