Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace PandoraBox
- {
- public class MixAndCutPlugin : IPluginMacro
- {
- public string Execute(string template, PluginMacroArgs args)
- {
- return Regex.Replace(template, @"\{MIXANDCUT-(\d+)}(.*?){/MIXANDCUT}", m =>
- {
- var count = int.Parse(m.Groups[1].Value); //кол-во лежит в 1 параметре макроса
- var innerText = m.Groups[2].Value; //текст лежит в 2 параметре макроса
- var rndWords = innerText
- .Trim() //во внутреннем тексте обрезаем пробелы
- .Split(' ') //рубим по пробелам
- //.OrderBy(i => Rnd.InnerObject.Next()) //перемешиваем, правда я отключил его, раскомментируйте если надо
- .Where(word => word.Length >= 3) //отфильтровать только слова >= 3 символов
- .Take(count); //взять только нужное число слов
- var result = String.Join(" ", rndWords); //соединяем слова в фразу через пробелы
- //чистка регуляркой 1
- result = Regex.Replace(result, @"[^a-zа-я0-9]*$", "");
- //чистка регуляркой 2
- result = Regex.Replace(result, @"\(([^\)\r\n]*)$", "($1)");
- //вывод
- return result;
- });
- }
- public ushort Level { get { return 10; } }
- public String Name { get { return "MixAndCutPlugin"; } }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment