Beispiel #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;
        }
Beispiel #2
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            var dictionary = file.ExtraData;
            YouTubeCommandType youTubeCommandType = YouTubeCommandType.YouTube;

            bool valid = dictionary.Any();

            if (valid)
            {
                bool hasMirrorType = file.ExtraData.TryGetValue("YouTubeType", out IEnumerable <string> youTubeCommandTypeStr) > 0;
                if (hasMirrorType)
                {
                    valid = Enum.TryParse(youTubeCommandTypeStr.First(), out youTubeCommandType);
                }
                else
                {
                    valid = false;
                }
            }
            else
            {
                valid = false;
            }

            return(valid ? (new YouTubeCommand(controller.ErrorLogger, controller.waitHandler, controller, controller.languageHandler, file.Aliases, file.Examples, file.Help, module, youTubeCommandType)) : null);
        }
Beispiel #3
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            var    dictionary = file.ExtraData;
            string delimiter  = "";

            bool valid = dictionary.Any();

            if (valid)
            {
                bool has = file.ExtraData.TryGetValue("Delimiter", out IEnumerable <string> delimiterStr) > 0;
                if (has)
                {
                    delimiter = delimiterStr.First();
                }
                else
                {
                    valid = false;
                }
            }
            else
            {
                valid = false;
            }

            return(valid ? (new ChooseCommand(controller.languageHandler, file.Aliases, file.Examples, file.Help, module, delimiter)) : null);
        }
Beispiel #4
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;
        }
Beispiel #5
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.Image;
            }

            var        dictionary = file.ExtraData;
            MirrorType mirrorType = MirrorType.LeftOntoRight;

            bool valid = dictionary.Any();

            if (valid)
            {
                bool hasMirrorType = file.ExtraData.TryGetValue("MirrorType", out IEnumerable <string> mirrorTypeStr) > 0;
                if (hasMirrorType)
                {
                    valid = Enum.TryParse(mirrorTypeStr.First(), out mirrorType);
                }
                else
                {
                    valid = false;
                }
            }
            else
            {
                valid = false;
            }

            return(valid ? (new ObaboCommand(controller.ErrorLogger, controller.waitHandler, controller, controller.languageHandler, file.Aliases, file.Examples, file.Help, module, mirrorType)) : null);
        }
Beispiel #6
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            bool requiresSymbolParsed = bool.TryParse(file.RequiresSymbol, out bool requiresSymbol);

            if (!requiresSymbolParsed)
            {
                requiresSymbol = true;
            }

            var          dictionary   = file.ExtraData;
            ResponseType responseType = ResponseType.Default;
            string       choiceFormat = "";

            string[][] choices;
            if (dictionary.Any())
            {
                bool hasResponseType = file.ExtraData.TryGetValue("ResponseType", out IEnumerable <string> responseTypeStr) > 0;
                if (hasResponseType)
                {
                    Enum.TryParse(responseTypeStr.First(), out responseType);
                    // If not parsed then "Default" will be used.
                }

                bool hasChoiceFormat = file.ExtraData.TryGetValue("ChoiceFormat", out IEnumerable <string> choiceFormats) > 0;
                if (hasChoiceFormat)
                {
                    choiceFormat = choiceFormats.First();
                }

                List <List <string> > temp = new List <List <string> >();
                foreach (var pair in file.ExtraData)
                {
                    if (pair.Key.Length == 1)
                    {
                        int section = pair.Key[0] - 'A';

                        if (temp.Count <= section)
                        {
                            temp.Add(new List <string>());
                        }
                        temp[section].Add(pair.Value);
                    }
                }
                choices = temp.Select(l => l.ToArray()).ToArray();
            }
            else
            {
                choices = new string[0][];
            }

            return(new ResponseMessageListCommand(file.Aliases, choices, choiceFormat, file.Examples, file.Help, module, responseType, requiresSymbol));
        }
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.Translation;
            }

            return(new TranslateCommand(controller, controller.ErrorLogger, controller.languageHandler, file.Aliases, file.Examples, file.Help, module));
        }
Beispiel #8
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.BotAdmin;
            }

            return(new SetNameCommand(controller.client, controller.languageHandler, file.Aliases, file.Examples, file.Help, module));
        }
Beispiel #9
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            return(new PokemonTypeCommand(controller.languageHandler, file.Aliases, file.Examples, file.Help, module));
        }
