Added support for StreamElements' Overlay Key for TTS. Added emote support for stores. Reduced emotes sent to users.
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user