Example #1
0
            public void PropagiateLoad(ResourceFactoryManager factoryManager, UserSession session, InvokerData invoker, string url)
            {
                var playlist = factoryManager.LoadPlaylistFrom(url, factory).UnwrapThrow();

                playlist.OwnerUid = invoker.ClientUid;
                session.Set <PlaylistManager, Playlist>(playlist);
            }
        public E <LocalStr> Enqueue(InvokerData invoker, string message, string audioType = null)
        {
            var result = ResourceFactoryManager.Load(message, audioType);

            if (!result)
            {
                return(result.Error);
            }
            return(Enqueue(invoker, new PlaylistItem(result.Value.BaseData)));
        }
        /// <summary>Tries to play the passed link.</summary>
        /// <param name="invoker">The invoker of this resource. Used for responses and association.</param>
        /// <param name="link">The link to resolve, load and play.</param>
        /// <param name="audioType">The associated resource type string to a factory.</param>
        /// <param name="meta">Allows overriding certain settings for the resource. Can be null.</param>
        /// <returns>Ok if successful, or an error message otherwise.</returns>
        public E <LocalStr> Play(InvokerData invoker, string link, string audioType = null, MetaData meta = null)
        {
            var result = ResourceFactoryManager.Load(link, audioType);

            if (!result)
            {
                return(result.Error);
            }
            return(Play(invoker, result.Value, meta ?? new MetaData()));
        }
Example #4
0
        // TODO xml doc doesnt match here
        /// <summary>Playes the passed <see cref="PlayData.PlayResource"/></summary>
        /// <param name="invoker">The invoker of this resource. Used for responses and association.</param>
        /// <param name="audioType">The associated <see cref="AudioType"/> to a factory.</param>
        /// <param name="link">The link to resolve, load and play.</param>
        /// <param name="meta">Allows overriding certain settings for the resource. Can be null.</param>
        /// <returns>Ok if successful, or an error message otherwise.</returns>
        public R Play(InvokerData invoker, string link, AudioType?type = null, MetaData meta = null)
        {
            var result = ResourceFactoryManager.Load(link, type);

            if (!result)
            {
                return(result.Message);
            }
            return(Play(invoker, result.Value, meta ?? new MetaData()));
        }
Example #5
0
        /// <summary>Playes the passed <see cref="AudioResource"/></summary>
        /// <param name="invoker">The invoker of this resource. Used for responses and association.</param>
        /// <param name="ar">The resource to load and play.</param>
        /// <param name="meta">Allows overriding certain settings for the resource. Can be null.</param>
        /// <returns>Ok if successful, or an error message otherwise.</returns>
        public R Play(InvokerData invoker, AudioResource ar, MetaData meta = null)
        {
            var result = ResourceFactoryManager.Load(ar);

            if (!result)
            {
                return(result.Message);
            }
            return(Play(invoker, result.Value, meta ?? new MetaData()));
        }
Example #6
0
        public R Enqueue(InvokerData invoker, string message, AudioType?type = null)
        {
            var result = ResourceFactoryManager.Load(message, type);

            if (!result)
            {
                return(result.Message);
            }
            return(EnqueueInternal(invoker, new PlaylistItem(result.Value.BaseData)));
        }
Example #7
0
            public string PropagiateLoad(ResourceFactoryManager factoryManager, UserSession session, InvokerData invoker, string parameter)
            {
                var result = factoryManager.LoadPlaylistFrom(parameter, factory);

                if (!result)
                {
                    return(result);
                }

                result.Value.CreatorDbId = invoker.DatabaseId;
                session.Set <PlaylistManager, Playlist>(result.Value);
                return("Ok");
            }
        /// <summary>Tries to play the passed <see cref="AudioResource"/></summary>
        /// <param name="invoker">The invoker of this resource. Used for responses and association.</param>
        /// <param name="ar">The resource to load and play.</param>
        /// <param name="meta">Allows overriding certain settings for the resource. Can be null.</param>
        /// <returns>Ok if successful, or an error message otherwise.</returns>
        public E <LocalStr> Play(InvokerData invoker, AudioResource ar, MetaData meta = null)
        {
            if (ar is null)
            {
                throw new ArgumentNullException(nameof(ar));
            }

            var result = ResourceFactoryManager.Load(ar);

            if (!result)
            {
                return(result.Error);
            }
            return(Play(invoker, result.Value, meta ?? new MetaData()));
        }
