Beispiel #1
0
        /// <summary>
        /// 获取随机消息
        /// </summary>
        /// <param name="SendParam"></param>
        /// <returns></returns>
        private string GetRandomMessage(SendParamModel SendParam)
        {
            string tempMessage = "";

            //固定消息,只会传一条消息模板过来
            if (SendParam.TemplateRule == 0)
            {
                tempMessage = SendParam.Message[0];
            }
            //随机消息,随机获取
            else if (SendParam.TemplateRule == 1)
            {
                int messageIndex = PublicUtils.GetRandom(0, SendParam.Message.Count);
                tempMessage = SendParam.Message[messageIndex];
            }

            //替换时间变量
            tempMessage = tempMessage.Replace("[时间]", "[Time]");
            //替换昵称变量
            tempMessage = tempMessage.Replace("[昵称]", "[ObjName]");
            //替换时段
            tempMessage = tempMessage.Replace("[时段]", "[TimePer]");
            //替换分段
            //自己进行分段
            //tempMessage = tempMessage.Replace("[分段]", "[Next]");

            //替换随机表情
            //tempMessage = tempMessage.Replace("[随机表情]", "[RFace]");
            return(FaceHelper.ReplaceRandomFace(tempMessage));
        }
Beispiel #2
0
        /// <summary>
        /// 发送文本消息,主要处理框架分段发送会缺失以及顺序会乱的问题,自己分段并且加上延时
        /// </summary>
        /// <param name="RobotQQ"></param>
        /// <param name="MsgType"></param>
        /// <param name="MsgTo"></param>
        /// <param name="ObjQQ"></param>
        /// <param name="Msg"></param>
        /// <param name="ABID"></param>
        /// <param name="SendParam"></param>
        private void SendTextMsg(string MsgTo, string ObjQQ, string Msg, int ABID, SendParamModel SendParam)
        {
            string pattern = "\\[分段\\]";

            string[] msessages = Regex.Split(Msg, pattern);
            for (int i = 0; i < msessages.Length; i++)
            {
                if (!string.IsNullOrEmpty(msessages[i]))
                {
                    IRQQApi.Api_SendMsg(SendParam.RobotQQ, SendParam.SendObject, MsgTo, ObjQQ, msessages[i], 1);
                    //如果不是最后一次,则进入文本分段休眠
                    if (i != msessages.Length - 1)
                    {
                        int interval = PublicUtils.GetRandom(SendParam.NextIntervalDown, SendParam.NextIntervalUp + 1);
                        OnOutStatus?.Invoke(string.Format("机器人[{0}]进入文本分段休眠{1}秒!", new object[] { SendParam.RobotQQ, interval }));
                        Thread.Sleep(interval * 1000);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="RobotQQ"></param>
        /// <param name="MsgType"></param>
        /// <param name="MsgTo"></param>
        /// <param name="ObjQQ"></param>
        /// <param name="Msg"></param>
        /// <param name="ABID"></param>
        /// <param name="SendParam"></param>
        private void SendMsg(string MsgTo, string ObjQQ, string name, int sendCount, string objectText, SendParamModel SendParam)
        {
            //每发一次消息获取一个随机消息
            string tempMessage = GetRandomMessage(SendParam);
            //如果有语音,则拆分发送
            string pattern = "\\[IR:Voi=(.)*?\\]";

            //当前模板存在语音
            if (Regex.Match(tempMessage, pattern).Length > 0)
            {
                MatchCollection matchCollection = Regex.Matches(tempMessage, pattern);
                string[]        messages        = Regex.Split(tempMessage, pattern);
                for (int j = 0; j < messages.Length; j++)
                {
                    if (!string.IsNullOrEmpty(messages[j]))
                    {
                        if (messages[j] == "r")
                        {
                            //发送语音
                            //获取当前文本
                            //0 1 2 3 4 5 6 7  x   x - 1 / 2
                            //0 1 2 3 y
                            //如果语音数据列表存在,则发送,否则提示不存在
                            //获取语音标签
                            string voiceKey = matchCollection[(j - 1) / 2].Value;
                            if (SendParam.Voices.ContainsKey(voiceKey))
                            {
                                if (SendParam.SendObject == 1)
                                {
                                    IRQQApi.Api_SendVoice(SendParam.RobotQQ, ObjQQ, SendParam.Voices[voiceKey]);
                                }
                                else
                                {
                                    string guid = IRQQApi.Api_UpLoadVoice(SendParam.RobotQQ, 2, ObjQQ, SendParam.Voices[voiceKey]);
                                    OnOutStatus?.Invoke(string.Format("获取到的GUID:{0}", new string[] { guid }));
                                    IRQQApi.Api_SendMsg(SendParam.RobotQQ, 2, MsgTo, ObjQQ, guid, 0);
                                }
                                OnOutStatus?.Invoke(string.Format("机器人[{0}]发送语音给第{1}个{2}[{3}-{4}]发送语音成功:{5}", new object[] { SendParam.RobotQQ, sendCount + 1, objectText, ObjQQ, name, voiceKey }));
                            }
                            else
                            {
                                OnOutStatus?.Invoke(string.Format("机器人[{0}]发送语音给第{1}个{2}[{3}-{4}]失败,找不到语音文件{5}", new object[] { SendParam.RobotQQ, sendCount + 1, objectText, ObjQQ, name, voiceKey }));
                            }
                        }
                        else
                        {
                            //直接发当前文本
                            SendTextMsg(MsgTo, ObjQQ, messages[j], 1, SendParam);
                            OnOutStatus?.Invoke(string.Format("机器人[{0}]发送语音给第{1}个{2}[{3}-{4}]发送拆分文本成功:{5}", new object[] { SendParam.RobotQQ, sendCount + 1, objectText, ObjQQ, name, messages[j] }));
                        }
                        //算出分段间隔时间
                        int interval = PublicUtils.GetRandom(SendParam.NextIntervalDown, SendParam.NextIntervalUp + 1);
                        OnOutStatus?.Invoke(string.Format("机器人[{0}]进入语音分段休眠{1}秒!", new object[] { SendParam.RobotQQ, interval }));
                        Thread.Sleep(interval * 1000);
                    }
                }
            }
            else
            {
                SendTextMsg(MsgTo, ObjQQ, tempMessage, 1, SendParam);
            }
        }