示例#1
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            if (!messageObj.Message.Equals("/转"))
            {
                return(null);
            }
            using (Session session = new Session(1000 * 60, messageObj.Identity, messageObj.UserId))
            {
                SendMessage(new CommonMessageResponse("请发送图片,5张以内,1分钟内有效。", messageObj, true));
                try
                {
                    CommonMessage cm       = session.GetMessage();
                    var           infoList = CqCode.GetImageInfo(cm.Message);
                    if (infoList == null)
                    {
                        return(new CommonMessageResponse("你发送的消息没有包含图片。", cm));
                    }
                    if (infoList.Length > 5)
                    {
                        return(new CommonMessageResponse("你发送的图片过多。", cm));
                    }

                    List <Image> imgList = infoList.Select(imgInfo => HttpClientUtil.GetImageFromUrl(imgInfo.Url))
                                           .ToList();

                    var sendList = HandleImage(imgList);

                    return(new CommonMessageResponse(string.Join("\r\n", sendList), messageObj));
                }
                catch (TimeoutException)
                {
                    return(null);
                }
            }
        }
示例#2
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            if (messageObj.MessageType == MessageType.Private)
            {
                return(null);
            }
            var imgList = CqCode.GetImageInfo(messageObj.Message);

            if (imgList == null)
            {
                return(null);
            }

            string groupId = messageObj.GroupId ?? messageObj.DiscussId;

            if (!GroupDic.ContainsKey(groupId))
            {
                GroupDic.GetOrAdd(groupId, new GroupSettings
                {
                    GroupId    = groupId,
                    MessageObj = messageObj
                });
            }

            foreach (var item in imgList)
            {
                if (item.Extension.ToLower() == ".gif")
                {
                    continue;
                }
                if (item.FileInfo.Exists)
                {
                    GroupDic[groupId].PathQueue.Enqueue(item.FileInfo.FullName);
                }
                else
                {
                    string path = HttpClientUtil.SaveImageFromUrl(item.Url, System.Drawing.Imaging.ImageFormat.Jpeg);
                    GroupDic[groupId].PathQueue.Enqueue(path);
                }
#if DEBUG
                _totalCount++;
#endif
            }

            if (GroupDic[groupId].Task == null || GroupDic[groupId].Task.IsCompleted ||
                GroupDic[groupId].Task.IsCanceled)
            {
                GroupDic[groupId].Task = Task.Run(() => RunDetector(GroupDic[groupId]));
#if DEBUG
                Logger.Info("[" + groupId + "] (熊猫) 共 " + _totalCount);
#endif
            }

            return(null);
        }
示例#3
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            if (messageObj.MessageType == MessageType.Private)
            {
                return(null);
            }
            string groupId = messageObj.GroupId ?? messageObj.DiscussId;

            if (!GroupDic.ContainsKey(groupId))
            {
                GroupDic.GetOrAdd(groupId, new GroupSettings
                {
                    GroupId    = groupId,
                    MessageObj = messageObj
                });
            }
            //GroupDic[groupId].GroupType = messageObj.GroupId == null ? MessageType.Discuss : MessageType.Group;

            var imgList = CqCode.GetImageInfo(messageObj.Message);

            if (imgList == null)
            {
                return(null);
            }

            foreach (var item in imgList)
            {
                if (item.Extension.ToLower() == ".gif")
                {
                    continue;
                }
                if (item.FileInfo.Exists)
                {
                    GroupDic[groupId].PathQueue.Enqueue(item.FileInfo.FullName);
                }
                else
                {
                    WebRequestUtil.GetImageFromUrl(item.Url, item.Md5, item.Extension);
                    GroupDic[groupId].PathQueue.Enqueue(Path.Combine(Domain.CurrentDirectory, "images",
                                                                     item.Md5 + item.Extension));
                }

                _totalCount++;
            }

            if (GroupDic[groupId].Task == null || GroupDic[groupId].Task.IsCompleted ||
                GroupDic[groupId].Task.IsCanceled)
            {
                GroupDic[groupId].Task = Task.Run(() => RunDetector(GroupDic[groupId]));
                Logger.Info("[" + groupId + "] (熊猫) 共 " + _totalCount);
            }

            return(null);
        }
示例#4
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            if (messageObj.Group == null)
            {
                return(null);
            }

            //if (user != "2241521134") return null;
            _user      = messageObj.UserId;
            _group     = messageObj.GroupId;
            _messageId = messageObj.MessageId;

            var imgList = CqCode.GetImageInfo(messageObj.Message);

            if (imgList == null)
            {
                return(null);
            }

            foreach (var item in imgList)
            {
                if (item.Extension.ToLower() == ".gif")
                {
                    continue;
                }
                if (item.FileInfo.Exists)
                {
                    _pathList.Add(item.FileInfo.FullName);
                }
                else
                {
                    WebRequestUtil.GetImageFromUrl(item.Url, item.Md5, item.Extension);
                    _pathList.Add(Path.Combine(Domain.CurrentDirectory, "images", item.Md5 + item.Extension));
                }

                _totalCount++;
            }

            _thread = new Thread(RunDetector);
            _thread.Start(_pathList);
            Logger.Warn("已经发送了请求,目前队列中共" + _totalCount);
            return(null);
        }