Beispiel #10
0
        // private readonly List<CorrelationData> pokemonStdDevs;

        internal PokemonCommand(SlateBotController controller, string[] aliases, string examples, string help, ModuleType module)
            : base(CommandHandlerType.PokemonType, aliases, examples, help, module)
        {
            this.languageHandler = controller.languageHandler;
            this.waitHandler     = controller.waitHandler;
            this.asyncResponder  = controller;
            this.dal             = controller.dal;
            this.errorLogger     = dal.errorLogger;

            // Build the database
            // this.pokemonStdDevs = dal.PokemonSDevs;
        }
Beispiel #11
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            var  dictionary = file.ExtraData;
            bool ignoreCase = true;
            bool reverse    = false;
            bool doTTS      = false;

            string[] old;
            string[] @new;
            Dictionary <string, string> replacements = new Dictionary <string, string>();

            if (dictionary.Any())
            {
                bool hasIgnoreCase = file.ExtraData.TryGetValue("IgnoreCase", out IEnumerable <string> ignoreCaseStr) > 0;
                if (hasIgnoreCase)
                {
                    ignoreCase = bool.Parse(ignoreCaseStr.First());
                }

                bool hasReverse = file.ExtraData.TryGetValue("Reverse", out IEnumerable <string> reverseStr) > 0;
                if (hasReverse)
                {
                    reverse = bool.Parse(reverseStr.First());
                }

                bool hasDoTTS = file.ExtraData.TryGetValue("DoTTS", out IEnumerable <string> doTTSStr) > 0;
                if (hasDoTTS)
                {
                    doTTS = bool.Parse(doTTSStr.First());
                }

                old  = file.ExtraData.Where(pair => pair.Key.Equals("Old")).Select(pair => pair.Value).ToArray();
                @new = file.ExtraData.Where(pair => pair.Key.Equals("New")).Select(pair => pair.Value).ToArray();

                if (old.Length == @new.Length)
                {
                    for (int i = 0; i < old.Length; i++)
                    {
                        replacements.Add(old[i], @new[i]);
                    }
                }
            }

            return(new ReplaceCommand(file.Aliases, file.Examples, file.Help, module, replacements, ignoreCase, reverse, doTTS));
        }
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            var    dictionary = file.ExtraData;
            string url, formattedResponseURL, jsonProperty;

            if (dictionary.Any())
            {
                bool hasURL = file.ExtraData.TryGetValue("URL", out IEnumerable <string> urlStr) > 0;
                if (hasURL)
                {
                    url = urlStr.First();
                }
                else
                {
                    url = null;
                }

                bool hasFormattedResponseURL = file.ExtraData.TryGetValue("FormattedResponseURL", out IEnumerable <string> formattedResponseURLStr) > 0;
                if (hasFormattedResponseURL)
                {
                    formattedResponseURL = formattedResponseURLStr.First();
                }
                else
                {
                    formattedResponseURL = null;
                }

                bool hasJSONProperty = file.ExtraData.TryGetValue("JSONProperty", out IEnumerable <string> jsonPropertyStr) > 0;
                if (hasJSONProperty)
                {
                    jsonProperty = jsonPropertyStr.First();
                }
                else
                {
                    jsonProperty = null;
                }
            }
            else
            {
                throw new InvalidOperationException("XML for PullImageCommand is insufficient.");
            }

            return(new PullImageCommand(controller.languageHandler, controller, file.Aliases, file.Examples, file.Help, module, url, formattedResponseURL, jsonProperty));
        }
Beispiel #13
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)}");
        }
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            var dictionary = file.ExtraData;
            int fromBase   = 0;
            int toBase     = 0;

            bool valid = dictionary.Any();

            if (valid)
            {
                bool hasFromBase = file.ExtraData.TryGetValue("FromBase", out IEnumerable <string> fromBaseStr) > 0;
                if (hasFromBase)
                {
                    fromBase = int.Parse(fromBaseStr.First());
                }
                else
                {
                    valid = false;
                }

                bool hasToBase = file.ExtraData.TryGetValue("ToBase", out IEnumerable <string> toBaseStr) > 0;
                if (hasToBase)
                {
                    toBase = int.Parse(toBaseStr.First());
                }
                else
                {
                    valid = false;
                }
            }
            else
            {
                valid = false;
            }

            return(valid ? (new BaseChangeCommand(controller.languageHandler, file.Aliases, file.Examples, file.Help, module, fromBase, toBase)) : null);
        }
Beispiel #15
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);
        }
