Added support for StreamElements' Overlay Key for TTS. Added emote support for stores. Reduced emotes sent to users.

This commit is contained in:
Tom
2026-01-03 05:18:03 +00:00
parent 78b6d4b789
commit 3009906b2a
11 changed files with 123 additions and 70 deletions

View File

@@ -1,6 +1,6 @@
using HermesSocketLibrary.db;
using HermesSocketLibrary.Requests.Messages;
using HermesSocketLibrary.Socket.Data;
using Npgsql;
using HermesSocketServer.Services;
using ILogger = Serilog.ILogger;
namespace HermesSocketServer.Socket.Handlers
@@ -10,7 +10,7 @@ namespace HermesSocketServer.Socket.Handlers
private const int EMOTE_BUFFER_SIZE = 5000;
public int OperationCode { get; } = 7;
private readonly Database _database;
private readonly ChannelManager _manager;
private readonly HashSet<string> _emotes;
private readonly string[] _array;
private readonly ILogger _logger;
@@ -18,9 +18,9 @@ namespace HermesSocketServer.Socket.Handlers
private int _index;
public EmoteDetailsHandler(Database database, ILogger logger)
public EmoteDetailsHandler(ChannelManager manager, ILogger logger)
{
_database = database;
_manager = manager;
_emotes = new HashSet<string>(EMOTE_BUFFER_SIZE);
_array = new string[EMOTE_BUFFER_SIZE];
_logger = logger;
@@ -72,30 +72,12 @@ namespace HermesSocketServer.Socket.Handlers
if (!data.Emotes.Any())
return;
int rows = 0;
string sql = "INSERT INTO \"Emote\" (id, name) VALUES (@idd, @name) ON CONFLICT (id) DO UPDATE SET name = @name;";
using (var connection = await _database.DataSource.OpenConnectionAsync())
{
using (var command = new NpgsqlCommand(sql, connection))
{
foreach (var entry in data.Emotes)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("idd", entry.Key);
command.Parameters.AddWithValue("name", entry.Value);
await command.PrepareAsync();
try
{
rows += await command.ExecuteNonQueryAsync();
}
catch (Exception e)
{
_logger.Error(e, "Failed to add emote detail: " + entry.Key + " -> " + entry.Value);
}
}
}
}
var channel = _manager.Get(sender.Id);
if (channel == null)
return;
foreach (var entry in data.Emotes)
channel.Emotes.Set(entry.Key, new EmoteInfo() { Id = entry.Key, Name = entry.Value, UserId = channel.Id });
}
}
}