Пример #1
0
        public async Task SendMessageTest()
        {
            InitializeDatastore.Run();
            var client = new WebSocketClient(PrivateConstants.TestAccountWebsocketAuth);

            client.Run(new MessageProcessor(client));
            await Task.Delay(2000);

            client.Send(new PublicMessage($"test{Tools.RandomString(3)}"));
        }
Пример #2
0
        public async Task SendBanTest()
        {
            InitializeDatastore.Run();
            var client = new WebSocketClient(PrivateConstants.BotWebsocketAuth);

            client.Run(new MessageProcessor(client));
            await Task.Delay(5000);

            client.Visit(new Ban("dharmatest", TimeSpan.FromMinutes(3), "test reason"));
        }
Пример #3
0
        public void CalculateLiveStatus()
        {
            InitializeDatastore.Run();
            Datastore.Viewers = 0;

            Datastore.UpdateStateVariable(MagicStrings.OnTime, 0, true);
            Datastore.UpdateStateVariable(MagicStrings.OffTime, 300, true);

            Assert.AreEqual(Datastore.OnTime(), 0);
            Assert.AreEqual(Datastore.OffTime(), 300);

            var testList = new List <Tuple <int, int, int, bool, string> > {
                //minutes, asserted onTime, asserted offTime, livestatus, livestring
                Tuple.Create(10, 10, 0, true, "Destiny is live! With 0 viewers for ~0m"),
                Tuple.Create(20, 10, 0, true, "Live with 0 viewers for ~10m"),
                Tuple.Create(30, 10, 0, true, "Live with 0 viewers for ~20m"),
                Tuple.Create(40, 10, 40, false, "Stream went offline in the past ~10m"),
                Tuple.Create(42, 10, 40, false, "Stream went offline in the past ~10m"),
                Tuple.Create(44, 10, 40, false, "Stream went offline in the past ~10m"),
                Tuple.Create(46, 10, 40, false, "Stream went offline in the past ~10m"),
                Tuple.Create(48, 10, 40, false, "Stream went offline in the past ~10m"),
                Tuple.Create(49, 10, 40, false, "Stream went offline in the past ~10m"),
                Tuple.Create(50, 0, 40, false, "Stream offline for ~10m"),
                Tuple.Create(51, 0, 40, false, "Stream offline for ~11m"),
                Tuple.Create(52, 0, 40, false, "Stream offline for ~12m"),
                Tuple.Create(55, 0, 40, false, "Stream offline for ~15m"),
                Tuple.Create(60, 60, 0, true, "Destiny is live! With 0 viewers for ~0m"),
                Tuple.Create(61, 60, 0, true, "Live with 0 viewers for ~1m"),
                Tuple.Create(65, 60, 0, true, "Live with 0 viewers for ~5m"),
                Tuple.Create(70, 60, 0, true, "Live with 0 viewers for ~10m"),
                Tuple.Create(75, 60, 0, true, "Live with 0 viewers for ~15m"),
                Tuple.Create(80, 60, 80, false, "Stream went offline in the past ~10m"),
                Tuple.Create(85, 60, 80, false, "Stream went offline in the past ~10m"),
                Tuple.Create(86, 60, 0, true, "Live with 0 viewers for ~26m"),
                Tuple.Create(89, 60, 0, true, "Live with 0 viewers for ~29m"),
                Tuple.Create(90, 60, 90, false, "Stream went offline in the past ~10m"),
                Tuple.Create(95, 60, 90, false, "Stream went offline in the past ~10m"),
                Tuple.Create(99, 60, 90, false, "Stream went offline in the past ~10m"),
                Tuple.Create(100, 0, 90, false, "Stream offline for ~10m"),
                Tuple.Create(105, 0, 90, false, "Stream offline for ~15m"),
            };

            foreach (var x in testList)
            {
                var temp = Tools.LiveStatus(x.Item4, Tools.Epoch(TimeSpan.FromMinutes(x.Item1)), true);
                Assert.AreEqual(Datastore.OnTime(), x.Item2 * 60);
                Assert.AreEqual(Datastore.OffTime(), x.Item3 * 60);
                Assert.AreEqual(temp, x.Item5);
            }
        }
Пример #4
0
        public void UpdateOrInsertStateVariable_Success()
        {
            InitializeDatastore.Run();

            //test insert
            var expectedAnswer = 1;
            var key            = "a";

            Datastore.UpdateStateVariable(key, expectedAnswer, true);
            Assert.AreEqual(Datastore.GetStateVariable(key), expectedAnswer);

            //test update
            expectedAnswer = 1 + expectedAnswer;
            Datastore.UpdateStateVariable(key, expectedAnswer, true);
            Assert.AreEqual(Datastore.GetStateVariable(key), expectedAnswer);
        }
