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

@@ -1,4 +1,5 @@
using HermesSocketLibrary.db;
using HermesSocketLibrary.Requests.Messages;
using HermesSocketServer.Models;
using ILogger = Serilog.ILogger;
@@ -17,18 +18,25 @@ namespace HermesSocketServer.Requests
_logger = logger;
}
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
data["voice"] = data["voice"].ToString()!;
data["state"] = data["state"].ToString() == "True";
data["user"] = channel.Id;
var id = data["voice"].ToString()!;
var state = data["state"].ToString() == "True";
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's [voice id: {data["voice"]}] state [new state: {data["state"]}][channel: {data["user"]}]");
if (result > 0)
return RequestResult.Successful(null);
return RequestResult.Failed("Something went wrong when updating the database.");
var voiceState = new TTSVoiceState()
{
Id = id,
UserId = channel.Id,
Enabled = state,
};
var result = channel.VoiceStates.Set(id, voiceState);
if (result)
{
_logger.Information($"Updated voice state on channel [voice id: {id}][state: {state}][channel: {channel.Id}]");
return Task.FromResult(RequestResult.Successful(voiceState));
}
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the database."));
}
}
}