public string Format(MessageChain chain) { var cmps = new LinkedList <object>(); foreach (var comp in chain) { cmps.AddLast(comp switch { Plain plain => new { type = "text", data = new { text = plain.Text } }, Face face => new { type = "face", data = new { id = face.FaceId } }, At at => new { type = "at", data = new { qq = at.TargetId.ToString() } }, ImageBase { Source: UrlSource source } image => new { type = "image", data = new { file = source.Url.AbsoluteUri, type = image is Flash ? "flash" : "image", cache = 0 } }, ImageBase { Source: StreamSource source } image => new { type = "image", data = new { file = GetBase64Url(source.Data), type = image is Flash ? "flash" : "image", cache = 0 } }, AtAll atall => new { type = "at", data = new { qq = "atall" } }, Quote quote => new { type = "reply", data = new { id = quote.MessageId } }, Poke poke => new { type = "poke", data = new { type = ((int)poke.Name).ToString(), id = "-1" } }, XmlContent xml => new { type = "xml", data = new { data = xml.Content } }, JsonContent json => new { type = "json", data = new { data = json.Content } }, Music music => new { type = "music", data = new { type = music.Type switch { Music.MusicSource.QqMusic => "qq", Music.MusicSource.Music163 => "163", Music.MusicSource.XiaMi => "xm" },
string CodeSelector(MessageElement comp) { return(comp switch { At it => it.TargetId.ToString(), AtAll it => string.Empty, Face it => it.FaceId.ToString(), ImageBase it when it.Source != null && it.Source is UrlSource => $"{it.ImageId},{((UrlSource)it.Source).Url.AbsoluteUri}", Poke it => it.Name.ToString(), Quote it => it.MessageId.ToString(), Source it => it.MessageId.ToString(), _ => throw new NotImplementedException() });
string CodeSelector(MessageComponent comp) { return(comp switch { At it => it.TargetId.ToString(), AtAll it => string.Empty, Face it => it.FaceId.ToString(), ImageBase it => $"{it.ImageId},{it.Url}", Poke it => it.Name.ToString(), Quote it => it.MessageId.ToString(), Source it => it.MessageId.ToString(), _ => throw new NotImplementedException() });
public static MessageChainBuilder AddAtAll(this MessageChainBuilder builder) { AtAll atall = new AtAll(); return(builder.Add(atall)); }