private CommonMessageResponse AddCount(CommonMessage cm) { string user = cm.UserId, group = cm.GroupId; try { Logger.Warn("发现好图,存了"); if (!UserCount.ContainsKey(user)) { UserCount.Add(user, 2); } UserCount[user]--; if (UserCount[user] != 0) { return(new CommonMessageResponse("?", cm, true)); } else { UserCount[user] = 2; CqApi.SetGroupBan(group, user, (int)(0.5 * 60 * 60)); return(new CommonMessageResponse("?", cm, true)); } } finally { SaveSettings(UserCount); } }
public override CommonMessageResponse Message_Received(CommonMessage messageObj) { if (messageObj.GroupId == "133605766") { return(null); } if (messageObj.GroupId == null) { return(null); } if (messageObj.ArgString.Trim() == "") { return(new CommonMessageResponse("要睡多少小时呀??", messageObj, true)); } double sleepTime; if (SleepTime > 12) { sleepTime = 12; } else if (SleepTime < 0.5) { sleepTime = 0.5; } else if (SleepTime > 0) { sleepTime = SleepTime; } else { return(new CommonMessageResponse("穿越是不可以的……", messageObj, true)); } DateTime dt = new DateTime(); dt = dt.AddHours(sleepTime); int s = (int)(dt.Ticks / 10000000); CqApi.SetGroupBan(messageObj.GroupId, messageObj.UserId, s); string msg = "祝你一觉睡到" + DateTime.Now.AddHours(sleepTime).ToString("HH:mm") + " :D"; return(new CommonMessageResponse(msg, messageObj, true)); }
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; }
/// <summary> /// 核心识别by sahuang /// </summary> private void RunDetector(object pathList) { var list = (List <string>)pathList; foreach (var fullPath in list) { try { //Thread.Sleep(6000); //continue; if (_proc != null) { if (!_proc.HasExited) { _proc.Kill(); } _proc = null; } _proc = new Process { StartInfo = { FileName = "python3", // python3 dragon-detection.py "root" Arguments = $"{Path.Combine(Domain.CurrentDirectory, "dragon", "dragon-detection.py")} \"{fullPath}\"", CreateNoWindow = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardOutput = true, // 重定向标准输出 RedirectStandardError = true // 重定向错误输出 //StartInfo.StandardOutputEncoding = Encoding.UTF8; } }; _proc.OutputDataReceived += ProcOutputReceived; _proc.ErrorDataReceived += ProcErrorReceived; Logger.Origin("正在调用中"); _proc.Start(); _proc.BeginOutputReadLine(); _proc.BeginErrorReadLine(); _proc.WaitForExit(); ProcExited(); } catch (Exception ex) { Logger.Exception(ex); } finally { _totalCount--; } } if (_currentCount <= 0) { return; } //CqApi.SetGroupBan(group, user, rnd.Next(1, 100 * dragonCount + 1) * 60); if (_group != "133605766") { CqApi.SendGroupMessageAsync(_group, new At(_user) + " 你龙了?"); } else { CqApi.DeleteMessage(_messageId); } if (_currentCount <= 1) { return; } Thread.Sleep(8000); CqApi.SetGroupBan(_group, _user, Rnd.Next(1, 100 * _currentCount + 1) * 60); //CqApi.SendGroupMessageAsync(group, "而且有好多张,送你" + dragonCount + "倍套餐!!"); }