Beispiel #16
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.General;
            }

            bool requiresSymbolParsed = bool.TryParse(file.RequiresSymbol, out bool requiresSymbol);

            if (!requiresSymbolParsed)
            {
                requiresSymbol = true;
            }

            var                  dictionary   = file.ExtraData;
            ResponseType         responseType = ResponseType.Default;
            IEnumerable <string> choices;

            if (dictionary.Any())
            {
                bool hasResponseType = file.ExtraData.TryGetValue("ResponseType", out IEnumerable <string> responseTypeStr) > 0;
                if (hasResponseType)
                {
                    Enum.TryParse(responseTypeStr.First(), out responseType);
                    // If not parsed then "Default" will be used.
                }

                choices = file.ExtraData.Where(pair => pair.Key.StartsWith("C")).Select(pair => pair.Value);
            }
            else
            {
                choices = new string[0];
            }

            return(new ResponseMessageCommand(file.Aliases, choices, file.Examples, file.Help, module, responseType, requiresSymbol));
        }
Beispiel #17
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);
        }
Beispiel #18
0
 public Command CreateCommand(SlateBotController controller, CommandFile _)
 {
     return(new ReceiveFileCommand(controller.dal, controller.commandHandlerController, controller));
 }
Beispiel #19
0
 internal ReloadCommand(SlateBotController controller, LanguageHandler languageHandler, string[] aliases, string examples, string help, ModuleType module)
     : base(CommandHandlerType.Reload, aliases, examples, help, module)
 {
     this.controller      = controller ?? throw new System.ArgumentNullException(nameof(controller));
     this.languageHandler = languageHandler ?? throw new System.ArgumentNullException(nameof(languageHandler));
 }
Beispiel #20
0
 /// <summary>
 /// Constructor of the <see cref="UserSettingsHandler"/>.
 /// </summary>
 public UserSettingsHandler(SlateBotController controller)
 {
     this.controller = controller;
     controller.OnCommandReceived += Controller_OnCommandReceived;
 }
Beispiel #21
0
        public Command CreateCommand(SlateBotController controller, CommandFile file)
        {
            bool moduleParsed = Enum.TryParse(file.Module, out ModuleType module);

            if (!moduleParsed)
            {
                module = ModuleType.Image;
            }

            var    dictionary = file.ExtraData;
            string template = null;
            Point  topLeft = new Point(), topRight = new Point(), bottomLeft = new Point();

            bool valid      = dictionary.Any();
            bool autoPoints = true;

            if (valid)
            {
                bool hasTemplate = file.ExtraData.TryGetValue("Template", out IEnumerable <string> templateStr) > 0;
                if (hasTemplate)
                {
                    template = templateStr.First();
                }
                else
                {
                    valid = false;
                }

                bool hasTopLeft = file.ExtraData.TryGetValue("TopLeft", out IEnumerable <string> topLeftStr) > 0;
                if (hasTopLeft)
                {
                    var topLeftPointArr = topLeftStr.First().Split(',');
                    topLeft = new Point(int.Parse(topLeftPointArr[0]), int.Parse(topLeftPointArr[1]));

                    bool hasTopRight = file.ExtraData.TryGetValue("TopRight", out IEnumerable <string> topRightStr) > 0;
                    if (hasTopRight)
                    {
                        var topRightPointArr = topRightStr.First().Split(',');
                        topRight = new Point(int.Parse(topRightPointArr[0]), int.Parse(topRightPointArr[1]));

                        bool hasBottomLeft = file.ExtraData.TryGetValue("BottomLeft", out IEnumerable <string> bottomLeftStr) > 0;
                        if (hasBottomLeft)
                        {
                            var bottomLeftPointArr = bottomLeftStr.First().Split(',');
                            bottomLeft = new Point(int.Parse(bottomLeftPointArr[0]), int.Parse(bottomLeftPointArr[1]));
                            autoPoints = false;
                        }
                        else
                        {
                            valid = false;
                        }
                    }
                    else
                    {
                        valid = false;
                    }
                }
            }
            else
            {
                valid = false;
            }

            if (valid)
            {
                string templatePath = template;
                if (!Path.IsPathRooted(template))
                {
                    templatePath = Path.Combine(controller.dal.memeFolder, templatePath);
                }

                if (autoPoints)
                {
                    return(new MemeCommand(controller.ErrorLogger, controller.waitHandler, controller, controller.languageHandler, file.Aliases, file.Examples, file.Help, module, templatePath));
                }
                else
                {
                    return(new MemeCommand(controller.ErrorLogger, controller.waitHandler, controller, controller.languageHandler, file.Aliases, file.Examples, file.Help, module, templatePath, topLeft, topRight, bottomLeft));
                }
            }
            else
            {
                return(null);
            }
        }