示例#5
0
        public static void Query()
        {
            while (MessageQueue.Count != 0)
            {
                if (!MessageQueue.TryDequeue(out var messageObj))
                {
                    continue;
                }
                var cmd = messageObj.Command;

                const long cabbageId = 1020640876;
                string     uname;
                if (cmd == "statme" || cmd == "bpme" || cmd == "mybp" || cmd == "costme" || cmd == "mycost")
                {
                    BllUserRole        bllUserRole = new BllUserRole();
                    List <TblUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId));
                    if (userInfo.Count == 0)
                    {
                        CoolQDispatcher.SendMessage(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true));
                    }

                    uname = userInfo[0].CurrentUname;
                }
                else
                {
                    uname = messageObj.ArgString;
                }

                using (Session session = new Session(25000, new Identity(cabbageId, MessageType.Private), cabbageId))
                {
                    CoolQDispatcher.SendMessage(
                        new CommonMessageResponse($"!{cmd.Replace("my", "").Replace("me", "")} {uname}",
                                                  new Identity(cabbageId, MessageType.Private)));
                    try
                    {
                        CommonMessage result = session.GetMessage();
                        session.Timeout = 600;
                        CommonMessage result2 = null;
                        try
                        {
                            result2 = session.GetMessage();
                        }
                        catch
                        {
                            // ignored
                        }

                        ImageInfo[] imgList =
                            CqCode.GetImageInfo(result.Message) ?? CqCode.GetImageInfo(result2?.Message);

                        if (imgList == null)
                        {
                            CoolQDispatcher.SendMessage(new CommonMessageResponse(result.Message, messageObj));
                            if (result2 != null)
                            {
                                CoolQDispatcher.SendMessage(new CommonMessageResponse(result2.Message, messageObj));
                            }
                            continue;
                        }
                        //throw new IndexOutOfRangeException("查询失败:" + result.Message);
                        var message = CqCode.DecodeToString(result.Message);
                        foreach (var item in imgList)
                        {
                            var          str = new FileImage(new Uri(item.Url));
                            StringFinder sf  = new StringFinder(message);
                            sf.FindNext("[图片]");
                            string str1 = sf.Cut();
                            if (sf.FindNext("[图片]", false) > message.Length - 1)
                            {
                                message = str1 + str;
                                continue;
                            }

                            sf.FindToLast();
                            string str2 = sf.Cut();
                            message = str1 + str + str2;
                        }

                        CoolQDispatcher.SendMessage(
                            new CommonMessageResponse(message + "\r\n(查询由白菜支持)", messageObj));
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        string msg = e.Message;
                        CoolQDispatcher.SendMessage(new CommonMessageResponse(msg, messageObj, true));
                    }
                    catch (TimeoutException)
                    {
                        string msg = "查询失败,白菜没有搭理人家..";
                        CoolQDispatcher.SendMessage(new CommonMessageResponse(msg, messageObj, true));
                    }
                    catch (Exception ex)
                    {
                        string msg = "查询失败,未知错误。";
                        Logger.Exception(ex);
                        CoolQDispatcher.SendMessage(new CommonMessageResponse(msg, messageObj, true));
                    } // catch
                }     // using
            }         // while
        }             //void
示例#6
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            // 查黄图
            if (messageObj.Group == null || messageObj.GroupId != "133605766")
            {
                return(null);
            }
            var imgList = CqCode.GetImageInfo(messageObj.Message);

            if (imgList == null)
            {
                return(null);
            }
            List <string>    urlList   = new List <string>();
            List <CosObject> cacheList = new List <CosObject>();

            foreach (var item in imgList)
            {
                if (Md5List.Keys.Contains(item.Md5))
                {
                    cacheList.Add(Md5List[item.Md5]);
                }
                else if (item.Size > 1000 * 60) //60KB
                {
                    urlList.Add(item.Url);
                }
            }

            if (urlList.Count == 0 && cacheList.Count == 0)
            {
                return(null);
            }

            Logger.Warn("发现了" + (urlList.Count + cacheList.Count) + "张图");

            CosAnalyzer model = new CosAnalyzer
            {
                result_list = new List <CosObject>()
            };

            if (urlList.Count != 0)
            {
                string str = Newtonsoft.Json.JsonConvert.SerializeObject(new
                {
                    appid    = "1252749411",
                    url_list = urlList.ToArray()
                });

                var abc = WebRequestUtil.CreatePostHttpResponse(
                    "http://service.image.myqcloud.com/detection/porn_detect", str, authorization: Signature.Get());
                var respStr = WebRequestUtil.GetResponseString(abc);

                model = Newtonsoft.Json.JsonConvert.DeserializeObject <CosAnalyzer>(respStr);
            }

            model.result_list.AddRange(cacheList);
            int i = 0;

            foreach (var item in model.result_list)
            {
                if (i < imgList.Length && !Md5List.Keys.Contains(imgList[i].Md5))
                {
                    Md5List.Add(imgList[i].Md5, item);
                }
                i++;

                switch (item.data.result)
                {
                case 0 when item.data.normal_score > item.data.hot_score &&
                    item.data.normal_score > item.data.porn_score && item.data.confidence > 40:
                    continue;

                case 1:
                case 2:
                    CqApi.SetGroupBan(messageObj.GroupId, messageObj.UserId, 24 * 60 * 60);
                    return(new CommonMessageResponse("...", messageObj));

                default:
                    break;
                }

                if (item.data.porn_score >= item.data.hot_score && item.data.porn_score > 65)
                {
                    return(AddCount(messageObj));
                }

                if (item.data.hot_score >= item.data.porn_score && item.data.hot_score > item.data.normal_score &&
                    item.data.hot_score > 80)
                {
                    return(AddCount(messageObj));
                }

                break;
            }

            return(null);

            //if (user != "2241521134") return null;
        }