Example #1
0
        private E <string> Run(ParameterData setup)
        {
            var configResult = ConfRoot.OpenOrCreate(configFilePath);

            if (!configResult.Ok)
            {
                return("Could not create config");
            }
            ConfRoot config = configResult.Value;

            Config.Deprecated.UpgradeScript.CheckAndUpgrade(config);
            ConfigUpgrade2.Upgrade(config.Configs.BotsPath.Value);
            config.Save();

            var builder = new DependencyBuilder(injector);

            builder.AddModule(this);
            builder.AddModule(config);
            builder.AddModule(injector);
            builder.AddModule(config.Db);
            builder.RequestModule <SystemMonitor>();
            builder.RequestModule <DbStore>();
            builder.AddModule(config.Plugins);
            builder.RequestModule <PluginManager>();
            builder.AddModule(config.Web);
            builder.AddModule(config.Web.Interface);
            builder.AddModule(config.Web.Api);
            builder.RequestModule <WebServer>();
            builder.AddModule(config.Rights);
            builder.RequestModule <RightsManager>();
            builder.RequestModule <BotManager>();
            builder.RequestModule <TokenManager>();
            builder.RequestModule <CommandManager>();
            builder.AddModule(config.Factories);
            builder.RequestModule <SpotifyApi>();
            builder.RequestModule <ResourceResolver>();
            builder.RequestModule <Stats>();
            builder.AddModule(config.Tools.Librespot);

            if (!builder.Build())
            {
                Log.Error("Missing core module dependency");
                return("Could not load all core modules");
            }

            YoutubeDlHelper.DataObj = config.Tools.YoutubeDl;

            builder.GetModule <SystemMonitor>().StartTimedSnapshots();
            builder.GetModule <CommandManager>().RegisterCollection(MainCommands.Bag);
            builder.GetModule <RightsManager>().CreateConfigIfNotExists(setup.Interactive);
            builder.GetModule <BotManager>().RunBots(setup.Interactive);
            builder.GetModule <WebServer>().StartWebServer();
            builder.GetModule <Stats>().StartTimer(setup.SendStats);

            return(R.Ok);
        }
Example #2
0
        public async Task Run(ParameterData setup)
        {
            scheduler.VerifyOwnThread();

            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            TaskScheduler.UnobservedTaskException      += UnobservedTaskExceptionHandler;
            Console.CancelKeyPress += ConsoleInterruptHandler;

            var config = ConfRoot.OpenOrCreate(configFilePath);

            if (config is null)
            {
                throw new Exception("Could not create config");
            }
            ConfigUpgrade2.Upgrade(config.Configs.BotsPath.Value);
            config.Save();

            var builder = new DependencyBuilder(injector);

            injector.AddModule(this);
            injector.AddModule(scheduler);
            injector.AddModule(injector);
            injector.AddModule(config);
            injector.AddModule(config.Db);
            injector.AddModule(config.Plugins);
            injector.AddModule(config.Web);
            injector.AddModule(config.Web.Interface);
            injector.AddModule(config.Web.Api);
            injector.AddModule(config.Rights);
            injector.AddModule(config.Factories);
            builder.RequestModule <SystemMonitor>();
            builder.RequestModule <DbStore>();
            builder.RequestModule <PluginManager>();
            builder.RequestModule <WebServer>();
            builder.RequestModule <RightsManager>();
            builder.RequestModule <BotManager>();
            builder.RequestModule <TokenManager>();
            builder.RequestModule <CommandManager>();
            builder.RequestModule <ResourceResolver>();
            builder.RequestModule <Stats>();

            if (!builder.Build())
            {
                throw new Exception("Could not load all core modules");
            }

            Upgrader.PerformUpgrades(injector);
            YoutubeDlHelper.DataObj = config.Tools.YoutubeDl;

            injector.GetModuleOrThrow <CommandManager>().RegisterCollection(MainCommands.Bag);
            injector.GetModuleOrThrow <RightsManager>().CreateConfigIfNotExists(setup.Interactive);
            injector.GetModuleOrThrow <WebServer>().StartWebServer();
            injector.GetModuleOrThrow <Stats>().StartTimer(setup.SendStats);
            await injector.GetModuleOrThrow <BotManager>().RunBots(setup.Interactive);
        }
