public GroupMessageSettingViewModel(IEnumerable <IAutoAnswer> answers)
        {
            Answers  = answers;
            Settings = answers.Select(x => new SettingInfo {
                Name = x.Name, Key = x.SettingKey
            }).ToList();
            Items        = OrmManager.Fetch <GroupInfo>(x => x.StillIn && x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
            SavedCommand = new Command(() => {
                foreach (var setting in Settings)
                {
                    SelectedItem.SetState(setting.Key, setting.Selected);
                }
                OrmManager.Update(SelectedItem);
            });
            SelectedCommand = new Command(() => {
                if (string.IsNullOrEmpty(SelectedItem.State))
                {
                    SelectedItem.State = WorkContext.GetState <QQState>(Constract.CurrentQQState).State;
                }
                for (int i = 0; i < Settings.Count; i++)
                {
                    Settings[i].Selected = SelectedItem.GetState <bool>(Settings[i].Key);
                }

                RaisePropertyChanged(nameof(Settings));
                PrevSelectedItem = SelectedItem;
            }, () => SelectedItem != PrevSelectedItem && SelectedItem != null);
        }
示例#2
0
        public DefaultMessageSettingViewModel(IEnumerable <IAutoAnswer> answers)
        {
            Answers  = answers;
            Settings = answers.Select(x => new SettingInfo {
                Name = x.Name, Key = x.SettingKey
            }).ToList();
            Items        = OrmManager.Fetch <QQState>(x => x.Id > 0);
            SavedCommand = new Command(() => {
                foreach (var setting in Settings)
                {
                    SelectedItem.SetState(setting.Key, setting.Selected);
                }
                OrmManager.Update(SelectedItem);
                var client = SelectedItem.GetClient();
                if (client != null)
                {
                    client.DefaultState = SelectedItem.State;
                }
            });
            SelectedCommand = new Command(() => {
                if (string.IsNullOrEmpty(SelectedItem.State))
                {
                    SelectedItem.State = "{}";
                }
                for (int i = 0; i < Settings.Count; i++)
                {
                    Settings[i].Selected = SelectedItem.GetState <bool>(Settings[i].Key);
                }

                RaisePropertyChanged(nameof(Settings));
                PrevSelectedItem = SelectedItem;
            }, () => SelectedItem != PrevSelectedItem && SelectedItem != null);
        }
 public ListDisscussionViewModel(ILoggerFacade logger) //,ISmartService smartService: base(container)IUnityContainer container
 {
     Logger          = logger;
     Items           = OrmManager.Fetch <DiscussInfo>(x => x.StillIn);
     SelectedCommand = new Command(() => {
         Logger.Debug(SelectedItem.Name);
     }, () => SelectedItem != null);
     RefreshBasicCommand = new Command(() => {
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitDisscussList();
         Items = OrmManager.Fetch <DiscussInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ) && x.StillIn);
         RaisePropertyChanged(nameof(Items));
     });
     RefreshDetailCommand = new Command(() => {
         Task.Run(() => {
             foreach (var group in Items)
             {
                 var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
                 state?.GetClient().InitDisscussInfo(group.Did);
                 // smartService.InitDisscussInfo(group.Did);
             }
         });
         Items = OrmManager.Fetch <DiscussInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ) && x.StillIn);
         RaisePropertyChanged(nameof(Items));
     }, () => Items.Count() > 0);
     RefreshSelectedCommand = new Command(() => {
         // Logger.Debug(SelectedItem.Name);
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitDisscussInfo(SelectedItem.Did);
         //smartService.InitDisscussInfo(SelectedItem.Did);
         Items = OrmManager.Fetch <DiscussInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ) && x.StillIn);
         RaisePropertyChanged(nameof(Items));
     }, () => SelectedItem != null);
 }
示例#4
0
 protected override void OnLoaded()
 {
     TotalPage = (OrmManager.Count <SystemLogData>() + PageSize - 1) / PageSize;
     // base.OnLoaded();
     Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip((CurrentPage - 1) * PageSize).Take(PageSize);
     RaisePropertyChanged(nameof(TotalPage));
     RaisePropertyChanged(nameof(Logs));
 }
