/// <summary>
        /// Move song to top
        /// </summary>
        /// <param name="p_Service">Chat service</param>
        /// <param name="p_Message">Chat message</param>
        /// <param name="p_ID">ID of the BSR</param>
        private void Command_MoveToTop(IChatService p_Service, IChatMessage p_Message, string p_ID)
        {
            if (!HasPower(p_Message.Sender))
            {
                SendChatMessage($"@{p_Message.Sender.UserName} You have no power here!");
                return;
            }

            string l_Key = p_ID.ToLower();

            lock (SongQueue)
            {
                var l_BeatMap = SongQueue.Where(x => x.BeatMap.Key.ToLower() == l_Key).FirstOrDefault();
                if (l_BeatMap != null)
                {
                    SongQueue.Remove(l_BeatMap);
                    SongQueue.Insert(0, l_BeatMap);

                    SendChatMessage($"@{p_Message.Sender.UserName} (bsr {l_BeatMap.BeatMap.Key}) {l_BeatMap.BeatMap.Metadata.SongName} / {l_BeatMap.BeatMap.Metadata.LevelAuthorName} is now on top of queue!");

                    /// Update request manager
                    OnQueueChanged();

                    return;
                }

                SendChatMessage($"@{p_Message.Sender.UserName} No song in queue found with the key \"{l_Key}\"!");
            }
        }
