示例#1
0
        /// <summary>
        /// Type=2 群消息<para/>
        /// 处理收到的群消息
        /// </summary>
        /// <param name="sender">事件的触发对象</param>
        /// <param name="e">事件的附加参数</param>
        public void ReceiveGroupMessage(object sender, GroupMessageEventArgs e)
        {
            // 本子程序会在酷Q【线程】中被调用,请注意使用对象等需要初始化(CoInitialize,CoUninitialize)。
            // 这里处理消息
            try
            {
                Regex regex = new Regex(@"^.(\S+) *(\d*)\r\n([\s\S]+)$");   //注意匹配1后面是“ *”,也就是任意个空格
                Match match = regex.Match(e.Msg);
                if (match.Success)
                {
                    string type = match.Groups[1].Value;
                    if (type == "表情" || type == "表情包")
                    {
                        type = Pic.GetRandomPic();
                    }

                    if (Pic.PicExist(type))
                    {
                        Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Debug, "生成表情", type);
                        Pic pic = new Pic(type);

                        int.TryParse(match.Groups[2].Value, out int size);
                        string content = match.Groups[3].Value;
                        pic.Make(content, size);

                        string filename = pic.Save(e.FromGroup);
                        Common.CqApi.SendGroupMessage(e.FromGroup, Common.CqApi.CqCode_Image(filename));

                        e.Handled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "错误", ex.Message);
            }
        }