Example #1
0
 public void Answer(AnswerContext context)
 {
     if (!context.CanAnswer)
     {
         return;
     }
     if (CommandKey.Any(x => context.Message.StartsWith(x)))
     {
         string[] tmp = context.Message.Split(' ');
         var      reg = new Regex("([0-9]{7,11})");
         if (tmp.Length == 2)
         {
             var phone = reg.Match(tmp[1]);
             if (phone.Success)
             {
                 var result = GetPhone(phone.Value);
                 if (result != null)
                 {
                     context.Answers.Add(string.Join(",", result));
                 }
             }
             else
             {
                 context.Alerts.Add("格式不对,参考:" + Example()[0]);
             }
         }
     }
 }
Example #2
0
        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);

                    // }
                }
            }
        }
Example #3
0
 public void Answer(AnswerContext context)
 {
     if (!context.CanAnswer)
     {
         return;
     }
     if (CommandKey.Any(x => context.Message.StartsWith(x)))
     {
         string[] tmp   = context.Message.Split(' ');
         var      reg15 = new Regex("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3$");
         var      reg18 = new Regex("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$");
         if (tmp.Length == 2)
         {
             var id15 = reg15.Match(tmp[1]);
             if (id15.Success)
             {
                 var result = GetID(id15.Value);
                 if (result != null)
                 {
                     context.Answers.Add(string.Join(Environment.NewLine, result));
                 }
             }
             else
             {
                 var id18 = reg18.Match(tmp[1]);
                 if (id18.Success)
                 {
                     var result = GetID(id18.Value);
                     if (result != null)
                     {
                         context.Answers.Add(string.Join(",", result));
                     }
                 }
                 else
                 {
                     context.Alerts.Add("格式不对,参考:" + Example()[0]);
                 }
             }
         }
         else
         {
             context.Alerts.Add("格式不对,参考:" + Example()[0]);
         }
     }
 }
Example #4
0
        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
                        { }
                    }
                }
            }
        }
Example #5
0
        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);
                    }
                }
            }
        }
Example #6
0
        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("&quot;", "");
                                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);
                    }
                }
            }
        }
Example #7
0
        public void Answer(AnswerContext context)
        {
            if (!context.CanAnswer)
            {
                return;
            }

            if (CommandKey.Any(x => context.Message.Equals(x)))
            {
                bool EnableFlag = false;
                if (context.State != null && context.GetState <bool>(SettingKey))
                {
                    EnableFlag = true;
                }
                else if (context.MessageType == "message")
                {
                    EnableFlag = true;
                }
                if (EnableFlag)
                {
                    var answer = "";
                    foreach (var ans in context.SmartService.GetAnswers().Where(x => x.ShowInMenu && x.CanAnswer(context)))
                    {
                        var commandtext = "";
                        var exampletext = "";
                        //context.Answers.Add(ans.Name);
                        if (ans.Template() != null)
                        {
                            commandtext = "命令格式:" + Environment.NewLine + string.Join(Environment.NewLine, ans.Template());
                        }
                        //context.Answers.Add();
                        if (ans.Example() != null)
                        {
                            exampletext = "示例:" + Environment.NewLine + string.Join(Environment.NewLine, ans.Example());
                        }
                        //context.Answers.Add("示例:"+string.Join(",", ans.Example()));
                        if (answer.Length + ans.Name.Length < 400)
                        {
                            answer += ans.Name + Environment.NewLine;
                        }
                        else
                        {
                            context.Answers.Add(answer);
                            answer = ans.Name + Environment.NewLine;
                        }
                        if (answer.Length + commandtext.Length < 400)
                        {
                            answer += commandtext;
                        }
                        else
                        {
                            context.Answers.Add(answer);
                            answer = commandtext;
                        }

                        if (answer.Length + exampletext.Length < 400)
                        {
                            answer += exampletext;
                        }
                        else
                        {
                            context.Answers.Add(answer);
                            answer = exampletext;
                        }
                    }

                    if (!string.IsNullOrEmpty(answer))
                    {
                        context.Answers.Add(answer);
                    }
                }
            }
        }