Example #3
0
        public static ParameterData ReadParameter(string[] args)
        {
            var data = new ParameterData {
                Exit = ExitType.No,
            };

            ParameterData Cancel()
            {
                data.Exit = ExitType.Immediately; return(data);
            }

            for (int i = 0; i < args.Length; i++)
            {
                // -i --interactive, minimal ui/console tool to execute basic stuff like
                // create bot, excute commands

                // --setup setup the entire environment (-y to skip for user input?)
                // > mono (apt-get/upgrade to latest version, + package upgade)
                // > libopus (self-compile/apt-get)
                // > ffmpeg (apt-get)
                // > youtube-dl (repo/apt-get)
                // > check NLog.config exists
                // > Ask for Uid/Group id to insert into rigths.toml template
                // > Crete new bot (see --new-bot)

                // --new-bot name={} address={} server_password={} ?

                switch (args[i])
                {
                case "?":
                case "-h":
                case "--help":
                    Console.WriteLine(" --config -c <file>  Specifies the path to the config file.");
                    Console.WriteLine(" --version -V        Gets the bot version.");
                    Console.WriteLine(" --skip-checks       Skips checking the system for all required tools.");
                    Console.WriteLine(" --hide-banner       Does not print the version information header.");
                    Console.WriteLine(" --non-interactive   Disables console prompts from setup tools.");
                    Console.WriteLine(" --help -h           Prints this help...");
                    return(Cancel());

                case "-c":
                case "--config":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("No config file specified after \"{0}\"", args[i]);
                        return(Cancel());
                    }
                    data.ConfigFile = args[++i];
                    break;

                case "--skip-checks":
                    data.SkipVerifications = true;
                    break;

                case "--hide-banner":
                    data.HideBanner = true;
                    break;

                case "--non-interactive":
                    data.NonInteractive = true;
                    break;

                case "-V":
                case "--version":
                    Console.WriteLine(SystemData.AssemblyData.ToLongString());
                    return(Cancel());

                default:
                    Console.WriteLine("Unrecognized parameter: {0}", args[i]);
                    return(Cancel());
                }
            }
            return(data);
        }
Example #4
0
        public static ParameterData ReadParameter(string[] args)
        {
            var data = new ParameterData();

            ParameterData Cancel()
            {
                data.Exit = ExitType.Immediately; return(data);
            }

            for (int i = 0; i < args.Length; i++)
            {
                // -i --interactive, minimal ui/console tool to execute basic stuff like
                // create bot, excute commands

                // --setup setup the entire environment (-y to skip for user input?)
                // > mono (apt-get/upgrade to latest version, + package upgade)
                // > libopus (self-compile/apt-get)
                // > ffmpeg (apt-get)
                // > youtube-dl (repo/apt-get)
                // > check NLog.config exists
                // > Crete new bot (see --new-bot)

                // --new-bot name={} address={} server_password={} ?

                switch (args[i])
                {
                case "?":
                case "-h":
                case "--help":
                    Console.WriteLine(" --help -h           Prints this help...");
                    Console.WriteLine(" --config -c <file>  Specifies the path to the config file.");
                    Console.WriteLine(" --version -V        Gets the bot version.");
                    Console.WriteLine(" --skip-checks       Skips checking the system for all required tools.");
                    Console.WriteLine(" --hide-banner       Does not print the version information header.");
                    Console.WriteLine(" --non-interactive   Disables console prompts from setup tools.");
                    Console.WriteLine(" --stats-example     Shows you what the bot sends to the global stats tracker.");
                    Console.WriteLine(" --stats-disabled    Disables sending to the global stats tracker.");
                    return(Cancel());

                case "-c":
                case "--config":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("No config file specified after \"{0}\"", args[i]);
                        return(Cancel());
                    }
                    data.ConfigFile = args[++i];
                    break;

                case "--skip-checks":
                    data.SkipVerifications = true;
                    break;

                case "--hide-banner":
                    data.HideBanner = true;
                    break;

                case "--non-interactive":
                    data.Interactive = false;
                    break;

                case "--no-llgc":
                    data.Llgc = false;
                    break;

                case "--stats-example":
                    Console.WriteLine("The bot will contribute to the stats counter about once per day.");
                    Console.WriteLine("We do NOT store any IP or identifiable information.");
                    Console.WriteLine("Please keep this feature enabled to help us improve and grow.");
                    Console.WriteLine("An example stats packet looks like this:");
                    Console.WriteLine(Stats.CreateExample());
                    return(Cancel());

                case "--stats-disabled":
                    data.SendStats = false;
                    break;

                case "-V":
                case "--version":
                    Console.WriteLine(SystemData.AssemblyData.ToLongString());
                    return(Cancel());

                default:
                    Console.WriteLine("Unrecognized parameter: {0}", args[i]);
                    return(Cancel());
                }
            }
            return(data);
        }