示例#1
0
 private void CacheSource()
 {
     if (_source == null)
     {
         _source = LoadSource(_sourcePath);
     }
 }
示例#2
0
 private void CacheSource()
 {
     if (_source == null)
     {
         _source = LoadSource(Path.Combine(BotCore.ResourcesDirectory, SOURCE_FILE_NAME));
     }
 }
示例#3
0
        private string Insult(string target, InsultDataSource source)
        {
            string format = source.Formats[random.Next(source.Formats.Length)];
            string result = RecursiveHandleReplacements(format, target, source);

            result = RemoveExcessSpaces(result);
            return(HandleAns(result));
        }
示例#4
0
        private string RecursiveHandleReplacements(string input, string target, InsultDataSource source)
        {
            Regex regex  = new Regex(@"{(.*?)}");
            var   result = regex.Replace(input, x => HandleReplacement(x.Value, target, source));

            if (input == result)
            {
                return(result);
            }
            else
            {
                return(RecursiveHandleReplacements(result, target, source));
            }
        }
示例#5
0
        private string GetFromSource(string input, string target, InsultDataSource source)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(input);
            }

            string contents = input.Substring(1, input.Length - 2);

            if (contents.StartsWith('$')) // Content refers to a variable
            {
                return(source.GetVariable(contents.Substring(1), target));
            }
            return(source.Get(contents, target));
        }
示例#6
0
        private string HandleReplacement(string input, string target, InsultDataSource source)
        {
            // Handle optionals. Replacements ending with ?xxx where xxx referes to chance of appearing in integers between 0 and 100
            input = HandleOptional(input);

            // Handle multiples. Replacements ending with multiple dots indicating a random amount of the same replacement that may potentially repeat.
            string multi = HandleMultiples(input);

            if (multi != input)
            {
                return(multi); // Return early, since the input has now been split in multiple and must handled recursively.
            }

            // Handle choosable. Replacements with multiple options split with /.
            input = HandleChoosables(input);

            return(GetFromSource(input, target, source));
        }