Added stores for connections. Added requests for groups, group chatters, group permissions & connections. Using TTS Voice State store.
This commit is contained in:
		
							
								
								
									
										75
									
								
								Store/ConnectionStore.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								Store/ConnectionStore.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,75 @@ | ||||
| using HermesSocketLibrary.db; | ||||
| using HermesSocketLibrary.Socket.Data; | ||||
| using HermesSocketServer.Store.Internal; | ||||
|  | ||||
| namespace HermesSocketServer.Store | ||||
| { | ||||
|     public class ConnectionStore : ComplexAutoSavedStore<string, Connection> | ||||
|     { | ||||
|         private readonly string _userId; | ||||
|         private readonly Database _database; | ||||
|         private readonly Serilog.ILogger _logger; | ||||
|  | ||||
|         public ConnectionStore(string userId, DatabaseTable table, Database database, Serilog.ILogger logger) | ||||
|             : base(table, database, logger) | ||||
|         { | ||||
|             _userId = userId; | ||||
|             _database = database; | ||||
|             _logger = logger; | ||||
|         } | ||||
|  | ||||
|         public override async Task Load() | ||||
|         { | ||||
|             var data = new Dictionary<string, object>() { { "user", _userId } }; | ||||
|             string sql = $"SELECT name, \"type\", \"clientId\", \"accessToken\", \"grantType\", \"scope\", \"expiresAt\", \"default\" FROM \"Connection\" WHERE \"userId\" = @user"; | ||||
|             await _database.Execute(sql, data, (reader) => | ||||
|             { | ||||
|                 var name = reader.GetString(0); | ||||
|                 _store.Add(name, new Connection() | ||||
|                 { | ||||
|                     Name = name, | ||||
|                     UserId = _userId, | ||||
|                     Type = reader.GetString(1), | ||||
|                     ClientId = reader.GetString(2), | ||||
|                     AccessToken = reader.GetString(3), | ||||
|                     GrantType = reader.GetString(4), | ||||
|                     Scope = reader.GetString(5), | ||||
|                     ExpiresAt = reader.GetDateTime(6), | ||||
|                     Default = reader.GetBoolean(7), | ||||
|                 }); | ||||
|             }); | ||||
|             _logger.Information($"Loaded {_store.Count} groups from database."); | ||||
|         } | ||||
|  | ||||
|         protected override void OnInitialAdd(string key, Connection value) | ||||
|         { | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(key, nameof(key)); | ||||
|             ArgumentNullException.ThrowIfNull(value, nameof(value)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(value.UserId, nameof(value.UserId)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(value.Name, nameof(value.Name)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(value.Type, nameof(value.Type)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(value.ClientId, nameof(value.ClientId)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(value.AccessToken, nameof(value.AccessToken)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(value.GrantType, nameof(value.GrantType)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(value.Scope, nameof(value.Scope)); | ||||
|             ArgumentNullException.ThrowIfNull(value.ExpiresAt, nameof(value.ExpiresAt)); | ||||
|             ArgumentNullException.ThrowIfNull(value.Default, nameof(value.Default)); | ||||
|         } | ||||
|  | ||||
|         protected override void OnInitialModify(string key, Connection oldValue, Connection newValue) | ||||
|         { | ||||
|             ArgumentNullException.ThrowIfNull(newValue, nameof(newValue)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(newValue.UserId, nameof(newValue.UserId)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(newValue.Name, nameof(newValue.Name)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(newValue.Type, nameof(newValue.Type)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(newValue.ClientId, nameof(newValue.ClientId)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(newValue.AccessToken, nameof(newValue.AccessToken)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(newValue.GrantType, nameof(newValue.GrantType)); | ||||
|             ArgumentException.ThrowIfNullOrWhiteSpace(newValue.Scope, nameof(newValue.Scope)); | ||||
|             ArgumentNullException.ThrowIfNull(newValue.ExpiresAt, nameof(newValue.ExpiresAt)); | ||||
|             ArgumentNullException.ThrowIfNull(newValue.Default, nameof(newValue.Default)); | ||||
|             ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.UserId, newValue.UserId, nameof(oldValue.UserId)); | ||||
|             ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.Name, newValue.Name, nameof(oldValue.Name)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -7,7 +7,7 @@ namespace HermesSocketServer.Store | ||||
| { | ||||
|     public class GroupStore : AutoSavedStore<string, Group> | ||||
|     { | ||||
|         private static readonly string[] AUTO_GENERATED_GROUP_NAMES = ["everyone", "subscribers", "vip", "moderators", "broadcaster"]; | ||||
|         public static readonly string[] AUTO_GENERATED_GROUP_NAMES = ["everyone", "subscribers", "vip", "moderators", "broadcaster"]; | ||||
|  | ||||
|         private IDictionary<string, ChatterGroupStore> _chatters; | ||||
|         private readonly string _userId; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user