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;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
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;
|
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-07-19 12:56:41 -04:00
|
|
|
|
using static TwitchChatTTS.Chat.Commands.TTSCommands;
|
2024-08-04 19:46:10 -04:00
|
|
|
|
using TwitchChatTTS.Twitch.Socket;
|
|
|
|
|
using TwitchChatTTS.Twitch.Socket.Messages;
|
|
|
|
|
using TwitchChatTTS.Twitch.Socket.Handlers;
|
2024-08-06 15:29:29 -04:00
|
|
|
|
using CommonSocketLibrary.Backoff;
|
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);
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddSingleton(configuration);
|
2024-03-12 14:05:27 -04:00
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
|
var logger = new LoggerConfiguration()
|
2024-06-24 18:11:36 -04:00
|
|
|
|
.MinimumLevel.Verbose()
|
|
|
|
|
.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-08-06 15:29:29 -04:00
|
|
|
|
s.AddSingleton<User>();
|
2024-08-04 19:46:10 -04:00
|
|
|
|
s.AddSingleton<AudioPlaybackEngine>();
|
2024-07-16 00:48:55 -04:00
|
|
|
|
s.AddSingleton<ICallbackManager<HermesRequestData>, CallbackManager<HermesRequestData>>();
|
2024-03-12 14:05:27 -04:00
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddSingleton(new JsonSerializerOptions()
|
2024-06-16 20:19:31 -04:00
|
|
|
|
{
|
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
|
2024-07-19 12:56:41 -04:00
|
|
|
|
s.AddSingleton<IChatCommand, SkipCommand>();
|
|
|
|
|
s.AddSingleton<IChatCommand, VoiceCommand>();
|
|
|
|
|
s.AddSingleton<IChatCommand, RefreshCommand>();
|
2024-08-11 17:22:37 -04:00
|
|
|
|
s.AddSingleton<IChatCommand, NightbotCommand>();
|
2024-07-19 12:56:41 -04:00
|
|
|
|
s.AddSingleton<IChatCommand, OBSCommand>();
|
|
|
|
|
s.AddSingleton<IChatCommand, TTSCommand>();
|
|
|
|
|
s.AddSingleton<IChatCommand, VersionCommand>();
|
|
|
|
|
s.AddSingleton<ICommandBuilder, CommandBuilder>();
|
2024-07-12 13:36:09 -04:00
|
|
|
|
s.AddSingleton<IChatterGroupManager, ChatterGroupManager>();
|
|
|
|
|
s.AddSingleton<IGroupPermissionManager, GroupPermissionManager>();
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddSingleton<ICommandFactory, CommandFactory>();
|
|
|
|
|
s.AddSingleton<ICommandManager, CommandManager>();
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddSingleton<TTSPlayer>();
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddSingleton<IRedemptionManager, 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-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-07-19 12:56:41 -04:00
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, HelloHandler>("obs");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, IdentifiedHandler>("obs");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, RequestResponseHandler>("obs");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, RequestBatchResponseHandler>("obs");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, EventMessageHandler>("obs");
|
|
|
|
|
|
|
|
|
|
s.AddKeyedSingleton<MessageTypeManager<IWebSocketHandler>, OBSMessageTypeManager>("obs");
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddKeyedSingleton<SocketClient<WebSocketMessage>, OBSSocketClient>("obs");
|
|
|
|
|
|
|
|
|
|
// 7tv websocket
|
2024-08-11 17:41:22 -04:00
|
|
|
|
s.AddKeyedSingleton<IBackoff>("7tv", new ExponentialBackoff(1000, 30 * 1000));
|
2024-07-19 12:56:41 -04:00
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, SevenHelloHandler>("7tv");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, DispatchHandler>("7tv");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, ReconnectHandler>("7tv");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, ErrorHandler>("7tv");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, EndOfStreamHandler>("7tv");
|
|
|
|
|
|
|
|
|
|
s.AddKeyedSingleton<MessageTypeManager<IWebSocketHandler>, SevenMessageTypeManager>("7tv");
|
2024-03-12 14:05:27 -04:00
|
|
|
|
s.AddKeyedSingleton<SocketClient<WebSocketMessage>, SevenSocketClient>("7tv");
|
|
|
|
|
|
2024-08-11 17:22:37 -04:00
|
|
|
|
// Nightbot
|
|
|
|
|
s.AddSingleton<NightbotApiClient>();
|
|
|
|
|
|
2024-08-04 19:46:10 -04:00
|
|
|
|
// twitch websocket
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddKeyedSingleton<IBackoff>("twitch", new ExponentialBackoff(1000, 120 * 1000));
|
|
|
|
|
s.AddSingleton<ITwitchConnectionManager, TwitchConnectionManager>();
|
|
|
|
|
s.AddKeyedTransient<SocketClient<TwitchWebsocketMessage>, TwitchWebsocketClient>("twitch", (sp, _) =>
|
|
|
|
|
{
|
|
|
|
|
var factory = sp.GetRequiredService<ITwitchConnectionManager>();
|
|
|
|
|
var client = factory.GetWorkingClient();
|
|
|
|
|
client.Connect().Wait();
|
|
|
|
|
return client;
|
|
|
|
|
});
|
|
|
|
|
s.AddKeyedTransient<SocketClient<TwitchWebsocketMessage>, TwitchWebsocketClient>("twitch-create");
|
2024-08-04 19:46:10 -04:00
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, SessionKeepAliveHandler>("twitch");
|
2024-08-04 19:46:10 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, SessionWelcomeHandler>("twitch");
|
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, SessionReconnectHandler>("twitch");
|
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, NotificationHandler>("twitch");
|
|
|
|
|
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelAdBreakHandler>("twitch-notifications");
|
2024-08-04 19:46:10 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelBanHandler>("twitch-notifications");
|
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelChatMessageHandler>("twitch-notifications");
|
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelChatClearHandler>("twitch-notifications");
|
2024-08-07 18:01:04 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelChatClearUserHandler>("twitch-notifications");
|
2024-08-04 19:46:10 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelChatDeleteMessageHandler>("twitch-notifications");
|
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelCustomRedemptionHandler>("twitch-notifications");
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelFollowHandler>("twitch-notifications");
|
2024-08-07 18:01:04 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelRaidHandler>("twitch-notifications");
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelResubscriptionHandler>("twitch-notifications");
|
2024-08-04 19:46:10 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelSubscriptionHandler>("twitch-notifications");
|
2024-08-06 15:29:29 -04:00
|
|
|
|
s.AddKeyedSingleton<ITwitchSocketHandler, ChannelSubscriptionGiftHandler>("twitch-notifications");
|
2024-08-04 19:46:10 -04:00
|
|
|
|
|
2024-03-15 08:27:35 -04:00
|
|
|
|
// hermes websocket
|
2024-08-11 17:41:22 -04:00
|
|
|
|
s.AddKeyedSingleton<IBackoff>("hermes", new ExponentialBackoff(1000, 15 * 1000));
|
2024-07-19 12:56:41 -04:00
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, HeartbeatHandler>("hermes");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, LoginAckHandler>("hermes");
|
|
|
|
|
s.AddKeyedSingleton<IWebSocketHandler, RequestAckHandler>("hermes");
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
2024-07-19 12:56:41 -04:00
|
|
|
|
s.AddKeyedSingleton<MessageTypeManager<IWebSocketHandler>, HermesMessageTypeManager>("hermes");
|
2024-03-15 08:27:35 -04:00
|
|
|
|
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();
|