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.Managers; using TwitchChatTTS.Hermes.Socket.Handlers; using TwitchChatTTS.Hermes.Socket; using TwitchChatTTS.Hermes.Socket.Managers; using TwitchChatTTS.Chat.Commands; using System.Text.Json; using Serilog; using Serilog.Events; using Serilog.Sinks.SystemConsole.Themes; using TwitchChatTTS.Twitch.Redemptions; using TwitchChatTTS.Chat.Groups.Permissions; using TwitchChatTTS.Chat.Groups; using TwitchChatTTS.Chat.Emotes; using HermesSocketLibrary.Requests.Callbacks; using static TwitchChatTTS.Chat.Commands.TTSCommands; using TwitchChatTTS.Twitch.Socket; using TwitchChatTTS.Twitch.Socket.Messages; using TwitchChatTTS.Twitch.Socket.Handlers; using CommonSocketLibrary.Backoff; using TwitchChatTTS.Chat.Speech; using TwitchChatTTS.Chat.Messaging; using TwitchChatTTS.Chat.Observers; using TwitchChatTTS.Chat.Commands.Limits; using TwitchChatTTS.Hermes.Socket.Requests; using TwitchChatTTS.Bus; using TwitchChatTTS.Veadotube; using TwitchChatTTS.Veadotube.Handlers; // 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() .IgnoreUnmatchedProperties() .WithNamingConvention(HyphenatedNamingConvention.Instance) .Build(); var configContent = File.ReadAllText("tts.config.yml"); var configuration = deserializer.Deserialize(configContent); s.AddSingleton(configuration); var logger = new LoggerConfiguration() .MinimumLevel.Verbose() .MinimumLevel.Override("mariuszgromada", LogEventLevel.Error) .Enrich.FromLogContext() .WriteTo.File("logs/log-.log", restrictedToMinimumLevel: LogEventLevel.Debug, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 3) .WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Information, theme: SystemConsoleTheme.Colored) .CreateLogger(); s.AddSerilog(logger); s.AddSingleton(); s.AddSingleton(); s.AddSingleton, CallbackManager>(); s.AddSingleton(new JsonSerializerOptions() { PropertyNameCaseInsensitive = false, PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower }); // Command parameters s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddTransient(); // Request acks s.AddSingleton(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddTransient(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton, UsagePolicy>(); s.AddSingleton(); s.AddSingleton(); // OBS websocket s.AddKeyedSingleton("obs"); s.AddKeyedSingleton("obs"); s.AddKeyedSingleton("obs"); s.AddKeyedSingleton("obs"); s.AddKeyedSingleton("obs"); s.AddKeyedSingleton, OBSMessageTypeManager>("obs"); s.AddKeyedSingleton, OBSSocketClient>("obs"); // 7tv websocket s.AddKeyedSingleton("7tv", new ExponentialBackoff(1000, 30 * 1000)); s.AddKeyedSingleton("7tv"); s.AddKeyedSingleton("7tv"); s.AddKeyedSingleton("7tv"); s.AddKeyedSingleton("7tv"); s.AddKeyedSingleton("7tv"); s.AddKeyedSingleton, SevenMessageTypeManager>("7tv"); s.AddKeyedSingleton, SevenSocketClient>("7tv"); // Veadotube s.AddKeyedSingleton("veadotube"); s.AddKeyedSingleton, VeadoMessageTypeManager>("veadotube"); s.AddKeyedSingleton, VeadoSocketClient>("veadotube"); // Nightbot s.AddSingleton(); // twitch websocket s.AddKeyedSingleton("twitch", new ExponentialBackoff(1000, 120 * 1000)); s.AddSingleton(); s.AddKeyedTransient, TwitchWebsocketClient>("twitch", (sp, _) => { var factory = sp.GetRequiredService(); var client = factory.GetWorkingClient(); client.Connect().Wait(); return client; }); s.AddKeyedTransient, TwitchWebsocketClient>("twitch-create"); s.AddKeyedSingleton("twitch"); s.AddKeyedSingleton("twitch"); s.AddKeyedSingleton("twitch"); s.AddKeyedSingleton("twitch"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); s.AddKeyedSingleton("twitch-notifications"); // hermes websocket s.AddKeyedSingleton("hermes", new ExponentialBackoff(1000, 15 * 1000)); s.AddKeyedSingleton("hermes"); s.AddKeyedSingleton("hermes"); s.AddKeyedSingleton("hermes"); s.AddKeyedSingleton, HermesMessageTypeManager>("hermes"); s.AddKeyedSingleton, HermesSocketClient>("hermes"); s.AddSingleton(); s.AddHostedService(); s.AddHostedService(p => p.GetRequiredService()); s.AddHostedService(); using IHost host = builder.Build(); await host.RunAsync();