Пример #1
0
        private bool PlayFanfare(string displayName, string message = emptyString)
        {
            if (playedFanfares.ContainsKey(displayName) && playedFanfares[displayName].DayOfYear == DateTime.Now.DayOfYear)
            {
                return(true);
            }

            bool stillPlaying         = DateTime.Now - lastFanfareActivated < TimeSpan.FromSeconds(lastFanfareDuration);
            bool suppressFanfareToday = message.StartsWith('[');

            if (suppressFanfareToday)
            {
                MarkFanfareAsPlayed(displayName);
                return(true);
            }

            if (stillPlaying || RestrictedSceneIsActive())
            {
                if (!fanfareQueue.Contains(displayName))
                {
                    fanfareQueue.Enqueue(displayName);
                }
                return(false);
            }

            lastFanfareActivated = DateTime.Now;


            // Determine the Fanfare to be played
            FanfareDto fanfare = DetermineFanfareToPlay(displayName);

            if (fanfare != null && (DateTime.Now - fanfare.LastPlayed).TotalHours > 5)
            {
                string sceneName = fanfare.DisplayName;
                if (GetFanfareCount(fanfare.DisplayName) > 1)
                {
                    sceneName += fanfare.Index;
                }

                lastFanfareDuration = fanfare.SecondsLong + 3;

                ActivatingSceneByName(sceneName, "Fanfare");
                try
                {
                    hubConnection.InvokeAsync("SuppressVolume", fanfare.SecondsLong);
                    obsWebsocket.SetCurrentScene(sceneName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Unable to play fanfare: " + sceneName);
                }

                MarkFanfareAsPlayed(fanfare);

                Chat(new VIPGreeting(displayName).Greeting);
            }

            return(true);
        }
Пример #2
0
        void MarkFanfareAsPlayed(FanfareDto fanfare)
        {
            FanfareDto updatedFanfare = fanfares.Where(_ => _.DisplayName == fanfare.DisplayName && _.Index == fanfare.Index && _.Duration == fanfare.Duration).First();

            updatedFanfare.LastPlayed = DateTime.Now;

            WriteFanfareData(FileName.FanfareData_Source, fanfares);

            MarkFanfareAsPlayed(fanfare.DisplayName);
        }
Пример #3
0
 private void MarkFanfareAsPlayed(FanfareDto fanfare)
 {
     if (playedFanfares.ContainsKey(fanfare.DisplayName))
     {
         playedFanfares[fanfare.DisplayName] = DateTime.Now;
     }
     else
     {
         playedFanfares.Add(fanfare.DisplayName, DateTime.Now);
     }
 }
Пример #4
0
        private bool PlayFanfare(FanfareDto fanfare, ChatMessage chatMessage)
        {
            if (fanfare == null)
            {
                return(false);
            }

            if (playedFanfares.ContainsKey(fanfare.DisplayName) && playedFanfares[fanfare.DisplayName].DayOfYear == DateTime.Now.DayOfYear)
            {
                return(true);
            }

            bool stillPlaying         = DateTime.Now - lastFanfareActivated < TimeSpan.FromSeconds(lastFanfareDuration);
            bool suppressFanfareToday = chatMessage != null && chatMessage.Message != null && chatMessage.Message.StartsWith('/');

            if (suppressFanfareToday)
            {
                MarkFanfareAsPlayed(fanfare);
                return(true);
            }

            if (stillPlaying || RestrictedSceneIsActive())
            {
                if (!fanfareQueue.Contains(fanfare))
                {
                    fanfareQueue.Enqueue(fanfare);
                }
                return(false);
            }

            lastFanfareActivated = DateTime.Now;
            lastFanfareDuration  = fanfare.SecondsLong + 3;
            ActivatingSceneByName(fanfare.DisplayName, "Fanfare");
            try
            {
                hubConnection.InvokeAsync("SuppressVolume", fanfare.SecondsLong);
                obsWebsocket.SetCurrentScene(fanfare.DisplayName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to play fanfare: " + fanfare.DisplayName);
            }
            if (fanfare.DisplayName == "SurlyDev")
            {
                GreetSurlyDev();
            }
            else
            {
                GreetVip(fanfare.DisplayName);
            }
            MarkFanfareAsPlayed(fanfare);
            return(true);
        }
Пример #5
0
        void PlayBackloggedFanfare()
        {
            if (fanfareQueue.Count == 0)
            {
                return;
            }
            FanfareDto fanfare = fanfareQueue.Peek();

            if (PlayFanfare(fanfare, null))
            {
                fanfareQueue.Dequeue();
            }
        }
Пример #6
0
        void HandleUserFanfare(ChatMessage chatMessage)
        {
            FanfareDto fanfare = fanfares.FirstOrDefault(x => string.Compare(x.DisplayName, chatMessage.DisplayName, StringComparison.InvariantCultureIgnoreCase) == 0);

            if (fanfare != null)
            {
                PlayFanfare(fanfare, chatMessage);
            }
            else
            {
                PlayBackloggedFanfare();
            }
        }
Пример #7
0
        void HandleUserFanfare(ChatMessage chatMessage)
        {
            FanfareDto fanfare = fanfares.FirstOrDefault(x => x.DisplayName == chatMessage.DisplayName);

            if (fanfare != null)
            {
                PlayFanfare(fanfare, chatMessage);
            }
            else
            {
                PlayBackloggedFanfare();
            }
        }
Пример #8
0
        private bool PlayFanfare(FanfareDto fanfare, ChatMessage chatMessage)
        {
            if (fanfare == null)
            {
                return(false);
            }

            if (playedFanfares.ContainsKey(fanfare.DisplayName) && playedFanfares[fanfare.DisplayName].DayOfYear == DateTime.Now.DayOfYear)
            {
                return(true);
            }

            bool stillPlaying         = DateTime.Now - lastFanfareActivated < TimeSpan.FromSeconds(lastFanfareDuration);
            bool suppressFanfareToday = chatMessage != null && chatMessage.Message != null && chatMessage.Message.StartsWith('[');

            if (suppressFanfareToday)
            {
                MarkFanfareAsPlayed(fanfare);
                return(true);
            }

            if (chatMessage != null && chatMessage.Message.IndexOf('[') >= 0)
            {
            }

            if (stillPlaying || RestrictedSceneIsActive())
            {
                if (!fanfareQueue.Contains(fanfare))
                {
                    fanfareQueue.Enqueue(fanfare);
                }
                return(false);
            }

            lastFanfareActivated = DateTime.Now;
            lastFanfareDuration  = fanfare.SecondsLong + 3;

            string sceneName = fanfare.DisplayName;

            if (fanfare.Count > 1)
            {
                string indexStr = (new Random().Next(fanfare.Count) + 1).ToString();
                sceneName += indexStr;
            }


            ActivatingSceneByName(sceneName, "Fanfare");
            try
            {
                hubConnection.InvokeAsync("SuppressVolume", fanfare.SecondsLong);
                obsWebsocket.SetCurrentScene(sceneName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to play fanfare: " + sceneName);
            }

            Chat(new VIPGreeting(fanfare.DisplayName).Greeting);

            MarkFanfareAsPlayed(fanfare);
            return(true);
        }