Esempio n. 1
0
        public static int CQ_sendGroupMsg(int authcode, long groupid, IntPtr msg)
        {
            if (Save.GroupList.TroopList.Any(x => x.GroupId == groupid) is false)
            {
                LogHelper.WriteLog(LogLevel.Warning, "消息无法投递", $"此账号未加入群 {groupid} ,无法发送消息");
            }
            Stopwatch sw = new Stopwatch();

            sw.Restart();
            string        text       = msg.ToString(GB18030);
            string        textBackup = msg.ToString(GB18030);
            string        url        = $@"{Save.url}v1/LuaApiCaller?qq={Save.curentQQ}&funcname=SendMsg";
            JObject       data;
            List <CQCode> cqCodeList = CQCode.Parse(text);

            if (text.Contains("[CQ:image") || text.Contains("[CQ:record"))
            {
                data = new JObject
                {
                    { "toUser", groupid },
                    { "sendToType", 2 },
                    { "groupid", 0 },
                    { "fileMd5", "" },
                    { "atUser", 0 }
                };
            }
            else
            {
                url += "V2";
                data = new JObject
                {
                    { "ToUserUid", groupid },
                    { "SendToType", 2 }
                };
            }
            CQCodeHelper.Progeress(cqCodeList, ref data, ref text);
            string pluginname = appInfos.Find(x => x.AuthCode == authcode).Name;

            if (Save.TestPluginsList.Any(x => x == pluginname))
            {
                Save.TestPluginChatter.Invoke(new System.Windows.Forms.MethodInvoker(() =>
                {
                    Save.TestPluginChatter.SelectionColor = Color.Green;
                    Save.TestPluginChatter.AppendText($"[{DateTime.Now:HH:mm:ss}] 插件发送消息: {textBackup}\n");
                }));
                return(0);
            }
            else
            {
                int logid = LogHelper.WriteLog(LogLevel.InfoSend, pluginname, "[↑]发送消息", $"群号:{groupid} 消息:{msg.ToString(GB18030)}", "处理中...");
                WebAPI.SendRequest(url, data.ToString());
                sw.Stop();
                LogHelper.UpdateLogStatus(logid, $"√ {sw.ElapsedMilliseconds / (double)1000:f2} s");
                return(Save.MsgList.Count + 1);
            }
        }
Esempio n. 2
0
        public static int CQ_sendPrivateMsg(int authCode, long qqId, IntPtr msg)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            string        text = msg.ToString(GB18030);
            string        url  = $@"{Save.url}v1/LuaApiCaller?qq={Save.curentQQ}&funcname=SendMsg";
            JObject       data;
            List <CQCode> cqCodeList = CQCode.Parse(text);

            if (text.Contains("[CQ:image"))
            {
                data = new JObject
                {
                    { "toUser", qqId },
                    { "sendToType", 1 },
                    { "groupid", 0 },
                    { "fileMd5", "" },
                    { "atUser", 0 }
                };
            }
            else
            {
                url += "V2";
                data = new JObject
                {
                    { "ToUserUid", qqId },
                    { "SendToType", 1 },
                    { "GroupID", 0 }
                };
            }
            switch (Helper.GetMsgType(qqId))
            {
            case -1:
                LogHelper.WriteLog(LogLevel.Warning, "消息无法投递", $"此账号未与 {qqId} 建立任何关系");
                return(0);

            case 1:
                break;

            case 3:
                if (data.ContainsKey("sendToType"))
                {
                    data["sendToType"] = 3;
                    data["groupid"]    = Helper.GetIDFirstInGroup(qqId);
                }
                else
                {
                    data["SendToType"] = 3;
                    data["GroupID"]    = Helper.GetIDFirstInGroup(qqId);
                }
                break;

            default:
                break;
            }
            CQCodeHelper.Progeress(cqCodeList, ref data, ref text);
            string pluginname = appInfos.Find(x => x.AuthCode == authCode).Name;

            if (WebAPI.SendRequest(url, data.ToString()).Contains("-103"))
            {
                LogHelper.WriteLog(LogLevel.Warning, "消息投递失败", "此群禁止临时会话");
                return(0);
            }
            int logid = LogHelper.WriteLog(LogLevel.InfoSend, pluginname, "[↑]发送好友消息", $"QQ:{qqId} 消息:{msg.ToString(GB18030)}", "处理中...");

            sw.Stop();
            LogHelper.UpdateLogStatus(logid, $"√ {sw.ElapsedMilliseconds / (double)1000:f2} s");
            return(0);
        }