Added & modified several message types.
This commit is contained in:
parent
d8522584c4
commit
9d838e66ad
@ -8,16 +8,10 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.1-dev-10391" />
|
||||
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="2.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00972" />
|
||||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
|
||||
<PackageReference Include="Serilog.Sinks.Trace" Version="4.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
43
Requests/Callbacks/CallbackManager.cs
Normal file
43
Requests/Callbacks/CallbackManager.cs
Normal file
@ -0,0 +1,43 @@
|
||||
namespace HermesSocketLibrary.Requests.Callbacks
|
||||
{
|
||||
public class CallbackManager<A> : ICallbackManager<A> where A : class
|
||||
{
|
||||
private readonly IDictionary<string, A> _callbacks;
|
||||
|
||||
|
||||
public CallbackManager()
|
||||
{
|
||||
_callbacks = new Dictionary<string, A>();
|
||||
}
|
||||
|
||||
|
||||
public string GenerateKeyForCallback(A callback)
|
||||
{
|
||||
string key = GenerateKey();
|
||||
_callbacks.Add(key, callback);
|
||||
return key;
|
||||
}
|
||||
|
||||
public A? Get(string key)
|
||||
{
|
||||
if (_callbacks.TryGetValue(key, out var callback))
|
||||
return callback;
|
||||
return null;
|
||||
}
|
||||
|
||||
public A? Take(string key)
|
||||
{
|
||||
if (_callbacks.TryGetValue(key, out var callback))
|
||||
{
|
||||
_callbacks.Remove(key);
|
||||
return callback;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GenerateKey()
|
||||
{
|
||||
return Guid.NewGuid().ToString("D");
|
||||
}
|
||||
}
|
||||
}
|
9
Requests/Callbacks/ICallbackManager.cs
Normal file
9
Requests/Callbacks/ICallbackManager.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace HermesSocketLibrary.Requests.Callbacks
|
||||
{
|
||||
public interface ICallbackManager<A> where A : class
|
||||
{
|
||||
string GenerateKeyForCallback(A callback);
|
||||
A? Get(string key);
|
||||
A? Take(string key);
|
||||
}
|
||||
}
|
@ -4,6 +4,6 @@ namespace HermesSocketLibrary.Requests
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
Task<RequestResult> Grant(string sender, IDictionary<string, object> data);
|
||||
Task<RequestResult> Grant(string sender, IDictionary<string, object>? data);
|
||||
}
|
||||
}
|
9
Requests/IRequestManager.cs
Normal file
9
Requests/IRequestManager.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using HermesSocketLibrary.Socket.Data;
|
||||
|
||||
namespace HermesSocketLibrary.Requests
|
||||
{
|
||||
public interface IRequestManager
|
||||
{
|
||||
Task<RequestResult> Grant(string sender, RequestMessage? message);
|
||||
}
|
||||
}
|
@ -1,8 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class EmoteInfo
|
||||
|
9
Requests/Messages/Group.cs
Normal file
9
Requests/Messages/Group.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class Group
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
}
|
8
Requests/Messages/GroupChatter.cs
Normal file
8
Requests/Messages/GroupChatter.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class GroupChatter
|
||||
{
|
||||
public string GroupId { get; set; }
|
||||
public long ChatterId { get; set;}
|
||||
}
|
||||
}
|
9
Requests/Messages/GroupInfo.cs
Normal file
9
Requests/Messages/GroupInfo.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class GroupInfo
|
||||
{
|
||||
public IEnumerable<Group> Groups { get; set; }
|
||||
public IEnumerable<GroupChatter> GroupChatters { get; set; }
|
||||
public IEnumerable<GroupPermission> GroupPermissions { get; set; }
|
||||
}
|
||||
}
|
10
Requests/Messages/GroupPermission.cs
Normal file
10
Requests/Messages/GroupPermission.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class GroupPermission
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string GroupId { get; set; }
|
||||
public string Path { get; set; }
|
||||
public bool? Allow { get; set; }
|
||||
}
|
||||
}
|
9
Requests/Messages/RedeemableAction.cs
Normal file
9
Requests/Messages/RedeemableAction.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class RedeemableAction
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
public IDictionary<string, string> Data { get; set; }
|
||||
}
|
||||
}
|
11
Requests/Messages/Redemption.cs
Normal file
11
Requests/Messages/Redemption.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class Redemption
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string RedemptionId { get; set; }
|
||||
public string ActionName { get; set; }
|
||||
public int Order { get; set; }
|
||||
public bool State { get; set; }
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace HermesSocketLibrary.Requests.Messages
|
||||
{
|
||||
public class TTSWordFilter
|
||||
@ -5,7 +8,8 @@ namespace HermesSocketLibrary.Requests.Messages
|
||||
public string? Id { get; set; }
|
||||
public string? Search { get; set; }
|
||||
public string? Replace { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Regex? Regex { get; set; }
|
||||
public bool IsRegex { get; set; }
|
||||
|
||||
|
||||
|
@ -1,40 +1,19 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using HermesSocketLibrary.Socket.Data;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
|
||||
namespace HermesSocketLibrary.Requests
|
||||
{
|
||||
public abstract class RequestManager
|
||||
public class RequestManager : IRequestManager
|
||||
{
|
||||
private readonly IDictionary<string, IRequest> _requests;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
|
||||
public RequestManager(IServiceProvider serviceProvider, ILogger logger)
|
||||
public RequestManager(IEnumerable<IRequest> requests, ILogger logger)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_logger = logger;
|
||||
|
||||
_requests = new ConcurrentDictionary<string, IRequest>();
|
||||
LoadRequests();
|
||||
}
|
||||
|
||||
protected abstract string AssemblyName { get; }
|
||||
|
||||
private void LoadRequests()
|
||||
{
|
||||
Type basetype = typeof(IRequest);
|
||||
var types = Assembly.Load(AssemblyName).GetTypes().Where(t => t.IsClass && !t.IsAbstract && basetype.IsAssignableFrom(t));
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
_logger.Debug($"Loading IRequest for '{type.Name}'.");
|
||||
var request = _serviceProvider.GetRequiredKeyedService<IRequest>(type.Name);
|
||||
_requests.Add(request.Name, request);
|
||||
}
|
||||
_requests = requests.ToDictionary(r => r.Name, r => r);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> Grant(string sender, RequestMessage? message)
|
||||
|
19
Socket/Data/Connection.cs
Normal file
19
Socket/Data/Connection.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HermesSocketLibrary.Socket.Data
|
||||
{
|
||||
public class Connection
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string ClientId { get; set; }
|
||||
public string AccessToken { get; set; }
|
||||
public string GrantType { get; set; }
|
||||
public string Scope { get; set; }
|
||||
public DateTime ExpiresIn { get; set; }
|
||||
public bool Default { get; set; }
|
||||
}
|
||||
}
|
@ -2,6 +2,6 @@ namespace HermesSocketLibrary.Socket.Data
|
||||
{
|
||||
public class EmoteDetailsMessage
|
||||
{
|
||||
public Dictionary<string, string> Emotes { get; set; }
|
||||
public IDictionary<string, string> Emotes { get; set; }
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ namespace HermesSocketLibrary.Socket.Data
|
||||
public string MessageId { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public long BroadcasterId { get; set; }
|
||||
public HashSet<string> Emotes { get; set; }
|
||||
public ICollection<string> Emotes { get; set; }
|
||||
public long ChatterId { get; set; }
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
namespace HermesSocketLibrary.Socket.Data
|
||||
{
|
||||
public class ErrorMessage
|
||||
{
|
||||
public Exception? Exception { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
||||
public ErrorMessage(Exception exception, string message)
|
||||
{
|
||||
Exception = exception;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public ErrorMessage(string message)
|
||||
{
|
||||
Message = message;
|
||||
Exception = null;
|
||||
}
|
||||
}
|
||||
}
|
41
Socket/Data/LoggingMessage.cs
Normal file
41
Socket/Data/LoggingMessage.cs
Normal file
@ -0,0 +1,41 @@
|
||||
namespace HermesSocketLibrary.Socket.Data
|
||||
{
|
||||
public enum HermesLoggingLevel
|
||||
{
|
||||
Trace,
|
||||
Debug,
|
||||
Info,
|
||||
Warn,
|
||||
Error,
|
||||
Critical,
|
||||
None
|
||||
}
|
||||
|
||||
public class LoggingMessage
|
||||
{
|
||||
public Exception? Exception { get; set; }
|
||||
public string Message { get; set; }
|
||||
public HermesLoggingLevel Level { get; set; }
|
||||
|
||||
public LoggingMessage(Exception exception, string message, HermesLoggingLevel level)
|
||||
{
|
||||
Exception = exception;
|
||||
Message = message;
|
||||
Level = level;
|
||||
}
|
||||
|
||||
public LoggingMessage(string message, HermesLoggingLevel level)
|
||||
{
|
||||
Message = message;
|
||||
Level = level;
|
||||
Exception = null;
|
||||
}
|
||||
|
||||
public LoggingMessage()
|
||||
{
|
||||
Message = string.Empty;
|
||||
Level = HermesLoggingLevel.Info;
|
||||
Exception = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ namespace HermesSocketLibrary.Socket.Data
|
||||
{
|
||||
public class RequestMessage
|
||||
{
|
||||
public string RequestId { get; set; }
|
||||
public string? Type { get; set; }
|
||||
public IDictionary<string, object>? Data { get; set; }
|
||||
public string? Nounce { get; set; }
|
||||
|
@ -1,12 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace HermesSocketLibrary.Socket.Data
|
||||
{
|
||||
public class SocketMessage
|
||||
{
|
||||
[JsonPropertyName("op")]
|
||||
public int? OpCode { get; set; }
|
||||
[JsonPropertyName("d")]
|
||||
public object? Data { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user