示例#5
0
 public ListSystemMessageLogViewModel(ILoggerFacade logger)  //: base(container)IUnityContainer container
 {
     Logger    = logger;
     Logs      = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Take(PageSize);
     TotalPage = (OrmManager.Count <SystemLogData>() + PageSize - 1) / PageSize;
     RaisePropertyChanged(nameof(CurrentPage));
     RaisePropertyChanged(nameof(Logs));
     SelectedCommand = new Command <TextBlock>(detailData => {
         detailData.Text = SelectedLog.OriginData;
         Logger.Log(SelectedLog.OriginData, Category.Debug, Priority.High);
     }, detailData => SelectedLog != null);
     GoToPageCommand = new Command(() => {
         Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage >= 1);
     FirstPageCommand = new Command(() => {
         CurrentPage = 1;
         Logs        = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage != 1 && CurrentPage <= TotalPage);
     NextPageCommand = new Command(() => {
         CurrentPage++;
         if (CurrentPage > TotalPage)
         {
             CurrentPage = TotalPage;
         }
         Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage < TotalPage);
     PrevPageCommand = new Command(() => {
         CurrentPage--;
         Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage > 1 && CurrentPage <= TotalPage);
     LastPageCommand = new Command(() => {
         CurrentPage = TotalPage;
         Logs        = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage < TotalPage);
 }
        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, "***");
                            }
                        }
                    }
                }
            }
        }
示例#7
0
 public ListFriendsViewModel() //ISmartService smartService: base(container)IUnityContainer container
 {
     Friends         = OrmManager.Fetch <FriendInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
     SelectedCommand = new Command(() => {
         Logger.Log(SelectedFriend.Nick, Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
     }, () => SelectedFriend != null);
     RefreshCommand = new Command(() => {
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitFriendList();
         //smartService.InitFriendList();
         Friends = OrmManager.Fetch <FriendInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
         RaisePropertyChanged(nameof(Friends));
     });
     RefreshSelectedCommand = new Command(() => {
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitGroupInfo(SelectedFriend.Uin);
         // smartService.InitFriendInfo(SelectedFriend.Uin);
         Friends = OrmManager.Fetch <FriendInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
         RaisePropertyChanged(nameof(Friends));
     }, () => SelectedFriend != null);
 }
        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;
                }
            }
        }
示例#9
0
        public ListQQStateViewModel(IUnityContainer container) //ISmartService smartService: base(container)IUnityContainer container
        {
            Container       = container;
            Logger          = container.Resolve <ILoggerFacade>();
            States          = OrmManager.Fetch <QQState>(x => x.Id > 0);
            SelectedCommand = new Command(() => {
                Logger.Log(SelectedState.QQNum.ToString(), Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
            }, () => SelectedState != null);
            RefreshCommand = new Command(() => {
                States = OrmManager.Fetch <QQState>(x => x.Id > 0);
                RaisePropertyChanged(nameof(States));
                // Logger.Log(SelectedGroup.Name, Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
            });
            TryLoginSelectedCommand = new Command(() => {
                Message = "开始登录";
                RaisePropertyChanged(nameof(Message));
                // var state = WorkContext.GetState<QQState>(Constract.CurrentQQState);
                // state?.GetClient().InitFriendList();
                var clientManager = ClientManager.GetClientManagerUser(container, SelectedState);
                WorkContext.SetState(Constract.CurrentQQState, SelectedState);
                WorkContext.SetState(Constract.CurrentQQ, SelectedState.QQNum);
                clientManager.Client.Logined += Client_Logined;
                if (clientManager.Client.TryLogin(SelectedState))
                {
                    Message = "登录成功";
                    RaisePropertyChanged(nameof(Message));
                }
                else
                {
                    Message = "登录失败";
                    RaisePropertyChanged(nameof(Message));
                }
                // States = OrmManager.Fetch<QQState>(x => x.Id > 0);

                Logger.Log(SelectedState.QQNum.ToString(), Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
            }, () => SelectedState != null);
        }
示例#10
0
 protected override void OnLoaded()
 {
     Items = OrmManager.Fetch <QQState>(x => x.Id > 0);
     RaisePropertyChanged(nameof(Items));
 }
示例#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);
                        }
                    }
                }
            }
        }
 protected override void OnLoaded()
 {
     CurrentQQ = WorkContext.GetState <long>(Constract.CurrentQQ);
     Items     = OrmManager.Fetch <GroupInfo>(x => x.StillIn && x.QQNum == CurrentQQ);
     RaisePropertyChanged(nameof(Items));
 }