public static string Build(SystemMessageData template, params string[] parameters) { var pieces = new List <string>(); var sb = new StringBuilder(); var prm = ChatUtils.SplitDirectives(parameters); var txt = template.Template.UnescapeHtml().Replace("<BR>", "\r\n"); var html = new HtmlDocument(); html.LoadHtml(txt); var htmlPieces = html.DocumentNode.ChildNodes; if (prm == null) { //only one parameter (opcode) so just add text foreach (var htmlPiece in htmlPieces) { var content = htmlPiece.InnerText; pieces.Add(content); } } else { //more parameters foreach (var piece in htmlPieces) { if (piece.Name == "img") { continue; } var content = ChatUtils.ReplaceParameters(piece.InnerText, prm, true); var innerPieces = content.Split(new[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries); var plural = false; var selectionStep = 0; foreach (var inPiece in innerPieces) { switch (selectionStep) { case 1: if (int.Parse(inPiece) != 1) { plural = true; } selectionStep++; continue; case 2: if (inPiece == "/s//s" && plural) { pieces[^ 1] = pieces.Last() + "s";
public SystemMessage(string parameters, SystemMessageData template, ChatChannel ch) { Channel = ch; RawMessage = parameters; Author = "System"; try { var prm = ChatUtils.SplitDirectives(parameters); var txt = template.Template.UnescapeHtml().Replace("<BR>", "\r\n"); var html = new HtmlDocument(); html.LoadHtml(txt); var htmlPieces = html.DocumentNode.ChildNodes; if (prm == null) { //only one parameter (opcode) so just add text foreach (var htmlPiece in htmlPieces) { var customColor = ChatUtils.GetCustomColor(htmlPiece); var content = htmlPiece.InnerText; RawMessage = content; AddPiece(new SimpleMessagePiece(content, App.Settings.FontSize, false, customColor)); } } else { //more parameters foreach (var htmlPiece in htmlPieces) { ParseSysHtmlPiece(htmlPiece, prm); } } foreach (var p in Pieces) { PlainMessage += p.Text; } } catch (Exception e) { Log.F($"Failed to parse system message: {parameters} -- {template.Template}\n {e}"); // ignored } }