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 Microsoft.Extensions.Logging; 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; // 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) { foreach (var key in redeemKeys) { if (key != key.ToLower() && configuration.Twitch?.Redeems != null) configuration.Twitch.Redeems.Add(key.ToLower(), configuration.Twitch.Redeems[key]); } } s.AddSingleton(configuration); s.AddLogging(); 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.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(sp => { var hermes = sp.GetRequiredService(); var task = hermes.FetchTwitchBotToken(); task.Wait(); return task.Result; }); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(sp => { var api = sp.GetRequiredService(); var task = api.GetSevenEmotes(); task.Wait(); return task.Result; }); s.AddSingleton(sp => { if (!string.IsNullOrWhiteSpace(configuration.Emotes?.CounterFilePath) && File.Exists(configuration.Emotes.CounterFilePath.Trim())) return deserializer.Deserialize(File.ReadAllText(configuration.Emotes.CounterFilePath.Trim())); return new EmoteCounter(); }); // 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.AddKeyedSingleton("obs-hello"); s.AddKeyedSingleton("obs-identified"); s.AddKeyedSingleton("obs-requestresponse"); 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.LogError("7tv client == null."); return new ReconnectContext() { SessionId = null }; } if (client.ConnectionDetails == null) { logger.LogError("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();