예제 #1
0
        private R InitializeCore()
        {
            ConfigManager = ConfigFile.OpenOrCreate(configFilePath) ?? ConfigFile.CreateDummy();

            // TODO: DUMMY REQUESTS
            var webd = ConfigManager.GetDataStruct <WebData>("WebData", true);
            var rmd  = ConfigManager.GetDataStruct <RightsManagerData>("RightsManager", true);

            ConfigManager.GetDataStruct <MainBotData>("MainBot", true);
            YoutubeDlHelper.DataObj = ConfigManager.GetDataStruct <YoutubeFactoryData>("YoutubeFactory", true);
            var pmd = ConfigManager.GetDataStruct <PluginManagerData>("PluginManager", true);

            ConfigManager.GetDataStruct <MediaFactoryData>("MediaFactory", true);
            var hmd = ConfigManager.GetDataStruct <HistoryManagerData>("HistoryManager", true);

            ConfigManager.GetDataStruct <AudioFrameworkData>("AudioFramework", true);
            ConfigManager.GetDataStruct <Ts3FullClientData>("QueryConnection", true);
            ConfigManager.GetDataStruct <PlaylistManagerData>("PlaylistManager", true);
            // END TODO
            ConfigManager.Close();

            Log.Info("[============ TS3AudioBot started =============]");
            Log.Info("[=== Date/Time: {0} {1}", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString());
            Log.Info("[=== Version: {0}", SystemData.AssemblyData);
            Log.Info("[=== Platform: {0}", SystemData.PlattformData);
            Log.Info("[=== Runtime: {0}", SystemData.RuntimeData.FullName);
            Log.Info("[=== Opus: {0}", TS3Client.Audio.Opus.NativeMethods.Info);
            Log.Info("[==============================================]");
            if (SystemData.RuntimeData.Runtime == Runtime.Mono)
            {
                if (SystemData.RuntimeData.SemVer == null)
                {
                    Log.Warn("Could not find your running mono version!");
                    Log.Warn("This version might not work properly.");
                    Log.Warn("If you encounter any problems, try installing the latest mono version by following http://www.mono-project.com/download/");
                }
                else if (SystemData.RuntimeData.SemVer.Major < 5)
                {
                    Log.Error("You are running a mono version below 5.0.0!");
                    Log.Error("This version is not supported and will not work properly.");
                    Log.Error("Install the latest mono version by following http://www.mono-project.com/download/");
                }
            }

            Log.Info("[============ Initializing Modules ============]");
            TS3Client.Messages.Deserializer.OnError += (s, e) => Log.Error(e.ToString());

            Injector = new CoreInjector();

            Injector.RegisterType <Core>();
            Injector.RegisterType <ConfigFile>();
            Injector.RegisterType <CoreInjector>();
            Injector.RegisterType <DbStore>();
            Injector.RegisterType <PluginManager>();
            Injector.RegisterType <CommandManager>();
            Injector.RegisterType <ResourceFactoryManager>();
            Injector.RegisterType <WebManager>();
            Injector.RegisterType <RightsManager>();
            Injector.RegisterType <BotManager>();
            Injector.RegisterType <TokenManager>();

            Injector.RegisterModule(this);
            Injector.RegisterModule(ConfigManager);
            Injector.RegisterModule(Injector);
            Injector.RegisterModule(new DbStore(hmd));
            Injector.RegisterModule(new PluginManager(pmd));
            Injector.RegisterModule(new CommandManager(), x => x.Initialize());
            Injector.RegisterModule(new ResourceFactoryManager(), x => x.Initialize());
            Injector.RegisterModule(new WebManager(webd), x => x.Initialize());
            Injector.RegisterModule(new RightsManager(rmd), x => x.Initialize());
            Injector.RegisterModule(new BotManager());
            Injector.RegisterModule(new TokenManager(), x => x.Initialize());

            if (!Injector.AllResolved())
            {
                Log.Debug("Cyclic core module dependency");
                Injector.ForceCyclicResolve();
                if (!Injector.AllResolved())
                {
                    Log.Error("Missing core module dependency");
                    return("Could not load all core modules");
                }
            }

            Log.Info("[==================== Done ====================]");
            return(R.OkR);
        }
예제 #2
0
        private E <string> Run(bool interactive = false)
        {
            var configResult = ConfRoot.OpenOrCreate(configFilePath);

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

            Config.Deprecated.UpgradeScript.CheckAndUpgrade(config);

            var injector = new CoreInjector();

            injector.RegisterType <Core>();
            injector.RegisterType <ConfRoot>();
            injector.RegisterType <CoreInjector>();
            injector.RegisterType <DbStore>();
            injector.RegisterType <PluginManager>();
            injector.RegisterType <CommandManager>();
            injector.RegisterType <ResourceFactoryManager>();
            injector.RegisterType <WebServer>();
            injector.RegisterType <RightsManager>();
            injector.RegisterType <BotManager>();
            injector.RegisterType <TokenManager>();

            injector.RegisterModule(this);
            injector.RegisterModule(config);
            injector.RegisterModule(injector);
            injector.RegisterModule(new DbStore(config.Db));
            injector.RegisterModule(new PluginManager(config.Plugins));
            injector.RegisterModule(new CommandManager(), x => x.Initialize());
            injector.RegisterModule(new ResourceFactoryManager(config.Factories), x => x.Initialize());
            injector.RegisterModule(new WebServer(config.Web), x => x.Initialize());
            injector.RegisterModule(new RightsManager(config.Rights));
            injector.RegisterModule(new BotManager());
            injector.RegisterModule(new TokenManager(), x => x.Initialize());

            if (!injector.AllResolved())
            {
                Log.Debug("Cyclic core module dependency");
                injector.ForceCyclicResolve();
                if (!injector.AllResolved())
                {
                    Log.Error("Missing core module dependency");
                    return("Could not load all core modules");
                }
            }

            YoutubeDlHelper.DataObj = config.Tools.YoutubeDl;

            Bots.RunBots(interactive);

            return(R.Ok);
        }