コード例 #1
0
        public void TestSuccessfulDVanillaNoPrefixCommand()
        {
            Response receivedResponse = null;

            void Controller_OnCommandReceived(object sender, SlateBot.Events.CommandReceivedEventArgs args)
            {
                receivedResponse = args.response;
            }

            var controller = new SlateBotController();

            controller.OnCommandReceived += Controller_OnCommandReceived;
            controller.Initialise();

            controller.HandleConsoleCommand("d4");
            Assert.IsNotNull(receivedResponse);
            Assert.IsTrue(receivedResponse.Message.StartsWith(Emojis.Dice));
            receivedResponse = null;

            controller.HandleConsoleCommand("d10");
            Assert.IsNotNull(receivedResponse);
            Assert.IsTrue(receivedResponse.Message.StartsWith(Emojis.Dice));
            receivedResponse = null;

            controller.HandleConsoleCommand("d5");
            Assert.IsNotNull(receivedResponse);
            Assert.IsTrue(receivedResponse.Message.StartsWith(Emojis.Dice));
            receivedResponse = null;
        }
コード例 #2
0
        public void TestSuccessfulDWithForceAndModifiersCommand()
        {
            Response receivedResponse = null;

            void Controller_OnCommandReceived(object sender, SlateBot.Events.CommandReceivedEventArgs args)
            {
                receivedResponse = args.response;
            }

            var controller = new SlateBotController();

            controller.OnCommandReceived += Controller_OnCommandReceived;
            controller.Initialise();

            controller.HandleConsoleCommand("2DF-1");
            Assert.IsNotNull(receivedResponse);
            Assert.IsTrue(receivedResponse.Message.StartsWith(Emojis.Dice));
            receivedResponse = null;

            controller.HandleConsoleCommand("3dF +2");
            Assert.IsNotNull(receivedResponse);
            Assert.IsTrue(receivedResponse.Message.StartsWith(Emojis.Dice));
            receivedResponse = null;

            controller.HandleConsoleCommand("4d10-3");
            Assert.IsNotNull(receivedResponse);
            Assert.IsTrue(receivedResponse.Message.StartsWith(Emojis.Dice));
            receivedResponse = null;

            controller.HandleConsoleCommand("2d100 -4");
            Assert.IsNotNull(receivedResponse);
            Assert.IsTrue(receivedResponse.Message.StartsWith(Emojis.Dice));
            receivedResponse = null;
        }
コード例 #3
0
ファイル: ReloadCommand.cs プロジェクト: kjhf/SlateBot
 public override IList <Response> Execute(SenderSettings senderDetail, IMessageDetail args)
 {
     if (Constants.IsBotOwner(senderDetail.UserSettings.UserId))
     {
         controller.Initialise();
         return(new Response[] { Response.CreateFromReact(Emojis.SoonUnicode) });
     }
     else
     {
         return(Response.CreateArrayFromString($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Error_BotOwnerOnly")}."));
     }
 }
コード例 #4
0
        public void TestDiceRegexDoesNotConflict()
        {
            var controller = new SlateBotController();

            controller.Initialise();
            List <Command> allCommands = new List <Command>();

            foreach (Languages language in Enum.GetValues(typeof(Languages)))
            {
                allCommands.AddRange(controller.commandHandlerController.GetCommandsForLanguage(language, false));
            }
            Assert.IsTrue(allCommands.Count > 3, "All commands not loaded?");

            // Test if any aliases match the dice Regex.
            string[] matchedRegexFailures = allCommands.SelectMany(c => c.Aliases.Where(alias => Regex.IsMatch(alias, DiceCommand.D_REGEX))).ToArray();
            Assert.IsTrue(matchedRegexFailures.Length == 0, $"Failed aliases: {string.Join(", ", matchedRegexFailures)}");
        }
コード例 #5
0
        public void TestReplaceCommand()
        {
            bool reacted = false;

            void Controller_OnCommandReceived(object sender, SlateBot.Events.CommandReceivedEventArgs args)
            {
                reacted = true;
            }

            var controller = new SlateBotController();

            controller.OnCommandReceived += Controller_OnCommandReceived;
            controller.Initialise();
            controller.HandleConsoleCommand("react aa");
            Assert.IsTrue(reacted);

            reacted = false;
            controller.HandleConsoleCommand("react ? ?");
            Assert.IsTrue(reacted);
        }
コード例 #6
0
        public void TestUnsuccessfulDVanillaNoSuffixCommand()
        {
            Response receivedResponse = null;

            void Controller_OnCommandReceived(object sender, SlateBot.Events.CommandReceivedEventArgs args)
            {
                receivedResponse = args.response;
            }

            var controller = new SlateBotController();

            controller.OnCommandReceived += Controller_OnCommandReceived;
            controller.Initialise();

            controller.HandleConsoleCommand("2d");
            Assert.IsNull(receivedResponse);

            controller.HandleConsoleCommand("1d");
            Assert.IsNull(receivedResponse);

            controller.HandleConsoleCommand("10d");
            Assert.IsNull(receivedResponse);
        }