Beispiel #1
0
        string getWords(TextAmenderBuilder builder)
        {
            string wordStr   = "";
            var    wordSplit = builder.AllWords;

            for (int i = 0; i < wordSplit.Count; i++)
            {
                string value = wordSplit[i];
                value = value
                        .Replace("\u005c", @"\\")
                        .Replace("\r\n", @"\\r\\n")
                        .Replace("*", @"\*");
                wordStr += $"{i:00}: {value}\r\n";
            }
            return(wordStr);
        }
Beispiel #2
0
        string getAmendedText(AmendmentBuilder builder)
        {
            var amender = new TextAmenderBuilder(Header, builder, TextAmendments);

            return(builder.TextOnly ? amender.NiceWords : amender.RawText);
        }
Beispiel #3
0
        async Task <TextAmendment> craftTextRemoval(dynamic clauseOrParagraph)
        {
            await ReplyAsync("All text amendments are based upon inserting, removing or replacing text at a certain index.\r\n" +
                             "You must specific the START index to which the inserted text will preceed.\r\n" +
                             "For removals, you must specifiy how many words to remove after that index");

            var amendment = new TextAmendment()
            {
                Type   = AmendType.Repeal,
                Start  = 0,
                Length = 0
            };
            var     amendments = new List <TextAmendment>();
            dynamic thing      = clauseOrParagraph.TextAmendments;

            if (thing is List <TextAmendment> )
            {
                amendments.AddRange(thing);
            }
            string _TEXT;

            try
            {
                _TEXT = clauseOrParagraph.Text;
            }
            catch
            {
                _TEXT = clauseOrParagraph.Header;
            }
            do
            {
                var builder = new TextAmenderBuilder(_TEXT, new AmendmentBuilder(0, false), amendments, true);
                if (amendment.Length > 0)
                {
                    await ReplyAsync("Does this look right to you?\r\n>>> " + builder.RawText);

                    var resp = await GetResponse("If the above is correct, entry `y`, otherwise type `n`");

                    if (resp.StartsWith("y"))
                    {
                        break;
                    }
                    amendments.Remove(amendment);
                    amendment.Length = 0;
                    continue; // reset.
                }
                string wordStr = getWords(builder);
                await ReplyAsync($"Text words:\r\n>>> {wordStr}");

                var index = await GetResponse($"Please provide the index of the first word that this amendment will remove");

                if (!int.TryParse(index, out var number))
                {
                    throw new ArgumentException("Input provided was not an integer!");
                }
                if (number < 0 || number > builder.AllWords.Count)
                {
                    throw new ArgumentException($"Index was out of range! (0-{builder.AllWords.Count})");
                }
                amendment.Start = number;
                var lengthStr = await GetResponse("Please provide how many words, including that index, should be removed after it");

                if (!int.TryParse(lengthStr, out var length))
                {
                    throw new ArgumentException("Input provided was not an integer!");
                }
                if (length <= 0)
                {
                    throw new ArgumentException("Input was out of range! (>=1)");
                }
                amendment.Length = length;
                amendments.Add(amendment);
            } while (true);
            return(amendment);
        }
Beispiel #4
0
        async Task <TextAmendment> craftTextReplacement(dynamic clauseOrParagraph)
        {
            await ReplyAsync("All text amendments are based upon inserting, removing or replacing text at a certain index.\r\n" +
                             "You must specific the START index to which the inserted text will preceed.");

            var amendment = new TextAmendment()
            {
                Type   = AmendType.Substitute,
                Start  = 0,
                Length = 0,
                New    = ""
            };
            var     amendments = new List <TextAmendment>();
            dynamic thing      = clauseOrParagraph.TextAmendments;

            if (thing is List <TextAmendment> )
            {
                amendments.AddRange(thing);
            }
            string _TEXT;

            try
            {
                _TEXT = clauseOrParagraph.Text;
            } catch
            {
                _TEXT = clauseOrParagraph.Header;
            }
            do
            {
                var builder = new TextAmenderBuilder(_TEXT, new AmendmentBuilder(0, false), amendments, true);
                if (amendment.Length > 0 && !string.IsNullOrWhiteSpace(amendment.New))
                {
                    await ReplyAsync("Does this look right to you?\r\n>>> " + builder.RawText);

                    var resp = await GetResponse("If the above is correct, entry `y`, otherwise type `n`");

                    if (resp.StartsWith("y"))
                    {
                        break;
                    }
                    amendments.Remove(amendment);
                    amendment.Length = 0;
                    amendment.New    = null;
                    continue; // reset.
                }
                string wordStr = getWords(builder);
                await ReplyAsync($"Text words:\r\n>>> {wordStr}");

                var index = await GetResponse($"Please provide the index of the first word that this amendment will replace");

                if (!int.TryParse(index, out var number))
                {
                    throw new ArgumentException("Input provided was not an integer!");
                }
                if (number < 0 || number > builder.AllWords.Count)
                {
                    throw new ArgumentException($"Index was out of range! (0-{builder.AllWords.Count})");
                }
                amendment.Start = number;
                string text = await escape(GetResponse("Please provide the new text to insert"));

                if (text.Length > 2)
                {
                    if (text.First() == '"' && text.Last() == '"')
                    {
                        text = text.Substring(1, text.Length - 2); // allow for user to preserve whitespace by quoting
                    }
                    else if (text.StartsWith(@"\"""))
                    {
                        text = text.Substring(2, text.Length - 3);
                    }
                }
                amendment.New = text;
                var lengthStr = await GetResponse("Please provide how many words, including that index, should be replaced with the provided string");

                if (!int.TryParse(lengthStr, out var length))
                {
                    throw new ArgumentException("Input provided was not an integer!");
                }
                if (length <= 0)
                {
                    throw new ArgumentException("Input was out of range! (>=1)");
                }
                amendment.Length = length;

                amendments.Add(amendment);
            } while (true);
            return(amendment);
        }