Added groups & permissions. Fixed TTS user creation. Better connection handling. Fixed 7tv reconnection.

This commit is contained in:
Tom
2024-07-16 04:48:55 +00:00
parent 9fb966474f
commit e6b3819356
45 changed files with 947 additions and 567 deletions

View File

@ -1,7 +0,0 @@
namespace TwitchChatTTS.Seven.Socket.Data
{
public class IdentifyMessage
{
}
}

View File

@ -2,6 +2,7 @@ using System.Text.Json;
using CommonSocketLibrary.Abstract;
using CommonSocketLibrary.Common;
using Serilog;
using TwitchChatTTS.Chat.Emotes;
using TwitchChatTTS.Seven.Socket.Data;
namespace TwitchChatTTS.Seven.Socket.Handlers
@ -9,14 +10,14 @@ namespace TwitchChatTTS.Seven.Socket.Handlers
public class DispatchHandler : IWebSocketHandler
{
private readonly ILogger _logger;
private readonly EmoteDatabase _emotes;
private readonly IEmoteDatabase _emotes;
private readonly object _lock = new object();
public int OperationCode { get; } = 0;
public DispatchHandler(ILogger logger, EmoteDatabase emotes)
public DispatchHandler(IEmoteDatabase emotes, ILogger logger)
{
_logger = logger;
_emotes = emotes;
_logger = logger;
}
public async Task Execute<Data>(SocketClient<WebSocketMessage> sender, Data data)
@ -53,12 +54,20 @@ namespace TwitchChatTTS.Seven.Socket.Handlers
{
if (removing)
{
RemoveEmoteById(o.Id);
if (_emotes.Get(o.Name) != o.Id) {
_logger.Warning("Mismatched emote found while removing a 7tv emote.");
continue;
}
_emotes.Remove(o.Name);
_logger.Information($"Removed 7tv emote [name: {o.Name}][id: {o.Id}]");
}
else if (updater != null)
{
RemoveEmoteById(o.Id);
if (_emotes.Get(o.Name) != o.Id) {
_logger.Warning("Mismatched emote found while updating a 7tv emote.");
continue;
}
_emotes.Remove(o.Name);
var update = updater(val);
var u = JsonSerializer.Deserialize<EmoteField>(update.ToString(), new JsonSerializerOptions()
@ -85,20 +94,5 @@ namespace TwitchChatTTS.Seven.Socket.Handlers
}
}
}
private void RemoveEmoteById(string id)
{
string? key = null;
foreach (var e in _emotes.Emotes)
{
if (e.Value == id)
{
key = e.Key;
break;
}
}
if (key != null)
_emotes.Remove(key);
}
}
}

View File

@ -41,9 +41,9 @@ namespace TwitchChatTTS.Seven.Socket.Handlers
];
_reconnectDelay = [
1000,
0,
0,
0,
-1,
-1,
-1,
0,
3000,
1000,
@ -77,19 +77,17 @@ namespace TwitchChatTTS.Seven.Socket.Handlers
if (string.IsNullOrWhiteSpace(_user.SevenEmoteSetId))
{
_logger.Warning("Connected to 7tv websocket previously, but no emote set id was set.");
_logger.Warning("Could not find the 7tv emote set id. Not reconnecting.");
return;
}
var context = _serviceProvider.GetRequiredService<ReconnectContext>();
if (_reconnectDelay[code] > 0)
await Task.Delay(_reconnectDelay[code]);
var manager = _serviceProvider.GetRequiredService<SevenManager>();
await manager.Connect();
var base_url = $"@emote_set.*<object_id={_user.SevenEmoteSetId}>";
string url = $"{SevenApiClient.WEBSOCKET_URL}{base_url}";
_logger.Debug($"7tv websocket reconnecting to {url}.");
await sender.ConnectAsync(url);
if (context.SessionId != null)
{
await sender.Send(34, new ResumeMessage() { SessionId = context.SessionId });

View File

@ -23,9 +23,8 @@ namespace TwitchChatTTS.Seven.Socket.Handlers
if (sender is not SevenSocketClient seven || seven == null)
return;
seven.Connected = true;
seven.ConnectionDetails = message;
_logger.Information("Connected to 7tv websockets.");
_logger.Debug("Received hello handshake ack.");
}
}
}