public static int CQ_sendGroupMsg(int authcode, long groupid, IntPtr msg) { string text = Marshal.PtrToStringAnsi(msg); string url = $@"{Save.url}v1/LuaApiCaller?qq={Save.curentQQ}&funcname=SendMsg&timeout=10"; List<CQCode> cqCodeList = CQCode.Parse(text); JObject data = new JObject { {"toUser",groupid}, {"sendToType",2}, {"groupid",0}, {"fileMd5","" } }; bool Picflag = false, Atflag = false; ; foreach (var item in cqCodeList) { switch (item.Function) { case CQFunction.At://[CQ:at,qq=xxxx] { if (!data.ContainsKey("atUser")) { data.Add("atUser", Convert.ToInt64(item.Items["qq"])); } else if (data["atUser"].ToString() == "0") data["atUser"] = Convert.ToInt64(item.Items["qq"]); Atflag = true; break; } case CQFunction.Image: { if (!data.ContainsKey("content")) data.Add("content", ""); if (!data.ContainsKey("picBase64Buf")) data.Add("picBase64Buf", ""); if (!data.ContainsKey("picUrl")) data.Add("picUrl", ""); if (!data.ContainsKey("atUser")) data.Add("atUser", 0); if (!data.ContainsKey("picUrl")) data.Add("picUrl", ""); if (item.Items.ContainsKey("url")) data["picUrl"] = item.Items["url"]; else if (item.Items.ContainsKey("file")) { if (File.Exists("data\\image\\" + item.Items["file"] + ".cqimg")) { IniConfig ini = new IniConfig("data\\image\\" + item.Items["file"] + ".cqimg"); ini.Load(); data["picUrl"] = ini.Object["image"]["url"].ToString(); Picflag = true; break; } string path = item.Items["file"], base64buf = string.Empty; if (File.Exists(path)) { base64buf = BinaryReaderExpand.ImageToBase64(path); } data["picBase64Buf"] = base64buf; } else if (item.Items.ContainsKey("md5")) { data["fileMd5"] = item.Items["file"]; } Picflag = true; break; } } } string filtered = Regex.Replace(text, @"\[CQ.*\]", ""); if (!string.IsNullOrEmpty(filtered)) data["content"] = filtered; if (Picflag) data.Add("sendMsgType", "PicMsg"); else if (Atflag) data.Add("sendMsgType", "AtMsg"); else data.Add("sendMsgType", "TextMsg"); if (!data.ContainsKey("atUser")) data.Add("atUser", 0); Console.WriteLine($"发送消息,群号{groupid}"); Console.WriteLine(msg); SendRequest(url, data.ToString()); return 0; }
public static void Progeress(List <CQCode> cqCodeList, ref JObject data, ref string text) { bool Picflag = text.Contains("[CQ:image"), Voiceflag = text.Contains("[CQ:record"); string contentSectionName = "Content"; if (Picflag || Voiceflag) { contentSectionName = "content"; } foreach (var item in cqCodeList) { switch (item.Function) { case CQFunction.At: //[CQ:at,qq=xxxx] { if (!data.ContainsKey(contentSectionName)) { data.Add(contentSectionName, ""); } text = text.Replace(item.ToSendString(), $"[ATUSER({Convert.ToInt64(item.Items["qq"])})]"); break; } case CQFunction.Image: { if (!data.ContainsKey("content")) { data.Add("content", ""); } if (!data.ContainsKey("picBase64Buf")) { data.Add("picBase64Buf", ""); } if (!data.ContainsKey("picUrl")) { data.Add("picUrl", ""); } if (!data.ContainsKey("atUser")) { data.Add("atUser", 0); } if (!data.ContainsKey("fileMd5")) { data.Add("fileMd5", ""); } if (item.Items.ContainsKey("url")) { data["picUrl"] = item.Items["url"]; } else if (item.Items.ContainsKey("file")) { if (File.Exists("data\\image\\" + item.Items["file"] + ".cqimg")) { IniConfig ini = new IniConfig("data\\image\\" + item.Items["file"] + ".cqimg"); ini.Load(); data["picUrl"] = ini.Object["image"]["url"].ToString(); Picflag = true; break; } string path = item.Items["file"], base64buf = string.Empty; if (File.Exists("data\\image\\" + path)) { base64buf = BinaryReaderExpand.ImageToBase64("data\\image\\" + path); } data["picBase64Buf"] = base64buf; } else if (item.Items.ContainsKey("md5")) { data["fileMd5"] = item.Items["file"]; } Picflag = true; text = Regex.Replace(text, @"\[CQ:image,.*?\]", "[PICFLAG]"); if (text == "[PICFLAG]") { text = ""; } break; } case CQFunction.Record: { if (!data.ContainsKey("content")) { data.Add("content", ""); } if (!data.ContainsKey("voiceBase64Buf")) { data.Add("voiceBase64Buf", ""); } if (!data.ContainsKey("voiceUrl")) { data.Add("voiceUrl", ""); } if (!data.ContainsKey("atUser")) { data.Add("atUser", 0); } if (item.Items.ContainsKey("file")) { string voicepath = $"data\\record\\{item.Items["file"]}"; if (File.Exists(voicepath)) { try { IniConfig ini = new IniConfig(voicepath); ini.Load(); data["voiceUrl"] = ini.Object["record"]["url"].ToString(); } catch { string extension = new FileInfo(voicepath).Extension; if (extension != ".silk") { if (SilkEncode(voicepath, extension)) { voicepath = voicepath.Replace(extension, ".silk"); } } voicepath = new FileInfo(voicepath).FullName; string base64Str; using (FileStream fsRead = new FileStream(voicepath, FileMode.Open)) { int fsLen = (int)fsRead.Length; byte[] heByte = new byte[fsLen]; int r = fsRead.Read(heByte, 0, heByte.Length); base64Str = Convert.ToBase64String(heByte); } data["voiceBase64Buf"] = base64Str; } Voiceflag = true; } } break; } case CQFunction.Face: { text = Regex.Replace(text, "\\[CQ:face,id=(\\d*)\\]", "[表情$1]"); break; } case CQFunction.Emoji: { int src = Convert.ToInt32(item.Items["id"]); text = text.Replace(item.ToSendString(), Encoding.UTF32.GetString(BitConverter.GetBytes(src))); break; } } } string filtered = Regex.Replace(text, @"\[CQ.*\]", ""); if (!string.IsNullOrEmpty(filtered)) { data[contentSectionName] = filtered; } if (Picflag) { data.Add("sendMsgType", "PicMsg"); } else if (Voiceflag) { data.Add("sendMsgType", "VoiceMsg"); } else { data.Add("SendMsgType", "TextMsg"); } }