Пример #1
0
        public R InitializeBot()
        {
            Log.Info("Bot connecting...");

            // Read Config File
            var afd  = Config.GetDataStruct <AudioFrameworkData>("AudioFramework", true);
            var tfcd = Config.GetDataStruct <Ts3FullClientData>("QueryConnection", true);
            var hmd  = Config.GetDataStruct <HistoryManagerData>("HistoryManager", true);
            var pld  = Config.GetDataStruct <PlaylistManagerData>("PlaylistManager", true);

            mainBotData = Config.GetDataStruct <MainBotData>("MainBot", true);

            AudioValues.audioFrameworkData = afd;

            Injector.RegisterType <Bot>();
            Injector.RegisterType <BotInjector>();
            Injector.RegisterType <PlaylistManager>();
            Injector.RegisterType <TeamspeakControl>();
            Injector.RegisterType <SessionManager>();
            Injector.RegisterType <HistoryManager>();
            Injector.RegisterType <PlayManager>();
            Injector.RegisterType <IPlayerConnection>();
            Injector.RegisterType <ITargetManager>();
            Injector.RegisterType <Ts3BaseFunctions>();

            Injector.RegisterModule(this);
            Injector.RegisterModule(Injector);
            Injector.RegisterModule(new PlaylistManager(pld));
            var teamspeakClient = new Ts3Full(tfcd);

            Injector.RegisterModule(teamspeakClient);
            Injector.RegisterModule(teamspeakClient.GetLowLibrary <Ts3FullClient>());
            Injector.RegisterModule(new SessionManager());
            HistoryManager historyManager = null;

            if (hmd.EnableHistory)
            {
                Injector.RegisterModule(historyManager = new HistoryManager(hmd), x => x.Initialize());
            }
            Injector.RegisterModule(new PlayManager());
            Injector.RegisterModule(teamspeakClient.TargetPipe);

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

            PlayerConnection.OnSongEnd        += PlayManager.SongStoppedHook;
            PlayManager.BeforeResourceStarted += BeforeResourceStarted;
            // In own favor update the own status text to the current song title
            PlayManager.AfterResourceStarted += LoggedUpdateBotStatus;
            PlayManager.AfterResourceStopped += LoggedUpdateBotStatus;
            // Log our resource in the history
            if (hmd.EnableHistory)
            {
                PlayManager.AfterResourceStarted += (s, e) => historyManager.LogAudioResource(new HistorySaveData(e.PlayResource.BaseData, e.Owner));
            }
            // Update our thumbnail
            PlayManager.AfterResourceStarted += GenerateStatusImage;
            PlayManager.AfterResourceStopped += GenerateStatusImage;
            // Register callback for all messages happening
            QueryConnection.OnMessageReceived += TextCallback;
            // Register callback to remove open private sessions, when user disconnects
            QueryConnection.OnClientDisconnect += OnClientDisconnect;
            QueryConnection.OnBotDisconnect    += (s, e) => Dispose();
            QueryConnection.OnBotConnected     += OnBotConnected;
            BadgesString = tfcd.ClientBadges;

            // Connect the query after everyting is set up
            try { QueryConnection.Connect(); }
            catch (Ts3Exception qcex)
            {
                Log.Info(qcex, "There is either a problem with your connection configuration, or the query has not all permissions it needs.");
                return("Query error");
            }
            return(R.OkR);
        }
Пример #2
0
        public E <string> InitializeBot()
        {
            Log.Info("Bot ({0}) connecting to \"{1}\"", Id, config.Connect.Address);

            // Registering config changes
            config.CommandMatcher.Changed += (s, e) =>
            {
                var newMatcher = Filter.GetFilterByName(e.NewValue);
                if (newMatcher.Ok)
                {
                    Filter.Current = newMatcher.Value;
                }
            };
            config.Language.Changed += (s, e) =>
            {
                var langResult = LocalizationManager.LoadLanguage(e.NewValue);
                if (!langResult.Ok)
                {
                    Log.Error("Failed to load language file ({0})", langResult.Error);
                }
            };

            Injector.RegisterType <Bot>();
            Injector.RegisterType <ConfBot>();
            Injector.RegisterType <BotInjector>();
            Injector.RegisterType <PlaylistManager>();
            Injector.RegisterType <Ts3Client>();
            Injector.RegisterType <SessionManager>();
            Injector.RegisterType <HistoryManager>();
            Injector.RegisterType <PlayManager>();
            Injector.RegisterType <IPlayerConnection>();
            Injector.RegisterType <IVoiceTarget>();
            Injector.RegisterType <Ts3BaseFunctions>();
            Injector.RegisterType <Filter>();

            Injector.RegisterModule(this);
            Injector.RegisterModule(config);
            Injector.RegisterModule(Injector);
            Injector.RegisterModule(new PlaylistManager(config.Playlists));
            var teamspeakClient = new Ts3Client(config);

            Injector.RegisterModule(teamspeakClient);
            Injector.RegisterModule(teamspeakClient.TsFullClient);
            Injector.RegisterModule(new SessionManager());
            HistoryManager historyManager = null;

            if (config.History.Enabled)
            {
                Injector.RegisterModule(historyManager = new HistoryManager(config.History), x => x.Initialize());
            }
            Injector.RegisterModule(new PlayManager());
            Injector.RegisterModule(teamspeakClient.TargetPipe);

            var filter = Filter.GetFilterByName(config.CommandMatcher);

            Injector.RegisterModule(new Filter {
                Current = filter.OkOr(Filter.DefaultAlgorithm)
            });
            if (!filter.Ok)
            {
                Log.Warn("Unknown command_matcher config. Using default.");
            }

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

            PlayerConnection.OnSongEnd        += PlayManager.SongStoppedHook;
            PlayManager.BeforeResourceStarted += BeforeResourceStarted;
            // In own favor update the own status text to the current song title
            PlayManager.AfterResourceStarted += LoggedUpdateBotStatus;
            PlayManager.AfterResourceStopped += LoggedUpdateBotStatus;
            // Log our resource in the history
            if (historyManager != null)
            {
                PlayManager.AfterResourceStarted += (s, e) => historyManager.LogAudioResource(new HistorySaveData(e.PlayResource.BaseData, e.Invoker.ClientUid));
            }
            // Update our thumbnail
            PlayManager.AfterResourceStarted += GenerateStatusImage;
            PlayManager.AfterResourceStopped += GenerateStatusImage;
            // Register callback for all messages happening
            ClientConnection.OnMessageReceived += TextCallback;
            // Register callback to remove open private sessions, when user disconnects
            ClientConnection.OnClientDisconnect += OnClientDisconnect;
            ClientConnection.OnBotConnected     += OnBotConnected;
            ClientConnection.OnBotDisconnect    += OnBotDisconnect;
            BadgesString = config.Connect.Badges;

            // Connect the query after everyting is set up
            return(ClientConnection.Connect());
        }