Пример #1
0
 /// <summary>
 /// 在当前群发送群消息
 /// </summary>
 /// <param name="message"></param>
 protected void sendMessage(object message)
 {
     if (Util.checkEmpty(message.ToString()))
     {
         return;
     }
     this.api.SendGroupMessage(this.fromGroup.ToString(), CQ.CQString(message.ToString()));
 }
Пример #2
0
 private void sendMessage(object msg)
 {
     if (Util.checkEmpty(msg.ToString()))
     {
         return;
     }
     this.api.SendPrivateMessage(this.qq, CQ.CQString(msg.ToString()));
 }
Пример #3
0
        private void sendMessage(object msg, bool isReplace)
        {
            if (Util.checkEmpty(msg.ToString()))
            {
                return;
            }
            string message = msg.ToString();

            if (isReplace)
            {
                message = CQ.CQString(message);
            }
            this.api.SendPrivateMessage(this.qq, message);
        }
Пример #4
0
        /// <summary>
        /// 在当前群发送群消息
        /// </summary>
        /// <param name="data"></param>
        /// <param name="isReplace"></param>
        protected void sendMessage(object data, bool isReplace)
        {
            if (Util.checkEmpty(data.ToString()))
            {
                return;
            }
            string message = data.ToString();

            if (isReplace)
            {
                message = CQ.CQString(message);
            }
            CQAPI.xtAddLog(LogType.status.DEBUG, "群聊消息", "[来自" + this.command + "发送的数据]");
            this.api.SendGroupMessage(this.fromGroup.ToString(), message);
        }
Пример #5
0
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="data"></param>
        private void parseUdpData(string data)
        {
            if (data == "" || data.Length == 0 || data.Trim().Length == 0)
            {
                throw new Exception("UDP请求数据为空");
            }
            if (!Util.isJson(data))
            {
                throw new Exception("UDP请求数据非JSON数据");
            }


            JObject obj = JObject.Parse(data);

            if (obj.Property("token") == null)
            {
                throw new Exception("验证失败:无token数据");
            }
            //获取token
            object tokenV = Conf.getConfig("global.config", "token");

            if (tokenV == null)
            {
                throw new Exception("验证失败:token服务端未设定,无法调用接口");
            }


            string token = obj["token"].ToString();

            if (token != tokenV.ToString())
            {
                throw new Exception("验证失败:token错误,无法调用接口");
            }

            if (obj.Property("fn") == null)
            {
                throw new Exception("UDP数据异常");
            }


            string fnName = obj["fn"].ToString();



            switch (fnName)
            {
            //发送群消息
            case "sendGroupMessage":

                if (Util.checkEmpty(obj.Property("group")))
                {
                    throw new Exception("群号码不能为空");
                }
                if (Util.checkEmpty(obj.Property("message")))
                {
                    throw new Exception("群消息不能为空");
                }

                api.SendGroupMessage(obj["group"].ToString(), CQ.CQString(obj["message"].ToString()));

                break;

            //发送私聊消息
            case "sendPrivateMessage":
                if (Util.checkEmpty(obj.Property("qq")))
                {
                    throw new Exception("私聊QQ号码不能为空");
                }
                if (Util.checkEmpty(obj.Property("message")))
                {
                    throw new Exception("私聊消息不能为空");
                }

                api.SendPrivateMessage(obj["qq"].ToString(), CQ.CQString(obj["message"].ToString()));

                break;

            default:
                throw new Exception(String.Format("没有找到【{0}】事件", fnName));
            }
        }