Ejemplo n.º 1
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Starting up...");
            if (args.Length > 1)
            {
                Console.WriteLine("This program does not support command line arguments.");
            }

            if (!File.Exists(ConfigPath))
            {
                CreateConfigQuit();
                return;
            }

            var json   = File.ReadAllText(ConfigPath);
            var config = JsonSerializer.Deserialize <CrossBotConfig>(json);

            if (config == null)
            {
                Console.WriteLine("Failed to deserialize configuration file.");
                WaitKeyExit();
                return;
            }

            SaveConfig(config);
            await BotRunner.RunFrom(config, CancellationToken.None).ConfigureAwait(false);

            WaitKeyExit();
        }
Ejemplo n.º 2
0
        private static async Task Main(string[] args)
        {
            string configPath;

            Console.WriteLine("Starting up...");
            if (args.Length > 0)
            {
                if (args.Length > 1)
                {
                    Console.WriteLine("Too many arguments supplied and will be ignored.");
                    configPath = DefaultConfigPath;
                }
                else
                {
                    configPath = args[0];
                }
            }
            else
            {
                configPath = DefaultConfigPath;
            }

            if (!File.Exists(configPath))
            {
                CreateConfigQuit(configPath);
                return;
            }

            if (!File.Exists(DefaultTwitchPath))
            {
                SaveConfig(new TwitchConfig(), DefaultTwitchPath);
            }

            if (!File.Exists(DefaultSocketServerAPIPath))
            {
                SaveConfig(new SocketAPI.SocketAPIServerConfig(), DefaultSocketServerAPIPath);
            }

            var json   = File.ReadAllText(configPath);
            var config = JsonSerializer.Deserialize <CrossBotConfig>(json);

            if (config == null)
            {
                Console.WriteLine("Failed to deserialize configuration file.");
                WaitKeyExit();
                return;
            }

            json = File.ReadAllText(DefaultTwitchPath);
            var twitchConfig = JsonSerializer.Deserialize <TwitchConfig>(json);

            if (twitchConfig == null)
            {
                Console.WriteLine("Failed to deserialize twitch configuration file.");
                WaitKeyExit();
                return;
            }

            json = File.ReadAllText(DefaultSocketServerAPIPath);
            var serverConfig = JsonSerializer.Deserialize <SocketAPI.SocketAPIServerConfig>(json);

            if (serverConfig == null)
            {
                Console.WriteLine("Failed to deserialize Socket API Server configuration file.");
                WaitKeyExit();
                return;
            }

            SaveConfig(config, configPath);
            SaveConfig(twitchConfig, DefaultTwitchPath);
            SaveConfig(serverConfig, DefaultSocketServerAPIPath);

            SocketAPI.SocketAPIServer server = SocketAPI.SocketAPIServer.shared;
            _ = server.Start(serverConfig);

            await BotRunner.RunFrom(config, CancellationToken.None, twitchConfig).ConfigureAwait(false);

            WaitKeyExit();
        }