Example #9
0
        public R Play(InvokerData invoker, uint historyId, MetaData meta = null)
        {
            var getresult = HistoryManager.GetEntryById(historyId);

            if (!getresult)
            {
                return(getresult.Message);
            }

            var loadresult = ResourceFactoryManager.Load(getresult.Value.AudioResource);

            if (!loadresult)
            {
                return(loadresult.Message);
            }

            return(Play(invoker, loadresult.Value, meta ?? new MetaData()));
        }
        public void RemoveBrokenLinks(ResourceFactoryManager resourceFactory)
        {
            const int iterations  = 3;
            var       currentIter = audioLogEntries.FindAll().ToList();

            for (int i = 0; i < iterations; i++)
            {
                Log.Info("Filter iteration {0}", i);
                currentIter = FilterList(resourceFactory, currentIter);
            }

            foreach (var entry in currentIter)
            {
                if (RemoveEntry(entry))
                {
                    Log.Info("Removed: {0} - {1}", entry.Id, entry.AudioResource.ResourceTitle);
                }
            }
        }
        /// <summary>
        /// Goes through a list of <see cref="AudioLogEntry"/> and checks if the contained <see cref="AudioResource"/>
        /// is playable/resolvable.
        /// </summary>
        /// <param name="list">The list to iterate.</param>
        /// <returns>A new list with all working items.</returns>
        private List <AudioLogEntry> FilterList(ResourceFactoryManager resourceFactory, IReadOnlyCollection <AudioLogEntry> list)
        {
            int userNotifyCnt = 0;
            var nextIter      = new List <AudioLogEntry>(list.Count);

            foreach (var entry in list)
            {
                var result = resourceFactory.Load(entry.AudioResource);
                if (!result)
                {
                    Log.Debug("Cleaning: ({0}) Reason: {1}", entry.AudioResource.UniqueId, result.Error);
                    nextIter.Add(entry);
                }

                if (++userNotifyCnt % 100 == 0)
                {
                    Log.Debug("Clean in progress {0}", new string('.', userNotifyCnt / 100 % 10));
                }
            }
            return(nextIter);
        }
        /// <summary>Plays the passed <see cref="PlayResource"/></summary>
        /// <param name="invoker">The invoker of this resource. Used for responses and association.</param>
        /// <param name="play">The associated resource type string to a factory.</param>
        /// <param name="meta">Allows overriding certain settings for the resource.</param>
        /// <returns>Ok if successful, or an error message otherwise.</returns>
        public E <LocalStr> Play(InvokerData invoker, PlayResource play, MetaData meta)
        {
            if (meta.From != PlaySource.FromPlaylist)
            {
                meta.ResourceOwnerUid = invoker.ClientUid;
            }

            var sourceLink = ResourceFactoryManager.RestoreLink(play.BaseData);
            var playInfo   = new PlayInfoEventArgs(invoker, play, meta, sourceLink);

            BeforeResourceStarted?.Invoke(this, playInfo);

            var result = StartResource(play, meta);

            if (!result)
            {
                return(result);
            }

            CurrentPlayData = playInfo;             // TODO meta as readonly
            AfterResourceStarted?.Invoke(this, playInfo);

            return(R.Ok);
        }
