public bool CanAnswer(AnswerContext context)
 {
     if (context.State != null && context.GetState <bool>(SettingKey))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 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);

                    // }
                }
            }
        }
Ejemplo n.º 3
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
                        { }
                    }
                }
            }
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void Answer(AnswerContext context)
        {
            if (!context.CanAnswer)
            {
                return;
            }
            if (context.State != null && context.GetState <bool>(SettingKey))
            {
                for (int j = 0; j < context.Answers.Count; j++)
                {
                    string[] tmp  = context.Answers[j].Split('{');
                    var      temp = "";
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        if (!tmp[i].StartsWith("..[face"))
                        {
                            temp += ("{}" + tmp[i]);
                        }
                        else
                        {
                            temp += tmp[i].Remove(0, 7);
                        }
                    }
                    context.Answers[j] = temp;

                    string[] filter = context.Answers[j].Split("{}".ToCharArray());

                    for (int i = 0; i < filter.Length; i++)
                    {
                        if (!filter[i].Trim().StartsWith("..[face") || !filter[i].Trim().EndsWith("].."))
                        {
                            context.Answers[j] += "\\\"" + filter[i] + "\\\",";
                        }
                        else
                        {
                            context.Answers[j] += filter[i].Replace("..[face", "[\\\"face\\\",").Replace("]..", "],");
                        }
                    }
                    context.Answers[j] = context.Answers[j].Remove(context.Answers[j].LastIndexOf(','));
                    context.Answers[j] = context.Answers[j].Replace("\r\n", "\n").Replace("\n\r", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine);
                }
            }
        }
        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;
                }
            }
        }
Ejemplo n.º 8
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);
                    }
                }
            }
        }
Ejemplo n.º 9
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);
                    }
                }
            }
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        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;
                        }
                    }
                }
            }
        }