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; using TwitchChatTTS.Seven; using TwitchChatTTS.OBS.Socket.Context; 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; 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 // 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() .WithNamingConvention(HyphenatedNamingConvention.Instance) .Build(); var configContent = File.ReadAllText("tts.config.yml"); var configuration = deserializer.Deserialize(configContent); var redeemKeys = configuration.Twitch?.Redeems?.Keys; 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); 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(new User()); s.AddSingleton(new JsonSerializerOptions() { PropertyNameCaseInsensitive = false, PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower }); // Command parameters s.AddKeyedSingleton("parameter-ttsvoicename"); s.AddKeyedSingleton("parameter-unvalidated"); s.AddKeyedSingleton("command-skipall"); s.AddKeyedSingleton("command-skip"); s.AddKeyedSingleton("command-voice"); s.AddKeyedSingleton("command-addttsvoice"); s.AddKeyedSingleton("command-removettsvoice"); s.AddKeyedSingleton("command-refreshttsdata"); s.AddKeyedSingleton("command-obs"); s.AddKeyedSingleton("command-tts"); s.AddKeyedSingleton("command-version"); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(new TwitchBotAuth()); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(new EmoteDatabase()); // OBS websocket s.AddSingleton(sp => 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(); s.AddKeyedSingleton("obs-hello"); s.AddKeyedSingleton("obs-identified"); s.AddKeyedSingleton("obs-requestresponse"); s.AddKeyedSingleton("obs-requestbatchresponse"); s.AddKeyedSingleton("obs-eventmessage"); s.AddKeyedSingleton, OBSHandlerManager>("obs"); s.AddKeyedSingleton, OBSHandlerTypeManager>("obs"); s.AddKeyedSingleton, OBSSocketClient>("obs"); // 7tv websocket s.AddTransient(sp => { var logger = sp.GetRequiredService(); var client = sp.GetRequiredKeyedService>("7tv") as SevenSocketClient; if (client == null) { logger.Error("7tv client == null."); return new ReconnectContext() { SessionId = 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 }; }); s.AddKeyedSingleton("7tv-sevenhello"); s.AddKeyedSingleton("7tv-hello"); s.AddKeyedSingleton("7tv-dispatch"); s.AddKeyedSingleton("7tv-reconnect"); s.AddKeyedSingleton("7tv-error"); s.AddKeyedSingleton("7tv-endofstream"); s.AddKeyedSingleton, SevenHandlerManager>("7tv"); s.AddKeyedSingleton, SevenHandlerTypeManager>("7tv"); s.AddKeyedSingleton, SevenSocketClient>("7tv"); // hermes websocket s.AddKeyedSingleton("hermes-heartbeat"); s.AddKeyedSingleton("hermes-loginack"); s.AddKeyedSingleton("hermes-requestack"); s.AddKeyedSingleton("hermes-error"); s.AddKeyedSingleton, HermesHandlerManager>("hermes"); s.AddKeyedSingleton, HermesHandlerTypeManager>("hermes"); s.AddKeyedSingleton, HermesSocketClient>("hermes"); s.AddHostedService(); using IHost host = builder.Build(); await host.RunAsync();