Example #13
0
		private bool InitializeBot()
		{
			// Read Config File
			const string configFilePath = "configTS3AudioBot.cfg";
			ConfigFile cfgFile = ConfigFile.Open(configFilePath) ?? ConfigFile.Create(configFilePath) ?? ConfigFile.GetDummy();
			var afd = cfgFile.GetDataStruct<AudioFrameworkData>(typeof(AudioFramework), true);
			var bcd = cfgFile.GetDataStruct<BobControllerData>(typeof(BobController), true);
			var qcd = cfgFile.GetDataStruct<QueryConnectionData>(typeof(QueryConnection), true);
			var hmd = cfgFile.GetDataStruct<HistoryManagerData>(typeof(HistoryManager), true);
			var pmd = cfgFile.GetDataStruct<PluginManagerData>(typeof(PluginManager), true);
			var pld = cfgFile.GetDataStruct<PlaylistManagerData>(typeof(PlaylistManager), true);
			mainBotData = cfgFile.GetDataStruct<MainBotData>(typeof(MainBot), true);
			cfgFile.Close();

			if (consoleOutput)
			{
				Log.RegisterLogger("[%T]%L: %M", "", Console.WriteLine);
			}

			if (writeLog && !string.IsNullOrEmpty(mainBotData.logFile))
			{
				var encoding = new UTF8Encoding(false);
				logStream = new StreamWriter(File.Open(mainBotData.logFile, FileMode.Append, FileAccess.Write, FileShare.Read), encoding);
				Log.RegisterLogger("[%T]%L: %M\n" + (writeLogStack ? "%S\n" : ""), "", (msg) =>
				{
					if (logStream != null)
						try
						{
							logStream.Write(msg);
							logStream.Flush();
						}
						catch (IOException) { }
				});
			}

			Log.Write(Log.Level.Info, "[============ TS3AudioBot started =============]");
			string dateStr = DateTime.Now.ToLongDateString();
			Log.Write(Log.Level.Info, "[=== Date: {0}{1} ===]", new string(' ', Math.Max(0, 32 - dateStr.Length)), dateStr);
			string timeStr = DateTime.Now.ToLongTimeString();
			Log.Write(Log.Level.Info, "[=== Time: {0}{1} ===]", new string(' ', Math.Max(0, 32 - timeStr.Length)), timeStr);
			Log.Write(Log.Level.Info, "[==============================================]");

			Log.Write(Log.Level.Info, "[============ Initializing Commands ===========]");
			CommandManager = new CommandManager();
			CommandManager.RegisterMain(this);

			Log.Write(Log.Level.Info, "[============ Initializing Modules ============]");
			QueryConnection = new QueryConnection(qcd);
			var playlistManager = new PlaylistManager(pld);
			BobController = new BobController(bcd, QueryConnection);
			// old: new VLCConnection(afd.vlcLocation);
			// new: BobController
			AudioFramework = new AudioFramework(afd, BobController, playlistManager);
			SessionManager = new SessionManager();
			HistoryManager = new HistoryManager(hmd);
			PluginManager = new PluginManager(this, pmd);

			Log.Write(Log.Level.Info, "[=========== Initializing Factories ===========]");
			FactoryManager = new ResourceFactoryManager(AudioFramework);
			FactoryManager.DefaultFactorty = new MediaFactory();
			FactoryManager.AddFactory(new YoutubeFactory());
			FactoryManager.AddFactory(new SoundcloudFactory());
			FactoryManager.AddFactory(new TwitchFactory());

			Log.Write(Log.Level.Info, "[=========== Registering callbacks ============]");
			// Inform our HistoryManager when a new resource started successfully
			AudioFramework.OnResourceStarted += HistoryManager.LogAudioResource;
			// Inform the BobClient on start/stop
			AudioFramework.OnResourceStarted += BobController.OnResourceStarted;
			AudioFramework.OnResourceStopped += BobController.OnResourceStopped;
			// In own favor update the own status text to the current song title
			AudioFramework.OnResourceStarted += SongUpdateEvent;
			// Register callback for all messages happening
			QueryConnection.OnMessageReceived += TextCallback;
			// Register callback to remove open private sessions, when user disconnects
			QueryConnection.OnClientDisconnect += (s, e) => SessionManager.RemoveSession(e.InvokerId);


			Log.Write(Log.Level.Info, "[================= Finalizing =================]");
			// Create a default session for all users in all chat
			SessionManager.DefaultSession = new PublicSession(this);
			// Connect the query after everyting is set up
			try { QueryConnection.Connect(); }
			catch (QueryCommandException qcex)
			{
				Log.Write(Log.Level.Error, "There is either a problem with your connection configuration, or the query has not all permissions it needs. ({0})", qcex);
				return false;
			}

			Log.Write(Log.Level.Info, "[============== Connected & Done ==============]");
			return true;
		}