Exemplo n.º 2
0
        public void Insert_InsertingAnElement_ShouldEqual()
        {
            //prepare

            ISongQueue queue = new SongQueue();
            Song       song  = new Song
            {
                Id   = 30,
                Name = "For Whom the Bell Tolls"
            };
            //list 3
            List <Song> list = new List <Song>
            {
                new Song
                {
                    Id   = 11,
                    Name = "Kitty Later"
                },
                new Song
                {
                    Id   = 12,
                    Name = "Ashtray Heart"
                },
                song,
                new Song
                {
                    Id   = 13,
                    Name = "Battle for the Sun"
                },
                new Song
                {
                    Id   = 14,
                    Name = "For What It's worth"
                },
                new Song
                {
                    Id   = 15,
                    Name = "Devil in the Details"
                }
            };



            //act
            queue.Set(third);
            _ = queue.Next; //doing it two times, because for the first time "next" takes the first of the queue
            _ = queue.Next;
            queue.Insert(song);

            Song[] expected = list.ToArray();
            Song[] actual   = queue.Content.ToArray();
            //asserting

            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        public void Set_ShouldEqual()
        {
            ISongQueue queue = new SongQueue();

            queue.Insert(third);

            queue.Set(first);

            Song[] expected = first.ToArray();
            Song[] actual   = queue.Content.ToArray();

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void Insert_InsertRange_ShouldEqual()
        {
            //prepare

            ISongQueue  queue        = new SongQueue();
            List <Song> toBeInserted = new List <Song>
            {
                new Song
                {
                    Id   = 31,
                    Name = "Getting Even"
                },
                new Song
                {
                    Id   = 32,
                    Name = "Rituals"
                }
            };

            List <Song> list = new List <Song>
            {
                new Song
                {
                    Id   = 6,
                    Name = "Hold on to Me"
                },
                new Song
                {
                    Id   = 7,
                    Name = "Rob the Bank"
                },
                new Song
                {
                    Id   = 8,
                    Name = "A Million Little Places"
                },

                toBeInserted[0],
                toBeInserted[1],

                new Song
                {
                    Id   = 9,
                    Name = "Exit Wounds"
                },
                new Song
                {
                    Id   = 10,
                    Name = "Purify"
                }
            };

            queue.Set(second);

            //act

            _ = queue.Next;
            _ = queue.Next;
            _ = queue.Next;

            queue.Insert(toBeInserted);

            //assert

            Song[] expected = list.ToArray();
            Song[] actual   = queue.Content.ToArray();

            Assert.Equal(expected, actual);
        }
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Handle BSR command
        /// </summary>
        /// <param name="p_Service">Chat service</param>
        /// <param name="p_Message">Chat message</param>
        /// <param name="p_ID">ID of the BSR</param>
        private void Command_BSR(IChatService p_Service, IChatMessage p_Message, string p_ID, bool p_ModeratorAddCommand, bool p_ModeratorAddToTop)
        {
            bool l_IsModerator = HasPower(p_Message.Sender);

            if (p_ModeratorAddCommand && !l_IsModerator)
            {
                SendChatMessage($"@{p_Message.Sender.UserName} You have no power here!");
                return;
            }

            if (!QueueOpen && !(l_IsModerator && p_ModeratorAddCommand))
            {
                SendChatMessage($"@{p_Message.Sender.UserName} the queue is closed!");
                return;
            }

            string l_Key = p_ID.ToLower();

            if (!OnlyHexInString(l_Key))
            {
                _ = m_BeatSaver.Search(l_Key).ContinueWith((p_SearchTaskResult) =>
                {
                    if (p_SearchTaskResult.Result == null || p_SearchTaskResult.Result.Docs.Count == 0)
                    {
                        SendChatMessage($"@{p_Message.Sender.UserName} your search \"{l_Key}\" produced 0 results!");
                        return;
                    }

                    var l_Docs     = p_SearchTaskResult.Result.Docs;
                    string l_Reply = $"@{p_Message.Sender.UserName} your search \"{l_Key}\" produced {l_Docs.Count} results : ";

                    int l_I = 0;
                    for (; l_I < l_Docs.Count && l_I < 4; ++l_I)
                    {
                        if (l_I != 0)
                        {
                            l_Reply += ", ";
                        }

                        l_Reply += " (!bsr " + l_Docs[l_I].Key + ") " + l_Docs[l_I].Name;
                    }

                    if (l_I < l_Docs.Count)
                    {
                        l_Reply += "...";
                    }

                    SendChatMessage(l_Reply);
                });

                return;
            }

            var l_UserRequestCount = 0;

            /// Check if blacklisted
            if (!(l_IsModerator && p_ModeratorAddCommand))
            {
                lock (SongBlackList)
                {
                    var l_BeatMap = SongBlackList.Where(x => x.BeatMap.Key.ToLower() == l_Key).FirstOrDefault();
                    if (l_BeatMap != null)
                    {
                        SendChatMessage($"@{p_Message.Sender.UserName} (bsr {l_BeatMap.BeatMap.Key}) {l_BeatMap.BeatMap.Metadata.SongName} / {l_BeatMap.BeatMap.Metadata.LevelAuthorName} is blacklisted!");
                        return;
                    }
                }
            }

            /// Check if already in queue
            lock (SongQueue)
            {
                var l_BeatMap = SongQueue.Where(x => x.BeatMap.Key.ToLower() == l_Key).FirstOrDefault();
                if (l_BeatMap != null)
                {
                    SendChatMessage($"@{p_Message.Sender.UserName} (bsr {l_BeatMap.BeatMap.Key}) {l_BeatMap.BeatMap.Metadata.SongName} / {l_BeatMap.BeatMap.Metadata.LevelAuthorName} is already in queue!");
                    return;
                }

                l_UserRequestCount = SongQueue.Where(x => x.RequesterName == p_Message.Sender.UserName).Count();
            }

            string l_NamePrefix = "";

            /// Handle request limits
            if (p_Service is BeatSaberPlusChatCore.Services.Twitch.TwitchService)
            {
                var l_TwitchUser = p_Message.Sender as BeatSaberPlusChatCore.Models.Twitch.TwitchUser;

                (int, string)l_Limit = (Config.ChatRequest.UserMaxRequest, "Users");

                if (l_TwitchUser.IsVip && !l_TwitchUser.IsSubscriber)
                {
                    l_Limit = (l_Limit.Item1 + Config.ChatRequest.VIPBonusRequest, "VIPs");
                }
                if (l_TwitchUser.IsSubscriber && !l_TwitchUser.IsVip)
                {
                    l_Limit = (l_Limit.Item1 + Config.ChatRequest.SubscriberBonusRequest, "Subscribers");
                }
                if (l_TwitchUser.IsSubscriber && l_TwitchUser.IsVip)
                {
                    l_Limit = (l_Limit.Item1 + Config.ChatRequest.VIPBonusRequest + Config.ChatRequest.SubscriberBonusRequest, "VIP Subscribers");
                }
                if (l_TwitchUser.IsModerator || l_TwitchUser.IsBroadcaster)
                {
                    l_Limit = (1000, "Moderators");
                }

                if (l_TwitchUser.IsModerator || l_TwitchUser.IsBroadcaster)
                {
                    l_NamePrefix = "🗡";
                }
                else if (l_TwitchUser.IsVip)
                {
                    l_NamePrefix = "💎";
                }
                else if (l_TwitchUser.IsSubscriber)
                {
                    l_NamePrefix = "👑";
                }

                if (l_UserRequestCount >= l_Limit.Item1)
                {
                    SendChatMessage($"@{p_Message.Sender.UserName} You already have {l_UserRequestCount} on the queue. {l_Limit.Item2} are limited to {l_Limit.Item1} request(s).");
                    return;
                }
            }

            /// Check if already requested
            if (!(l_IsModerator && p_ModeratorAddCommand) && m_RequestedThisSession.Contains(l_Key))
            {
                SendChatMessage($"@{p_Message.Sender.UserName} this song was already requested this session!");
                return;
            }

            /// Fetch beatmap
            _ = m_BeatSaver.Key(l_Key).ContinueWith(p_SongTaskResult =>
            {
                try
                {
                    string l_Reply = "@" + p_Message.Sender.UserName + " map " + l_Key + " not found.";
                    if (p_SongTaskResult.Result != null && ((l_IsModerator && p_ModeratorAddCommand) || FilterBeatMap(p_SongTaskResult.Result, p_Message.Sender.UserName, out l_Reply)))
                    {
                        var l_BeatMap = p_SongTaskResult.Result;
                        float l_Vote  = (float)Math.Round((double)l_BeatMap.Stats.Rating * 100f, 0);

                        if ((l_IsModerator && p_ModeratorAddCommand) || !m_RequestedThisSession.Contains(l_Key))
                        {
                            m_RequestedThisSession.Add(l_Key.ToLower());

                            var l_Entry = new SongEntry()
                            {
                                BeatMap       = l_BeatMap,
                                RequesterName = p_Message.Sender.UserName,
                                RequestTime   = DateTime.Now,
                                NamePrefix    = l_NamePrefix
                            };

                            lock (SongQueue)
                            {
                                if (l_IsModerator && p_ModeratorAddToTop)
                                {
                                    SongQueue.Insert(0, l_Entry);
                                }
                                else
                                {
                                    SongQueue.Add(l_Entry);
                                }
                            }

                            /// Update request manager
                            OnQueueChanged();

                            l_Reply = $"(bsr {l_BeatMap.Key}) {l_BeatMap.Metadata.SongName} / {l_BeatMap.Metadata.LevelAuthorName} {l_Vote}% requested by @{p_Message.Sender.UserName} added to queue.";
                        }
                        else
                        {
                            l_Reply = $"@{p_Message.Sender.UserName} this song was already requested this session!";
                        }
                    }

                    SendChatMessage(l_Reply);
                }
                catch (System.Exception p_Exception)
                {
                    Logger.Instance.Error("Command_BSR");
                    Logger.Instance.Error(p_Exception);
                }
            });
        }