public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } var anwer = ""; if (CommandKey.Any(x => context.Message.StartsWith(x))) { // bool EnableFlag = false; // if (context.State != null && context.GetState<bool>(SettingKey)) // { // EnableFlag = true; // } // else if(context.MessageType=="message"){ // EnableFlag = true; // } // if (EnableFlag) // { string[] tmp = context.Message.Split(' '); if (tmp.Length == 2) { anwer = GetStock(tmp[1], ""); } else if (tmp.Length == 3) { anwer = GetStock(tmp[1], tmp[2]); } else { context.Alerts.AddRange(Example()); } if (!string.IsNullOrEmpty(anwer)) { context.Answers.Add(anwer); var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "stock"; newlog.P1 = tmp[tmp.Length - 1]; newlog.Data = anwer; OrmManager.Insert(newlog); // } } } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } //var message = context.Message.ToLower(); if (CommandKey.Any(x => context.Message.IndexOf(x, StringComparison.InvariantCultureIgnoreCase) >= 0)) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { var result = GetResult(context.Message); if (result.Count() == 1 && string.IsNullOrEmpty(result[0])) { return; } else { context.Answers.AddRange(result); try { var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "orchard"; newlog.P1 = context.Message; newlog.Data = string.Join("回复了:", result); OrmManager.Insert(newlog); } catch { } } } } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } List <string> anwer = null; if (CommandKey.Any(x => context.Message.StartsWith(x))) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { string[] tmp = context.Message.Trim().Split(' '); if (tmp.Length == 2) { anwer = GetWeather(tmp[1]); } else { context.Alerts.AddRange(Example()); } if (anwer != null && anwer.Count > 0) { context.Answers.AddRange(anwer); var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "weather"; newlog.P1 = tmp[1]; newlog.Data = string.Join(",", anwer); OrmManager.Insert(newlog); } } } }
public void Answer(AnswerContext context) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { var words = OrmManager.Fetch <BadWords>(x => x.QQNum == context.CurrentQQ).Select(x => x.Word); if (words == null || words.Count() == 0) { return; } else { context.Answers.RemoveAll(x => string.IsNullOrEmpty(x)); for (int i = 0; i < context.Answers.Count; i++) { foreach (var word in words) { if (context.Answers[i].Contains(word)) { var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "badword"; newlog.P1 = word; newlog.Data = context.Answers[i]; OrmManager.Insert(newlog); context.Answers[i] = context.Answers[i].Replace(word, "***"); } } } } } }
public void Answer(AnswerContext context) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { var words = OrmManager.Fetch <BadWords>(x => x.QQNum == context.CurrentQQ && context.Message.Contains(x.Word)).Select(x => x.Word); if (words == null || words.Count() == 0) { return; } else { var template = "{0} 含有禁用词 {1},提出警告"; foreach (var word in words) { context.Alerts.Add(string.Format(template, context.FromUin, word)); } var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "badword"; newlog.P1 = string.Join(",", words); newlog.Data = context.Message; OrmManager.Insert(newlog); context.CanAnswer = false; } } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } var anwer = new SearchResult(); if (CommandKey.Any(x => context.Message.StartsWith(x))) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { string[] tmp = context.Message.Trim().Split(' '); if (tmp.Length == 2) { var keyword = tmp[1]; // anwer = GetWiki(tmp[1], ""); switch (tmp[0]) { case "互动百科": case "互动": { string url = "http://www.baike.com/wiki/" + keyword; string temp = QQClient.Get(url); if (temp.Contains("尚未收录")) { anwer.Answer = "没有找到这个词条哦~"; break; } temp = temp.Replace("<meta content=\"", "&"); temp = temp.Replace("\" name=\"description\">", "&"); string[] result = temp.Split('&'); if (!result[1].Equals("")) { anwer.Answer = result[1]; anwer.Url = "http://www.baike.com/wiki/" + HttpUtility.UrlEncode(keyword); } break; } case "维基百科": case "维基": { string url = "https://zh.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exsentences=2&exintro=&explaintext=&exsectionformat=plain&exvariant=zh&titles=" + keyword; string temp = QQClient.Get(url); JsonWikipediaModel temp1 = (JsonWikipediaModel)JsonConvert.DeserializeObject(temp, typeof(JsonWikipediaModel)); string[] result = temp1.query.pages.ToString().Split("{}".ToCharArray()); JsonWikipediaPageModel pages = (JsonWikipediaPageModel)JsonConvert.DeserializeObject("{" + tmp[2] + "}", typeof(JsonWikipediaPageModel)); if (pages.extract != null) { anwer.Answer = pages.extract; anwer.Url = "https://zh.wikipedia.org/wiki/" + HttpUtility.UrlEncode(keyword); } else { anwer.Answer = "没有找到这个Wiki哦~"; } break; } case "百度百科": case "百科": default: { string url = "http://wapbaike.baidu.com/item/" + keyword; string temp = QQClient.Get(url); if (temp.Contains("您所访问的页面不存在")) { anwer.Answer = "没有找到这个词条哦~"; } if (temp.Contains("百科名片")) { temp = temp.Replace(""", ""); temp = temp.Replace("&", ""); temp = temp.Replace("百科名片", "&"); string[] result = temp.Split('&'); temp = result[1]; temp = temp.Replace("<p>", "&"); temp = temp.Replace("</p>", "&"); result = temp.Split('&'); temp = result[1].Replace("</a>", ""); temp = temp.Replace("<b>", ""); temp = temp.Replace("</b>", ""); temp = temp.Replace("<i>", ""); temp = temp.Replace("</i>", ""); temp = temp.Replace("<a", "&"); temp = temp.Replace("\">", "&"); result = temp.Split('&'); temp = ""; for (int i = 0; i < tmp.Length; i += 2) { if ((!tmp[i].Contains("card-info")) && (!tmp[i].Contains("div class"))) { temp += tmp[i]; } } if (!temp.Equals("")) { anwer.Answer = temp; anwer.Url = "http://wapbaike.baidu.com/item/" + HttpUtility.UrlEncode(keyword); } else { anwer.Answer = "词条 " + keyword + " 请查看http://wapbaike.baidu.com/item/" + HttpUtility.UrlEncode(keyword); } } else { anwer.Answer = "没有找到这个词条哦~"; } break; } } } else { context.Alerts.AddRange(Example()); } if (!string.IsNullOrEmpty(anwer.Answer)) { if (anwer.Answer.Length + anwer.Url.Length >= 400) { context.Answers.Add(anwer.Answer.Substring(0, 400 - anwer.Url.Length - 6) + "..." + anwer.Url); } else { context.Answers.Add(anwer.Answer + anwer.Url); } // context.Answers.Add(anwer); var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "wiki"; newlog.P1 = tmp[1]; newlog.Data = anwer.Answer + anwer.Url; OrmManager.Insert(newlog); } } } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } var anwer = ""; if (CommandKey.Any(x => context.Message.StartsWith(x))) { bool EnableFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableFlag = true; } else if (context.MessageType == "message") { EnableFlag = true; } if (EnableFlag) { bool StudyFlag = true; bool SuperStudy = false; string[] tmp = context.Message.Split('^'); if (tmp.Length == 3) { SuperStudy = true; } if (tmp.Length != 3 || string.IsNullOrWhiteSpace(tmp[1]) || string.IsNullOrWhiteSpace(tmp[2])) { StudyFlag = false; SuperStudy = false; context.Alerts.AddRange(Example()); } if (SuperStudy) { string result = ""; result = AIStudy(tmp[1], tmp[2], context.FromUin, context.SendToId, true); anwer = GetStudyFlagInfo(result, "@" + context.FromNick, tmp[1], tmp[2]); if (!string.IsNullOrWhiteSpace(anwer)) { context.Answers.Add(anwer); var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "study"; newlog.P1 = tmp[1]; newlog.P2 = tmp[2]; newlog.Data = anwer; OrmManager.Insert(newlog); } return; } if (StudyFlag) { string result = ""; var Badwords = OrmManager.Fetch <BadWords>(x => x.QQNum == context.CurrentQQ).Select(x => x.Word).ToList(); if (Badwords.Count(x => tmp[1].Contains(x) || tmp[2].Contains(x)) > 0) { result = "ForbiddenWord"; anwer = "包含禁用词"; context.Answers.Add(anwer); return; } if (result.Equals("")) { result = AIStudy(tmp[1], tmp[2], context.FromUin, context.FromUin, false); } anwer = GetStudyFlagInfo(result, "@" + context.FromNick, tmp[1], tmp[2]); if (!string.IsNullOrWhiteSpace(anwer)) { context.Answers.Add(anwer); var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.SendToId; newlog.ToUin = context.FromUin; newlog.MessageType = "study"; newlog.P1 = tmp[1]; newlog.P2 = tmp[2]; newlog.Data = anwer; OrmManager.Insert(newlog); } } } } }
public void Answer(AnswerContext context) { if (!context.CanAnswer) { return; } var anwer = ""; bool EnableTalkFlag = false; if (context.State != null && context.GetState <bool>(SettingKey)) { EnableTalkFlag = true; } else if (context.MessageType == "message") { EnableTalkFlag = true; } bool MsgAdapterFlag = false; if (EnableTalkFlag) { anwer = AIGet(context.Message); if (!anwer.Equals("")) { var newlog = new AutoAnswerMessageLog(); newlog.FromUin = context.FromUin; newlog.ToUin = context.SendToId; newlog.MessageType = "talk"; newlog.P1 = context.Message; newlog.Data = anwer; OrmManager.Insert(newlog); context.Answers.Add(anwer); return; } string[] tmp1 = context.Message.Split("@#$(),,.。::;^&;“”~~!!#()%??》《、· \r\n\"".ToCharArray()); bool RepeatFlag = false; for (int i = 0; i < tmp1.Length && i < 10; i++) { if (tmp1[i].Equals(context.Message)) { continue; } for (int k = 0; k < i; k++) { if (tmp1[k].Equals(tmp1[i])) { RepeatFlag = true; } } if (RepeatFlag) { RepeatFlag = false; continue; } if (!tmp1[i].Equals("")) { context.Answers.Add(AIGet(tmp1[i])); MsgAdapterFlag = true; } } if (!MsgAdapterFlag) { string[] tmp2 = context.Message.Split("@#$(),,.。::;^&;“”~~!!#()%??》《、· \r\n\"啊喔是的么吧呀恩嗯了呢很吗".ToCharArray()); RepeatFlag = false; for (int i = 0; i < tmp2.Length && i < 10; i++) { if (tmp2[i].Equals(context.Message)) { continue; } for (int k = 0; k < i; k++) { if (tmp2[k].Equals(tmp2[i])) { RepeatFlag = true; } } for (int k = 0; k < tmp1.Length; k++) { if (tmp1[k].Equals(tmp2[i])) { RepeatFlag = true; } } if (RepeatFlag) { RepeatFlag = false; continue; } if (!tmp2[i].Equals("")) { context.Answers.Add(AIGet(tmp2[i])); MsgAdapterFlag = true; } } } } }