Example #8
0
        public void Answer(AnswerContext context)
        {
            var anwer = "";

            if (CommandKey.Any(x => context.Message.StartsWith(x)) && context.IsManager)
            {
                bool EnableFlag = false;
                if (context.State != null && context.GetState <bool>(SettingKey))
                {
                    EnableFlag = true;
                }
                if (EnableFlag)
                {
                    var groupInfo = OrmManager.Get <GroupInfo>(x => x.QQNum == context.CurrentQQ && x.GroupId == context.SendToId);
                    context.SmartService.InitGroupInfo(context.SendToId);
                    var  adminuin   = groupInfo.Owner;
                    var  memberInfo = OrmManager.Get <MemberInfo>(x => x.QQNum == context.CurrentQQ && x.GroupId == context.SendToId && x.Uin == context.FromUin);
                    bool HaveRight  = false;
                    if (context.FromUin.Equals(adminuin)) //|| context.SmartService.InitRealQQ(context.FromUin).Equals(MasterQQ)
                    {
                        HaveRight = true;
                    }
                    else if (memberInfo != null && memberInfo.IsManager)
                    {
                        HaveRight = true;
                    }
                    else
                    {
                        HaveRight = false;
                    }
                    string[] tmp = context.Message.Trim().Split(' ');
                    if (tmp.Length == 1)
                    {
                        context.Alerts.AddRange(Example());


                        return;
                    }
                    tmp[1] = tmp[1].Replace("\r", "").Replace("\n", "").Replace(" ", "");
                    if (tmp.Length < 2 || tmp[1] == null)
                    {
                        return;
                    }
                    if ((HaveRight) && (tmp[1].Equals("查询状态") || tmp[1].Equals("状态")))
                    {
                        string enableFormate  = "{0}已经启动,关闭命令:群管理 关闭 {0}";
                        string disableFormate = "{0}暂未启动,启动命令:群管理 启动 {0}";
                        foreach (var answer in context.SmartService.GetAnswers().Except(new[] { this }))
                        {
                            if (context.GetState <bool>(answer.SettingKey))
                            {
                                context.Answers.Add(string.Format(enableFormate, answer.Name));
                            }
                            else
                            {
                                context.Answers.Add(string.Format(disableFormate, answer.Name));
                            }
                        }
                        return;
                    }
                    if (HaveRight == false)
                    {
                        if (context.FromRealQQ != 0)
                        {
                            anwer = "用户" + context.FromNick + "不是群管理,无权进行此操作";
                        }
                        else
                        {
                            anwer = context.FromNick + "不是群管理,无权进行此操作";
                        }
                        context.Answers.Add(anwer);
                        return;
                    }
                    else
                    {
                        tmp[1] = tmp[1].Replace("开启", "启动");
                        tmp[1] = tmp[1].Replace("开起", "启动");

                        if (tmp.Length != 3 || tmp[2] == null)
                        {
                            return;
                        }
                        string enableFormate  = "{0}已经启动,关闭命令:群管理 关闭 {0}";
                        string disableFormate = "{0}已经关闭,启动命令:群管理 启动 {0}";
                        string NoThisFormate  = "没有这个 {0} 答话机";
                        var    answers        = context.SmartService.GetAnswers().Except(new[] { this });
                        var    answer         = answers.Where(x => x.Name == tmp[2]);
                        if (answer == null)
                        {
                            context.Answers.Add(string.Format(NoThisFormate, tmp[2]));
                            return;
                        }
                        else
                        {
                            foreach (var item in answer)
                            {
                                if (tmp[2] == item.Name)
                                {
                                    if (tmp[1] == "启动")
                                    {
                                        context.SetState(item.SettingKey, true);
                                        context.Answers.Add(string.Format(enableFormate, item.Name));
                                    }
                                    else
                                    {
                                        context.SetState(item.SettingKey, false);
                                        context.Answers.Add(string.Format(disableFormate, item.Name));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (CommandKey.Any(x => context.Message.StartsWith(x)) && !context.IsManager)
            {
                anwer = "你不是管理员,没有权限";
                context.Answers.Add(anwer);
            }
        }
Example #9
0
        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);
                        }
                    }
                }
            }
        }