Пример #5
0
        public void AutoMutedWordDatatbaseIncrementTest()
        {
            const string nick      = "simpleuser";
            const string mutedWord = "mutephrase";

            InitializeDatastore.Run();
            Datastore.AddToStateString(MagicStrings.MutedWords, mutedWord, TimeSpan.FromMinutes(10).TotalSeconds, Datastore.MutedWords);

            var banner = new Banner(new PublicMessage(nick, mutedWord), null, new List <Message>());

            foreach (var i in Enumerable.Range(1, 10))
            {
                banner.BanParser(true);
                Assert.AreEqual(i, Datastore.UserHistory(nick).History[MagicStrings.MutedWords][mutedWord]);
            }

            var testMute = new Mute {
                Duration = TimeSpan.FromDays(8)
            };

            Assert.AreEqual(testMute.Duration, TimeSpan.FromDays(7));
        }
Пример #6
0
        public void Run()
        {
            Logger.Init();
            InitializeDatastore.Run();

            var tokens = Tokens.Create(PrivateConstants.TwitterConsumerKey, PrivateConstants.TwitterConsumerSecret, PrivateConstants.TwitterAccessToken, PrivateConstants.TwitterAccessTokenSecret);

            _twitterStream = tokens.Streaming.UserAsObservable().Subscribe(new TweetObserver(_messageProcessor));

            PeriodicTask.Run(() => Tools.LiveStatus(), TimeSpan.FromMinutes(2));
            Tools.LiveStatus();
            PeriodicTask.Run(InitializeDatastore.UpdateEmotes, TimeSpan.FromMinutes(5));
            PeriodicTask.Run(PeriodicMessage, TimeSpan.FromMinutes(10));

            _client.Run(_messageProcessor);
            Console.CancelKeyPress += Console_CancelKeyPress;
            //http://stackoverflow.com/questions/14255655/tpl-dataflow-producerconsumer-pattern
            //http://msdn.microsoft.com/en-us/library/hh228601(v=vs.110).aspx

            ProcessConsoleInput();
            Exit();
        }
Пример #7
0
        public void CommanderTests()
        {
            InitializeDatastore.Run();

            var message = new Commander(new PublicMessage("!playlist"), new MessageProcessor(null)).Run();

            Assert.IsTrue(message.OriginalText == "Playlist at last.fm/user/StevenBonnellII");
            message = new Commander(new PublicMessage("!rules"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText == "github.com/destinygg/bot");
            message = new Commander(new PublicMessage("!refer"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText == "destiny.gg/amazon ☜(゚ヮ゚☜) Amazon referral ☜(⌒▽⌒)☞ 25$ off Sprint network (☞゚ヮ゚)☞ destiny.gg/ting");
            message = new Commander(new PublicMessage("!irc"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText == "IRC will be implemented Soon™. For now, chat is echoed to Rizon IRC at qchat.rizon.net/?channels=#destinyecho . Forwarding of IRC chat to Destiny.gg Chat is available");
            message = new Commander(new PublicMessage("!time"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText.Contains(" Central Steven Time"));
            message = new Commander(new PublicMessage("!live"), new MessageProcessor(null)).Run();
            var liveAnswers = new List <string> {
                "Live with ", "Destiny is live! With ", "Stream went offline in the past ~10m", "Stream offline for "
            };

            Assert.IsTrue(liveAnswers.Any(x => message.OriginalText.Contains(x)));
            message = new Commander(new PublicMessage("!blog"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText.Contains(" posted "));
            message = new Commander(new PublicMessage("!starcraft"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText.Contains(" game on "));
            message = new Commander(new PublicMessage("!song"), new MessageProcessor(null)).Run();
            var songAnswers = new List <string> {
                "No song played/scrobbled. Played ", " last.fm/user/stevenbonnellii"
            };

            Assert.IsTrue(songAnswers.Any(x => message.OriginalText.Contains(x)));
            message = new Commander(new PublicMessage("!earliersong"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText.Contains(" played before "));
            message = new Commander(new PublicMessage("!twitter"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText.Contains(" ago: "));
            message = new Commander(new PublicMessage("!youtube"), new MessageProcessor(null)).Run();
            Assert.IsTrue(message.OriginalText.Contains(" ago youtu.be/"));
        }