Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (true) {
- bool hasMatch = true;
- Regex regToken = new Regex("{([^{}]+)}"),
- regDefault = new Regex(@"{(\d):([^{}]+)}"),
- regUrl = new Regex(@"{(\d):url}"),
- regArg = new Regex(@"{(\d+)}"),
- regRnd = new Regex(@"{rnd:([^{}]+)}"),
- regRng = new Regex(@"{rng:([^{}]+)}");
- int matchIdx = -1, matchLen = -1;
- string matchReplace = "";
- string testOut = msg;
- int iterations=4;
- while (hasMatch && iterations>0) {
- if (regToken.IsMatch(testOut)) {
- int offset = 0;
- foreach (Match mToken in regToken.Matches(testOut)) {
- matchReplace = "";
- string matchOriginal = mToken.Value;
- if (regUrl.IsMatch(matchOriginal)) {
- Match mUrl = regUrl.Matches(matchOriginal)[0];
- if (prms.Length > int.Parse(mUrl.Groups[1].Value)) {
- matchReplace = HttpUtility.UrlEncode(prms[int.Parse(mUrl.Groups[1].Value)]);
- }
- else {
- matchReplace = matchOriginal;
- }
- }
- else if (regDefault.IsMatch(matchOriginal)) {
- Match mDefault = regDefault.Matches(matchOriginal)[0];
- if (prms.Length > int.Parse(mDefault.Groups[1].Value)) {
- matchReplace = prms[int.Parse(mDefault.Groups[1].Value)];
- }
- else {
- matchReplace = mDefault.Groups[2].Value;
- }
- }
- else if (regArg.IsMatch(matchOriginal)) {
- Match mArg = regArg.Matches(matchOriginal)[0];
- if (prms.Length > int.Parse(mArg.Groups[1].Value)) {
- matchReplace = prms[int.Parse(mArg.Groups[1].Value)];
- }
- else {
- matchReplace = matchOriginal;
- }
- }
- else if (regRnd.IsMatch(matchOriginal)) {
- Match mRnd = regRnd.Matches(matchOriginal)[0];
- if (mRnd.Groups[1].Value.ToLower() == "args") {
- string[] parts = msgText.Split(',');
- matchReplace = parts[R.Next(parts.Length)];
- }
- else {
- string[] parts = mRnd.Groups[1].Value.Split('|');
- matchReplace = parts[R.Next(parts.Length)];
- }
- }
- else if (regRng.IsMatch(matchOriginal)) {
- Match mRng = regRng.Matches(matchOriginal)[0];
- string[] parts = mRng.Groups[1].Value.Split(',');
- int p1 = 0, p2 = 0;
- if (parts[0].ToLower().Trim() == "min") {
- p1 = int.MinValue;
- }
- else {
- p1 = int.Parse(parts[0]);
- }
- if (parts[1].ToLower().Trim() == "max") {
- p2 = int.MaxValue-1;
- }
- else {
- p2 = int.Parse(parts[1]);
- }
- matchReplace = R.Next(Math.Min(p1, p2), Math.Max(p1, p2) + 1).ToString();
- }
- if (matchReplace != "") {
- testOut = testOut.Remove(mToken.Index-offset, mToken.Length).Insert(mToken.Index-offset, matchReplace);
- offset += mToken.Length - matchReplace.Length;
- }
- }
- }
- else {
- hasMatch = false;
- }
- iterations--;
- }
- if (target == "#timebot") {
- PendingOutput.Add(SendMessage(target, "new parser result: " + testOut));
- }
- else {
- /*PendingOutput.Add(SendMessage(admin, testOut));*/
- }
- /*return msgText;*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement