2024-03-12 14:05:27 -04:00
|
|
|
|
using TwitchChatTTS.OBS.Socket.Manager;
|
|
|
|
|
using TwitchChatTTS.OBS.Socket;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using TwitchChatTTS;
|
|
|
|
|
using CommonSocketLibrary.Abstract;
|
|
|
|
|
using CommonSocketLibrary.Common;
|
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
|
|
|
using TwitchChatTTS.Seven.Socket;
|
|
|
|
|
using TwitchChatTTS.OBS.Socket.Handlers;
|
|
|
|
|
using TwitchChatTTS.Seven.Socket.Handlers;
|
|
|
|
|
using TwitchChatTTS.Seven.Socket.Context;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
using TwitchLib.Client.Interfaces;
|
|
|
|
|
using TwitchLib.Client;
|
|
|
|
|
using TwitchLib.PubSub.Interfaces;
|
|
|
|
|
using TwitchLib.PubSub;
|
|
|
|
|
using TwitchLib.Communication.Interfaces;
|
|
|
|
|
using TwitchChatTTS.Seven.Socket.Managers;
|
|
|
|
|
using TwitchChatTTS.Hermes.Socket.Handlers;
|
|
|
|
|
using TwitchChatTTS.Hermes.Socket;
|
|
|
|
|
using TwitchChatTTS.Hermes.Socket.Managers;
|
|
|
|
|
using TwitchChatTTS.Chat.Commands.Parameters;
|
|
|
|
|
using TwitchChatTTS.Chat.Commands;
|
|
|
|
|
using System.Text.Json;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
using Serilog;
|
|
|
|
|
using Serilog.Events;
|
2024-06-24 18:11:36 -04:00
|
|
|
|
using Serilog.Sinks.SystemConsole.Themes;
|
|
|
|
|
using TwitchChatTTS.Twitch.Redemptions;
|
2024-07-12 13:36:09 -04:00
|
|
|
|
using TwitchChatTTS.Chat.Groups.Permissions;
|
|
|
|
|
using TwitchChatTTS.Chat.Groups;
|
2024-07-16 00:48:55 -04:00
|
|
|
|
using TwitchChatTTS.Chat.Emotes;
|
|
|
|
|
using HermesSocketLibrary.Requests.Callbacks;
|
2024-03-12 14:05:27 -04:00
|
|
|
|
|
|
|
|
|
// dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained true
|
|
|
|
|
// dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true
|
|
|
|
|
// SE voices: https://api.streamelements.com/kappa/v2/speech?voice=brian&text=hello
|
|
|
|
|
|
|
|
|
|
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
|
|
|
|
var s = builder.Services;
|
|
|
|
|
|
|
|
|
|
var deserializer = new DeserializerBuilder()
|
2024-06-24 18:11:36 -04:00
|
|
|
|
.IgnoreUnmatchedProperties()
|
2024-03-12 14:05:27 -04:00
|
|
|
|
.WithNamingConvention(HyphenatedNamingConvention.Instance)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var configContent = File.ReadAllText("tts.config.yml");
|
|
|
|
|
var configuration = deserializer.Deserialize<Configuration>(configContent);
|
|
|
|
|
s.AddSingleton<Configuration>(configuration);
|
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
|
var logger = new LoggerConfiguration()
|
2024-06-24 18:11:36 -04:00
|
|
|
|
.MinimumLevel.Verbose()
|
|
|
|
|
//.MinimumLevel.Override("TwitchLib.Communication.Clients.WebSocketClient", LogEventLevel.Warning)
|
|
|
|
|
//.MinimumLevel.Override("TwitchLib.PubSub.TwitchPubSub", LogEventLevel.Warning)
|
|
|
|
|
.MinimumLevel.Override("TwitchLib", LogEventLevel.Warning)
|
|
|
|
|
.MinimumLevel.Override("mariuszgromada", LogEventLevel.Error)
|
|
|
|
|
.Enrich.FromLogContext()
|
2024-07-12 13:36:09 -04:00
|
|
|
|
.WriteTo.File("logs/log-.log", restrictedToMinimumLevel: LogEventLevel.Debug, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 3)
|
2024-06-24 18:11:36 -04:00
|
|
|
|
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Information, theme: SystemConsoleTheme.Colored)
|
2024-06-16 20:19:31 -04:00
|
|
|
|
.CreateLogger();
|
|
|
|
|
|
|
|
|
|
s.AddSerilog(logger);
|
2024-03-15 08:27:35 -04:00
|
|
|
|
s.AddSingleton<User>(new User());
|
2024-07-16 00:48:55 -04:00
|
|
|
|
s.AddSingleton<ICallbackManager<HermesRequestData>, CallbackManager<HermesRequestData>>();
|
2024-03-12 14:05:27 -04:00
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
|
s.AddSingleton<JsonSerializerOptions>(new JsonSerializerOptions()
|
|
|
|
|
{
|
2024-03-15 08:27:35 -04:00
|
|
|
|
PropertyNameCaseInsensitive = false,
|
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
2024-03-12 14:05:27 -04:00
|
|
|
|
});
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
|
|
|
|
// Command parameters
|
|
|
|
|
s.AddKeyedSingleton<ChatCommandParameter, TTSVoiceNameParameter>("parameter-ttsvoicename");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommandParameter, UnvalidatedParameter>("parameter-unvalidated");
|
2024-07-16 00:48:55 -04:00
|
|
|
|
s.AddKeyedSingleton<ChatCommandParameter, SimpleListedParameter>("parameter-simplelisted");
|
2024-03-15 08:27:35 -04:00
|
|
|
|
s.AddKeyedSingleton<ChatCommand, SkipAllCommand>("command-skipall");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommand, SkipCommand>("command-skip");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommand, VoiceCommand>("command-voice");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommand, AddTTSVoiceCommand>("command-addttsvoice");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommand, RemoveTTSVoiceCommand>("command-removettsvoice");
|
2024-06-16 20:19:31 -04:00
|
|
|
|
s.AddKeyedSingleton<ChatCommand, RefreshTTSDataCommand>("command-refreshttsdata");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommand, OBSCommand>("command-obs");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommand, TTSCommand>("command-tts");
|
|
|
|
|
s.AddKeyedSingleton<ChatCommand, VersionCommand>("command-version");
|
2024-07-12 13:36:09 -04:00
|
|
|
|
s.AddSingleton<IChatterGroupManager, ChatterGroupManager>();
|
|
|
|
|
s.AddSingleton<IGroupPermissionManager, GroupPermissionManager>();
|
2024-03-15 08:27:35 -04:00
|
|
|
|
s.AddSingleton<ChatCommandManager>();
|
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddSingleton<TTSPlayer>();
|
|
|
|
|
s.AddSingleton<ChatMessageHandler>();
|
2024-06-24 18:11:36 -04:00
|
|
|
|
s.AddSingleton<RedemptionManager>();
|
2024-06-16 20:19:31 -04:00
|
|
|
|
s.AddSingleton<HermesApiClient>();
|
2024-07-16 00:48:55 -04:00
|
|
|
|
s.AddSingleton<TwitchBotAuth>();
|
2024-03-15 08:27:35 -04:00
|
|
|
|
s.AddTransient<IClient, TwitchLib.Communication.Clients.WebSocketClient>();
|
|
|
|
|
s.AddTransient<ITwitchClient, TwitchClient>();
|
|
|
|
|
s.AddTransient<ITwitchPubSub, TwitchPubSub>();
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddSingleton<TwitchApiClient>();
|
|
|
|
|
|
|
|
|
|
s.AddSingleton<SevenApiClient>();
|
2024-07-16 00:48:55 -04:00
|
|
|
|
s.AddSingleton<IEmoteDatabase, EmoteDatabase>();
|
2024-03-12 14:05:27 -04:00
|
|
|
|
|
|
|
|
|
// OBS websocket
|
2024-06-24 18:11:36 -04:00
|
|
|
|
s.AddSingleton<OBSManager>();
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, HelloHandler>("obs-hello");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, IdentifiedHandler>("obs-identified");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, RequestResponseHandler>("obs-requestresponse");
|
2024-06-16 20:19:31 -04:00
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, RequestBatchResponseHandler>("obs-requestbatchresponse");
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, EventMessageHandler>("obs-eventmessage");
|
|
|
|
|
|
|
|
|
|
s.AddKeyedSingleton<HandlerManager<WebSocketClient, IWebSocketHandler>, OBSHandlerManager>("obs");
|
|
|
|
|
s.AddKeyedSingleton<HandlerTypeManager<WebSocketClient, IWebSocketHandler>, OBSHandlerTypeManager>("obs");
|
|
|
|
|
s.AddKeyedSingleton<SocketClient<WebSocketMessage>, OBSSocketClient>("obs");
|
|
|
|
|
|
|
|
|
|
// 7tv websocket
|
2024-06-16 20:19:31 -04:00
|
|
|
|
s.AddTransient(sp =>
|
|
|
|
|
{
|
|
|
|
|
var logger = sp.GetRequiredService<ILogger>();
|
2024-03-12 14:05:27 -04:00
|
|
|
|
var client = sp.GetRequiredKeyedService<SocketClient<WebSocketMessage>>("7tv") as SevenSocketClient;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
if (client == null)
|
2024-03-15 08:27:35 -04:00
|
|
|
|
return new ReconnectContext() { SessionId = null };
|
2024-06-16 20:19:31 -04:00
|
|
|
|
if (client.ConnectionDetails == null)
|
2024-03-15 08:27:35 -04:00
|
|
|
|
return new ReconnectContext() { SessionId = null };
|
|
|
|
|
return new ReconnectContext() { SessionId = client.ConnectionDetails.SessionId };
|
2024-03-12 14:05:27 -04:00
|
|
|
|
});
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, SevenHelloHandler>("7tv-sevenhello");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, HelloHandler>("7tv-hello");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, DispatchHandler>("7tv-dispatch");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, ReconnectHandler>("7tv-reconnect");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, ErrorHandler>("7tv-error");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, EndOfStreamHandler>("7tv-endofstream");
|
|
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
|
s.AddSingleton<SevenManager>();
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddKeyedSingleton<HandlerManager<WebSocketClient, IWebSocketHandler>, SevenHandlerManager>("7tv");
|
|
|
|
|
s.AddKeyedSingleton<HandlerTypeManager<WebSocketClient, IWebSocketHandler>, SevenHandlerTypeManager>("7tv");
|
|
|
|
|
s.AddKeyedSingleton<SocketClient<WebSocketMessage>, SevenSocketClient>("7tv");
|
|
|
|
|
|
2024-03-15 08:27:35 -04:00
|
|
|
|
// hermes websocket
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, HeartbeatHandler>("hermes-heartbeat");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, LoginAckHandler>("hermes-loginack");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, RequestAckHandler>("hermes-requestack");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, HeartbeatHandler>("hermes-error");
|
|
|
|
|
|
|
|
|
|
s.AddKeyedSingleton<HandlerManager<WebSocketClient, IWebSocketHandler>, HermesHandlerManager>("hermes");
|
|
|
|
|
s.AddKeyedSingleton<HandlerTypeManager<WebSocketClient, IWebSocketHandler>, HermesHandlerTypeManager>("hermes");
|
|
|
|
|
s.AddKeyedSingleton<SocketClient<WebSocketMessage>, HermesSocketClient>("hermes");
|
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddHostedService<TTS>();
|
|
|
|
|
using IHost host = builder.Build();
|
|
|
|
|
await host.RunAsync();
|