From 538bf074540eead6824505f08a893e38fbe5886d Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 28 Dec 2024 17:24:02 +0000 Subject: [PATCH] Fixed compiler warnings. --- Models/Channel.cs | 12 +++++++----- Models/ChatterVoice.cs | 4 ++-- Models/User.cs | 10 +++++----- Models/Voice.cs | 4 ++-- Quests/QuestManager.cs | 10 ++++++++-- Requests/CreatePolicy.cs | 6 +++--- Requests/CreateTTSFilter.cs | 6 +++--- Requests/CreateTTSVoice.cs | 6 +++--- Requests/DeletePolicy.cs | 8 ++++---- Requests/DeleteTTSFilter.cs | 4 ++-- Requests/DeleteTTSVoice.cs | 4 ++-- Requests/GetChatterIds.cs | 4 ++-- Requests/GetDefaultTTSVoice.cs | 6 +++--- Requests/GetPolicies.cs | 4 ++-- Requests/GetRedeemableActions.cs | 24 ++++-------------------- Requests/GetRedemptions.cs | 9 ++++----- Requests/GetTTSUsers.cs | 4 ++-- Requests/GetTTSVoices.cs | 4 ++-- Requests/GetTTSWordFilters.cs | 4 ++-- Requests/IRequest.cs | 2 +- Requests/RequestManager.cs | 4 ++-- Requests/UpdateDefaultTTSVoice.cs | 6 +++--- Requests/UpdatePolicy.cs | 6 +++--- Requests/UpdateTTSFilter.cs | 6 +++--- Requests/UpdateTTSVoice.cs | 6 +++--- Requests/UpdateTTSVoiceState.cs | 2 +- ServerConfiguration.cs | 18 +++++++++--------- Services/ChannelManager.cs | 19 +++++++++++++++---- Socket/Handlers/LoggingHandler.cs | 9 +++++---- Socket/WebSocketUser.cs | 2 +- 30 files changed, 108 insertions(+), 105 deletions(-) diff --git a/Models/Channel.cs b/Models/Channel.cs index dac297c..1313959 100644 --- a/Models/Channel.cs +++ b/Models/Channel.cs @@ -4,10 +4,12 @@ namespace HermesSocketServer.Models { public class Channel { - public string Id { get; set; } - public User User { get; set; } - public ChatterStore Chatters { get; set; } - public PolicyStore Policies { get; set; } - public TTSFilterStore Filters { get; set; } + public required string Id { get; set; } + public required User User { get; set; } + public required ChatterStore Chatters { get; set; } + public required PolicyStore Policies { get; set; } + public required TTSFilterStore Filters { get; set; } + public required ActionStore Actions { get; set; } + public required RedemptionStore Redemptions { get; set; } } } \ No newline at end of file diff --git a/Models/ChatterVoice.cs b/Models/ChatterVoice.cs index 82a993d..7adb76a 100644 --- a/Models/ChatterVoice.cs +++ b/Models/ChatterVoice.cs @@ -3,7 +3,7 @@ namespace HermesSocketServer.Models public class ChatterVoice { public long ChatterId { get; set; } - public string UserId { get; set; } - public string VoiceId { get; set; } + public required string UserId { get; set; } + public required string VoiceId { get; set; } } } \ No newline at end of file diff --git a/Models/User.cs b/Models/User.cs index 4eb3493..9696512 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -2,10 +2,10 @@ namespace HermesSocketServer.Models { public class User { - public string Id { get; set; } - public string Name { get; set; } - public string Email { get; set; } - public string Role { get; set; } - public string DefaultVoice { get; set; } + public required string Id { get; set; } + public required string Name { get; set; } + public required string Email { get; set; } + public required string Role { get; set; } + public required string DefaultVoice { get; set; } } } \ No newline at end of file diff --git a/Models/Voice.cs b/Models/Voice.cs index b364a73..66ee2c2 100644 --- a/Models/Voice.cs +++ b/Models/Voice.cs @@ -2,7 +2,7 @@ namespace HermesSocketServer.Models { public class Voice { - public string Id { get; set; } - public string Name { get; set; } + public required string Id { get; set; } + public required string Name { get; set; } } } \ No newline at end of file diff --git a/Quests/QuestManager.cs b/Quests/QuestManager.cs index 9f9a347..f886c53 100644 --- a/Quests/QuestManager.cs +++ b/Quests/QuestManager.cs @@ -51,12 +51,15 @@ namespace HermesSocketServer.Quests }); string sql2 = "SELECT id FROM \"Quest\" WHERE type = @type AND start = @start"; - int? questId = (int?)await _database.ExecuteScalar(sql, c => + int? questId = (int?)await _database.ExecuteScalar(sql2, c => { c.Parameters.AddWithValue("@type", temp.Type); c.Parameters.AddWithValue("@start", temp.StartTime); }); + if (questId == null) + return; + var quest = new DailyQuest((short)questId.Value, task, date); _quests.Add(quest.Id, quest); } @@ -88,12 +91,15 @@ namespace HermesSocketServer.Quests }); string sql2 = "SELECT id FROM \"Quest\" WHERE type = @type AND start = @start"; - int? questId = (int?)await _database.ExecuteScalar(sql, c => + int? questId = (int?)await _database.ExecuteScalar(sql2, c => { c.Parameters.AddWithValue("@type", temp.Type); c.Parameters.AddWithValue("@start", temp.StartTime); }); + if (questId == null) + return; + var quest = new WeeklyQuest((short)questId.Value, task, date); _quests.Add(quest.Id, quest); } diff --git a/Requests/CreatePolicy.cs b/Requests/CreatePolicy.cs index 631254b..3e31603 100644 --- a/Requests/CreatePolicy.cs +++ b/Requests/CreatePolicy.cs @@ -14,7 +14,7 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var id = Guid.NewGuid(); string groupId = data["groupId"].ToString()!; @@ -36,9 +36,9 @@ namespace HermesSocketServer.Requests if (result) { _logger.Information($"Added policy to channel [policy id: {id}][group id: {groupId}][path: {path}][count: {count}][span: {span}][channel: {channel.Id}]"); - return RequestResult.Successful(policy); + return Task.FromResult(RequestResult.Successful(policy)); } - return RequestResult.Failed("Something went wrong when updating the cache."); + return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache.")); } } } \ No newline at end of file diff --git a/Requests/CreateTTSFilter.cs b/Requests/CreateTTSFilter.cs index ee86dcf..14ab9a8 100644 --- a/Requests/CreateTTSFilter.cs +++ b/Requests/CreateTTSFilter.cs @@ -15,7 +15,7 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var id = Guid.NewGuid(); string search = data["search"].ToString()!; @@ -33,9 +33,9 @@ namespace HermesSocketServer.Requests if (result) { _logger.Information($"Added filter to channel [filter id: {id}][search: {search}][replace: {replace}][channel: {channel.Id}]"); - return RequestResult.Successful(filter); + return Task.FromResult(RequestResult.Successful(filter)); } - return RequestResult.Failed("Something went wrong when updating the cache."); + return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache.")); } } } \ No newline at end of file diff --git a/Requests/CreateTTSVoice.cs b/Requests/CreateTTSVoice.cs index f6c57f3..3c3d8f7 100644 --- a/Requests/CreateTTSVoice.cs +++ b/Requests/CreateTTSVoice.cs @@ -19,7 +19,7 @@ namespace HermesSocketServer.Requests _random = new Random(); } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { string voice = data["voice"].ToString()!; string id = RandomString(25); @@ -32,9 +32,9 @@ namespace HermesSocketServer.Requests if (result) { _logger.Information($"Added a new voice [voice: {voice}][voice id: {id}]"); - return RequestResult.Successful(id); + return Task.FromResult(RequestResult.Successful(id)); } - return RequestResult.Failed("Something went wrong when updating the cache."); + return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache.")); } private string RandomString(int length) diff --git a/Requests/DeletePolicy.cs b/Requests/DeletePolicy.cs index cf656ef..0a117b7 100644 --- a/Requests/DeletePolicy.cs +++ b/Requests/DeletePolicy.cs @@ -14,18 +14,18 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { string policyId = data["id"].ToString()!; var policy = channel.Policies.Get(policyId); if (policy != null) { channel.Policies.Remove(policyId); _logger.Information($"Deleted a policy by id [policy id: {data["id"]}]"); - return RequestResult.Successful(policy.GroupId + "/" + policy.Path); + return Task.FromResult(RequestResult.Successful(policy.GroupId + "/" + policy.Path)); } - _logger.Warning("Failed to find policy by id "); - return RequestResult.Failed("Cannot find the policy by id."); + _logger.Warning($"Failed to find policy by id [id: {policyId}]"); + return Task.FromResult(RequestResult.Failed("Cannot find the policy by id.")); } } } \ No newline at end of file diff --git a/Requests/DeleteTTSFilter.cs b/Requests/DeleteTTSFilter.cs index 528cc16..7ab5a0a 100644 --- a/Requests/DeleteTTSFilter.cs +++ b/Requests/DeleteTTSFilter.cs @@ -14,13 +14,13 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { string filterId = data["id"].ToString()!; channel.Filters.Remove(filterId); _logger.Information($"Deleted a TTS filter by id [tts filter id: {filterId}]"); - return RequestResult.Successful(null); + return Task.FromResult(RequestResult.Successful(null)); } } } \ No newline at end of file diff --git a/Requests/DeleteTTSVoice.cs b/Requests/DeleteTTSVoice.cs index dc8b600..dac030e 100644 --- a/Requests/DeleteTTSVoice.cs +++ b/Requests/DeleteTTSVoice.cs @@ -17,12 +17,12 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { string voiceId = data["voice"].ToString()!; _voices.Remove(voiceId); _logger.Information($"Deleted a voice by id [voice id: {voiceId}]"); - return RequestResult.Successful(null); + return Task.FromResult(RequestResult.Successful(null)); } } } \ No newline at end of file diff --git a/Requests/GetChatterIds.cs b/Requests/GetChatterIds.cs index 3178207..504e2b9 100644 --- a/Requests/GetChatterIds.cs +++ b/Requests/GetChatterIds.cs @@ -14,11 +14,11 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { IEnumerable ids = channel.Chatters.Get().Values.Select(c => c.ChatterId); _logger.Information($"Fetched all chatters for channel [channel: {channel.Id}]"); - return RequestResult.Successful(ids, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(ids, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/GetDefaultTTSVoice.cs b/Requests/GetDefaultTTSVoice.cs index d8f5733..b85de29 100644 --- a/Requests/GetDefaultTTSVoice.cs +++ b/Requests/GetDefaultTTSVoice.cs @@ -19,13 +19,13 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var user = _users.Get(channel.Id); if (user == null) - return RequestResult.Failed("Unable to find user data.", notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Failed("Unable to find user data.", notifyClientsOnAccount: false)); - return RequestResult.Successful(user.DefaultVoice ?? _configuration.Tts.DefaultTtsVoice, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(user.DefaultVoice ?? _configuration.Tts.DefaultTtsVoice, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/GetPolicies.cs b/Requests/GetPolicies.cs index 90209ad..7310b1e 100644 --- a/Requests/GetPolicies.cs +++ b/Requests/GetPolicies.cs @@ -14,12 +14,12 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var results = channel.Policies.Get().Values; _logger.Information($"Fetched policies for channel [policy size: {results.Count}][channel: {channel.Id}]"); - return RequestResult.Successful(results, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(results, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/GetRedeemableActions.cs b/Requests/GetRedeemableActions.cs index 788479a..c3aaf8c 100644 --- a/Requests/GetRedeemableActions.cs +++ b/Requests/GetRedeemableActions.cs @@ -1,6 +1,3 @@ -using System.Text.Json; -using HermesSocketLibrary.db; -using HermesSocketLibrary.Requests.Messages; using HermesSocketServer.Models; using ILogger = Serilog.ILogger; @@ -10,31 +7,18 @@ namespace HermesSocketServer.Requests { public string Name => "get_redeemable_actions"; public string[] RequiredKeys => []; - private readonly JsonSerializerOptions _options; - private readonly Database _database; private readonly ILogger _logger; - public GetRedeemableActions(JsonSerializerOptions options, Database database, ILogger logger) + public GetRedeemableActions(ILogger logger) { - _options = options; - _database = database; _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { - var temp = new Dictionary() { { "user", channel.Id } }; - - var redemptions = new List(); - string sql = $"SELECT name, type, data FROM \"Action\" WHERE \"userId\" = @user"; - await _database.Execute(sql, temp, (r) => redemptions.Add(new RedeemableAction() - { - Name = r.GetString(0), - Type = r.GetString(1), - Data = JsonSerializer.Deserialize>(r.GetString(2), _options)! - })); + var redemptions = channel.Actions.Get().Values; _logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {channel.Id}]"); - return RequestResult.Successful(redemptions, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(redemptions, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/GetRedemptions.cs b/Requests/GetRedemptions.cs index d26767d..29ce670 100644 --- a/Requests/GetRedemptions.cs +++ b/Requests/GetRedemptions.cs @@ -1,5 +1,4 @@ using HermesSocketLibrary.db; -using HermesSocketLibrary.Requests.Messages; using HermesSocketServer.Models; using ILogger = Serilog.ILogger; @@ -18,11 +17,11 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var temp = new Dictionary() { { "user", channel.Id } }; - var redemptions = new List(); + var redemptions = channel.Redemptions.Get().Values; /* new List(); string sql = $"SELECT id, \"redemptionId\", \"actionName\", \"order\", state FROM \"Redemption\" WHERE \"userId\" = @user"; await _database.Execute(sql, temp, (r) => redemptions.Add(new Redemption() { @@ -31,9 +30,9 @@ namespace HermesSocketServer.Requests ActionName = r.GetString(2), Order = r.GetInt32(3), State = r.GetBoolean(4) - })); + }));*/ _logger.Information($"Fetched all redemptions for channel [channel: {channel.Id}]"); - return RequestResult.Successful(redemptions, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(redemptions, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/GetTTSUsers.cs b/Requests/GetTTSUsers.cs index 793bfb4..7b24ef8 100644 --- a/Requests/GetTTSUsers.cs +++ b/Requests/GetTTSUsers.cs @@ -14,11 +14,11 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var results = channel.Chatters.Get().ToDictionary(p => p.Key, p => p.Value.VoiceId); _logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {channel.Id}]"); - return RequestResult.Successful(results, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(results, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/GetTTSVoices.cs b/Requests/GetTTSVoices.cs index 5689425..35059e3 100644 --- a/Requests/GetTTSVoices.cs +++ b/Requests/GetTTSVoices.cs @@ -18,7 +18,7 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { IEnumerable voices = _voices.Get().Select(v => new VoiceDetails() { @@ -27,7 +27,7 @@ namespace HermesSocketServer.Requests }); _logger.Information($"Fetched all TTS voices for channel [channel: {channel.Id}]"); - return RequestResult.Successful(voices, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(voices, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/GetTTSWordFilters.cs b/Requests/GetTTSWordFilters.cs index ab701cb..ba7024d 100644 --- a/Requests/GetTTSWordFilters.cs +++ b/Requests/GetTTSWordFilters.cs @@ -15,12 +15,12 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { IEnumerable filters = channel.Filters.Get().Values; _logger.Information($"Fetched all word filters for channel [channel: {channel.Id}]"); - return RequestResult.Successful(filters, notifyClientsOnAccount: false); + return Task.FromResult(RequestResult.Successful(filters, notifyClientsOnAccount: false)); } } } \ No newline at end of file diff --git a/Requests/IRequest.cs b/Requests/IRequest.cs index 298c002..9df03a3 100644 --- a/Requests/IRequest.cs +++ b/Requests/IRequest.cs @@ -7,6 +7,6 @@ namespace HermesSocketServer.Requests string Name { get; } string[] RequiredKeys { get; } - Task Grant(Channel channel, IDictionary? data); + Task Grant(Channel channel, IDictionary data); } } \ No newline at end of file diff --git a/Requests/RequestManager.cs b/Requests/RequestManager.cs index a895cf5..70c922f 100644 --- a/Requests/RequestManager.cs +++ b/Requests/RequestManager.cs @@ -21,7 +21,7 @@ namespace HermesSocketServer.Requests { if (message == null || message.Type == null) { - _logger.Debug($"Request type does not exist [id: {message.RequestId}][nounce: {message.Nounce}]"); + _logger.Debug($"Request type does not exist [id: {message?.RequestId ?? "null"}][nounce: {message?.Nounce ?? "null"}]"); return RequestResult.Failed("Request type does not exist."); } @@ -58,7 +58,7 @@ namespace HermesSocketServer.Requests try { - return await request.Grant(channel, message.Data); + return await request.Grant(channel, message.Data ?? new Dictionary()); } catch (Exception e) { diff --git a/Requests/UpdateDefaultTTSVoice.cs b/Requests/UpdateDefaultTTSVoice.cs index 542be7f..6dfc2f3 100644 --- a/Requests/UpdateDefaultTTSVoice.cs +++ b/Requests/UpdateDefaultTTSVoice.cs @@ -17,17 +17,17 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { string user = data["user"].ToString()!; string voice = data["voice"].ToString()!; var success = _users.Modify(user, (user) => user.DefaultVoice = voice); if (!success) - return RequestResult.Failed("Unable to find user data."); + return Task.FromResult(RequestResult.Failed("Unable to find user data.")); _logger.Information($"Updated default TTS voice for channel [channel: {channel.Id}][voice: {voice}]"); - return RequestResult.Successful(null); + return Task.FromResult(RequestResult.Successful(null)); } } } \ No newline at end of file diff --git a/Requests/UpdatePolicy.cs b/Requests/UpdatePolicy.cs index aebb02e..24fe92a 100644 --- a/Requests/UpdatePolicy.cs +++ b/Requests/UpdatePolicy.cs @@ -14,7 +14,7 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var id = Guid.Parse(data["id"].ToString()!); string groupId = data["groupId"].ToString()!; @@ -36,9 +36,9 @@ namespace HermesSocketServer.Requests { var policy = channel.Policies.Get(id.ToString()); _logger.Information($"Updated policy to channel [policy id: {id}][group id: {groupId}][path: {path}][count: {count}][span: {span}][channel: {channel.Id}]"); - return RequestResult.Successful(policy); + return Task.FromResult(RequestResult.Successful(policy)); } - return RequestResult.Failed("Something went wrong when updating the cache."); + return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache.")); } } } \ No newline at end of file diff --git a/Requests/UpdateTTSFilter.cs b/Requests/UpdateTTSFilter.cs index a107ba4..bccfc31 100644 --- a/Requests/UpdateTTSFilter.cs +++ b/Requests/UpdateTTSFilter.cs @@ -16,7 +16,7 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { var id = data["id"].ToString()!; string search = data["search"].ToString()!; @@ -35,9 +35,9 @@ namespace HermesSocketServer.Requests if (result) { _logger.Information($"Updated filter to channel [filter id: {id}][search: {search}][replace: {replace}][channel: {channel.Id}]"); - return RequestResult.Successful(filter); + return Task.FromResult(RequestResult.Successful(filter)); } - return RequestResult.Failed("Something went wrong when updating the cache."); + return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache.")); } } } \ No newline at end of file diff --git a/Requests/UpdateTTSVoice.cs b/Requests/UpdateTTSVoice.cs index 70c1e5b..9ce44c5 100644 --- a/Requests/UpdateTTSVoice.cs +++ b/Requests/UpdateTTSVoice.cs @@ -17,7 +17,7 @@ namespace HermesSocketServer.Requests _logger = logger; } - public async Task Grant(Channel channel, IDictionary data) + public Task Grant(Channel channel, IDictionary data) { string voiceName = data["voice"].ToString()!; string voiceId = data["voiceid"].ToString()!; @@ -30,9 +30,9 @@ namespace HermesSocketServer.Requests if (result) { _logger.Information($"Updated voice's [voice id: {voiceId}] name [new name: {voiceName}]"); - return RequestResult.Successful(null); + return Task.FromResult(RequestResult.Successful(null)); } - return RequestResult.Failed("Something went wrong when updating the cache."); + return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache.")); } } } \ No newline at end of file diff --git a/Requests/UpdateTTSVoiceState.cs b/Requests/UpdateTTSVoiceState.cs index 08116cf..d4d9c8d 100644 --- a/Requests/UpdateTTSVoiceState.cs +++ b/Requests/UpdateTTSVoiceState.cs @@ -19,7 +19,7 @@ namespace HermesSocketServer.Requests public async Task Grant(Channel channel, IDictionary data) { - data["voice"] = data["voice"].ToString(); + data["voice"] = data["voice"].ToString()!; data["state"] = data["state"].ToString() == "True"; data["user"] = channel.Id; diff --git a/ServerConfiguration.cs b/ServerConfiguration.cs index 15bf60c..f779e86 100644 --- a/ServerConfiguration.cs +++ b/ServerConfiguration.cs @@ -2,28 +2,28 @@ namespace HermesSocketServer { public class ServerConfiguration { - public string Environment; - public WebsocketServerConfiguration WebsocketServer; - public DatabaseConfiguration Database; - public TTSConfiguration Tts; - public string AdminPassword; + public required string Environment; + public required WebsocketServerConfiguration WebsocketServer; + public required DatabaseConfiguration Database; + public required TTSConfiguration Tts; + public string? AdminPassword; } public class WebsocketServerConfiguration { - public string Host; - public string Port; + public required string Host; + public required string Port; } public class DatabaseConfiguration { - public string ConnectionString; + public required string ConnectionString; public int SaveDelayInSeconds; } public class TTSConfiguration { public long OwnerId; - public string DefaultTtsVoice; + public required string DefaultTtsVoice; } } \ No newline at end of file diff --git a/Services/ChannelManager.cs b/Services/ChannelManager.cs index dcd8973..5e47721 100644 --- a/Services/ChannelManager.cs +++ b/Services/ChannelManager.cs @@ -23,27 +23,32 @@ namespace HermesSocketServer.Services } - public async Task Add(string userId) + public Task Add(string userId) { var user = _users.Get(userId); if (user == null) { - return null; + return Task.FromResult(null); } lock (_lock) { if (_channels.ContainsKey(userId)) { - return null; + return Task.FromResult(null); } var chatters = new ChatterStore(userId, _database, _logger); var policies = new PolicyStore(userId, _database, _logger); var filters = new TTSFilterStore(userId, _database, _logger); + var actions = new ActionStore(userId, _database, _logger); + var redemptions = new RedemptionStore(userId, _database, _logger); + Task.WaitAll([ chatters.Load(), policies.Load(), filters.Load(), + actions.Load(), + redemptions.Load(), ]); var channel = new Channel() @@ -53,10 +58,12 @@ namespace HermesSocketServer.Services Chatters = chatters, Policies = policies, Filters = filters, + Actions = actions, + Redemptions = redemptions, }; _channels.Add(userId, channel); - return channel; + return Task.FromResult(channel); } } @@ -76,6 +83,8 @@ namespace HermesSocketServer.Services channel.Chatters.Save(), channel.Policies.Save(), channel.Filters.Save(), + channel.Actions.Save(), + channel.Redemptions.Save(), ]); } @@ -88,6 +97,8 @@ namespace HermesSocketServer.Services channel.Chatters.Save(), channel.Policies.Save(), channel.Filters.Save(), + channel.Actions.Save(), + channel.Redemptions.Save(), ]); } } diff --git a/Socket/Handlers/LoggingHandler.cs b/Socket/Handlers/LoggingHandler.cs index ddce6e5..be4769c 100644 --- a/Socket/Handlers/LoggingHandler.cs +++ b/Socket/Handlers/LoggingHandler.cs @@ -15,11 +15,11 @@ namespace HermesSocketServer.Socket.Handlers } - public async Task Execute(WebSocketUser sender, T data, HermesSocketManager sockets) + public Task Execute(WebSocketUser sender, T data, HermesSocketManager sockets) { if (data is not LoggingMessage message || sender.Id == null) - return; - + return Task.CompletedTask; + Action logging; if (message.Level == HermesLoggingLevel.Trace) logging = _logger.Verbose; @@ -35,10 +35,11 @@ namespace HermesSocketServer.Socket.Handlers logging = _logger.Fatal; else { _logger.Warning("Failed to receive a logging level from client."); - return; + return Task.CompletedTask; } logging.Invoke(message.Exception, message.Message + $" [ip: {sender.IPAddress}][id: {sender.Id}][name: {sender.Name}][token: {sender.ApiKey}][uid: {sender.UID}]"); + return Task.CompletedTask; } } } \ No newline at end of file diff --git a/Socket/WebSocketUser.cs b/Socket/WebSocketUser.cs index 7a32e23..a5fc6fa 100644 --- a/Socket/WebSocketUser.cs +++ b/Socket/WebSocketUser.cs @@ -23,7 +23,7 @@ namespace HermesSocketServer.Socket public IPAddress? IPAddress { get => _ipAddress; } public bool Connected { get => _connected; } public string UID { get; } - public string ApiKey { get; set; } + public string? ApiKey { get; set; } public string? Id { get; set; } public string? Name { get; set; } public bool Admin { get; set; }