Using Serilog. Added partial OBS batch request support. Added update checking. Added more commands. Added enabled/disabled TTS voices. And more.

This commit is contained in:
Tom
2024-06-17 00:19:31 +00:00
parent d4004d6230
commit 706cd06930
67 changed files with 1933 additions and 925 deletions

View File

@@ -7,7 +7,6 @@ using CommonSocketLibrary.Abstract;
using CommonSocketLibrary.Common;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using Microsoft.Extensions.Logging;
using TwitchChatTTS.Seven.Socket;
using TwitchChatTTS.OBS.Socket.Handlers;
using TwitchChatTTS.Seven.Socket.Handlers;
@@ -26,6 +25,8 @@ using TwitchChatTTS.Hermes.Socket.Managers;
using TwitchChatTTS.Chat.Commands.Parameters;
using TwitchChatTTS.Chat.Commands;
using System.Text.Json;
using Serilog;
using Serilog.Events;
// dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained true
// dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true
@@ -41,18 +42,31 @@ var deserializer = new DeserializerBuilder()
var configContent = File.ReadAllText("tts.config.yml");
var configuration = deserializer.Deserialize<Configuration>(configContent);
var redeemKeys = configuration.Twitch?.Redeems?.Keys;
if (redeemKeys != null) {
foreach (var key in redeemKeys) {
if (key != key.ToLower() && configuration.Twitch?.Redeems != null)
if (redeemKeys != null && redeemKeys.Any())
{
foreach (var key in redeemKeys)
{
if (key != key.ToLower())
configuration.Twitch.Redeems.Add(key.ToLower(), configuration.Twitch.Redeems[key]);
}
}
s.AddSingleton<Configuration>(configuration);
s.AddLogging();
var logger = new LoggerConfiguration()
#if DEBUG
.MinimumLevel.Debug()
#else
.MinimumLevel.Information()
#endif
.WriteTo.File("logs/log.log", rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7)
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Information)
.CreateLogger();
s.AddSerilog(logger);
s.AddSingleton<User>(new User());
s.AddSingleton<JsonSerializerOptions>(new JsonSerializerOptions() {
s.AddSingleton<JsonSerializerOptions>(new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = false,
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
});
@@ -65,46 +79,38 @@ s.AddKeyedSingleton<ChatCommand, SkipCommand>("command-skip");
s.AddKeyedSingleton<ChatCommand, VoiceCommand>("command-voice");
s.AddKeyedSingleton<ChatCommand, AddTTSVoiceCommand>("command-addttsvoice");
s.AddKeyedSingleton<ChatCommand, RemoveTTSVoiceCommand>("command-removettsvoice");
s.AddKeyedSingleton<ChatCommand, RefreshTTSDataCommand>("command-refreshttsdata");
s.AddKeyedSingleton<ChatCommand, OBSCommand>("command-obs");
s.AddKeyedSingleton<ChatCommand, TTSCommand>("command-tts");
s.AddKeyedSingleton<ChatCommand, VersionCommand>("command-version");
s.AddSingleton<ChatCommandManager>();
s.AddSingleton<TTSPlayer>();
s.AddSingleton<ChatMessageHandler>();
s.AddSingleton<HermesClient>();
s.AddSingleton<TwitchBotToken>(sp => {
var hermes = sp.GetRequiredService<HermesClient>();
var task = hermes.FetchTwitchBotToken();
task.Wait();
return task.Result;
});
s.AddSingleton<HermesApiClient>();
s.AddSingleton<TwitchBotAuth>(new TwitchBotAuth());
s.AddTransient<IClient, TwitchLib.Communication.Clients.WebSocketClient>();
s.AddTransient<ITwitchClient, TwitchClient>();
s.AddTransient<ITwitchPubSub, TwitchPubSub>();
s.AddSingleton<TwitchApiClient>();
s.AddSingleton<SevenApiClient>();
s.AddSingleton<EmoteDatabase>(sp => {
var api = sp.GetRequiredService<SevenApiClient>();
var task = api.GetSevenEmotes();
task.Wait();
return task.Result;
});
s.AddSingleton<EmoteCounter>(sp => {
if (!string.IsNullOrWhiteSpace(configuration.Emotes?.CounterFilePath) && File.Exists(configuration.Emotes.CounterFilePath.Trim()))
return deserializer.Deserialize<EmoteCounter>(File.ReadAllText(configuration.Emotes.CounterFilePath.Trim()));
return new EmoteCounter();
});
s.AddSingleton<EmoteDatabase>(new EmoteDatabase());
// OBS websocket
s.AddSingleton<HelloContext>(sp =>
new HelloContext() {
new HelloContext()
{
Host = string.IsNullOrWhiteSpace(configuration.Obs?.Host) ? null : configuration.Obs.Host.Trim(),
Port = configuration.Obs?.Port,
Password = string.IsNullOrWhiteSpace(configuration.Obs?.Password) ? null : configuration.Obs.Password.Trim()
}
);
s.AddSingleton<OBSRequestBatchManager>();
s.AddKeyedSingleton<IWebSocketHandler, HelloHandler>("obs-hello");
s.AddKeyedSingleton<IWebSocketHandler, IdentifiedHandler>("obs-identified");
s.AddKeyedSingleton<IWebSocketHandler, RequestResponseHandler>("obs-requestresponse");
s.AddKeyedSingleton<IWebSocketHandler, RequestBatchResponseHandler>("obs-requestbatchresponse");
s.AddKeyedSingleton<IWebSocketHandler, EventMessageHandler>("obs-eventmessage");
s.AddKeyedSingleton<HandlerManager<WebSocketClient, IWebSocketHandler>, OBSHandlerManager>("obs");
@@ -112,15 +118,18 @@ s.AddKeyedSingleton<HandlerTypeManager<WebSocketClient, IWebSocketHandler>, OBSH
s.AddKeyedSingleton<SocketClient<WebSocketMessage>, OBSSocketClient>("obs");
// 7tv websocket
s.AddTransient(sp => {
var logger = sp.GetRequiredService<ILogger<ReconnectContext>>();
s.AddTransient(sp =>
{
var logger = sp.GetRequiredService<ILogger>();
var client = sp.GetRequiredKeyedService<SocketClient<WebSocketMessage>>("7tv") as SevenSocketClient;
if (client == null) {
logger.LogError("7tv client == null.");
if (client == null)
{
logger.Error("7tv client == null.");
return new ReconnectContext() { SessionId = null };
}
if (client.ConnectionDetails == null) {
logger.LogError("Connection details in 7tv client == null.");
if (client.ConnectionDetails == null)
{
logger.Error("Connection details in 7tv client == null.");
return new ReconnectContext() { SessionId = null };
}
return new ReconnectContext() { SessionId = client.ConnectionDetails.SessionId };
@@ -147,6 +156,5 @@ s.AddKeyedSingleton<HandlerTypeManager<WebSocketClient, IWebSocketHandler>, Herm
s.AddKeyedSingleton<SocketClient<WebSocketMessage>, HermesSocketClient>("hermes");
s.AddHostedService<TTS>();
using IHost host = builder.Build();
await host.RunAsync();