Exemple #1
0
        public void ProcessPrivateMessage(PrivateMessageReceivedContext context)
        {
            if (context.Message.IndexOf("宠物绑定") == 0)
            {
                XmlSolve.del("qq_pet_uin", context.FromQq.ToString());
                XmlSolve.del("qq_pet_skey", context.FromQq.ToString());
                string[] str2;
                int      count_temp = 0;
                str2 = context.Message.Replace("宠物绑定", "").Split('/');
                foreach (string i in str2)
                {
                    if (count_temp == 0)
                    {
                        XmlSolve.insert("qq_pet_uin", context.FromQq.ToString(), i);
                        count_temp++;
                    }
                    else if (count_temp == 1)
                    {
                        XmlSolve.insert("qq_pet_skey", context.FromQq.ToString(), i);
                        count_temp++;
                    }
                }
                _mahuaApi.SendPrivateMessage(context.FromQq).Text("宠物绑定成功!").Done();
            }
            else
            {
                string replay = MessageSolve.GetReplay(context.FromQq, context.Message, _mahuaApi);
                if (replay != "")
                {
                    _mahuaApi.SendPrivateMessage(context.FromQq, replay);
                }
            }


            // 异步发送消息,不能使用 _mahuaApi 实例,需要另外开启Session
            //Task.Factory.StartNew(() =>
            //{
            //    using (var robotSession = MahuaRobotManager.Instance.CreateSession())
            //    {
            //        var api = robotSession.MahuaApi;
            //        api.SendPrivateMessage(context.FromQq, "异步的嘤嘤嘤");
            //    }
            //});
        }
 public void ProcessGroupMemberChanged(GroupMemberChangedContext context)
 {
     if (context.GroupMemberChangedType.ToString() == "Increased") //进群
     {
         _mahuaApi.SendGroupMessage(context.FromGroup, "欢迎" + Tools.At(context.JoinedOrLeftQq) + "进群!请仔细阅读群公告哦~");
     }
     else if (context.GroupMemberChangedType.ToString() == "Decreased")//退群
     {
         if (context.FromGroup == "241464054")
         {
             string player = XmlSolve.xml_get("bind_qq", context.JoinedOrLeftQq);
             if (player != "")
             {
                 _mahuaApi.SendGroupMessage("567145439", "检测到玩家" + player + "已退群,请管理进入游戏,执行\r\n/code " +
                                            MinecraftSolve.DelNewCode(player) + "\r\n命令来删除该玩家的白名单");
                 XmlSolve.del("bind_qq_wait", context.JoinedOrLeftQq);
                 XmlSolve.del("bind_qq", context.JoinedOrLeftQq);
             }
         }
     }
 }
        private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)  //定时程序
        {
            // 得到 hour minute second  如果等于某个值就开始执行某个程序。
            int intHour   = e.SignalTime.Hour;
            int intMinute = e.SignalTime.Minute;
            int intSecond = e.SignalTime.Second;

            //删除过期文件
            DirectoryInfo downloadDir = new DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "data/image/download/");

            FileSystemInfo[] downloadFiles = downloadDir.GetFileSystemInfos();
            for (int i = 0; i < downloadFiles.Length; i++)
            {
                FileInfo file = downloadFiles[i] as FileInfo;
                //是文件
                if (file != null)
                {
                    TimeSpan time = DateTime.Now - file.CreationTime;
                    if (time.TotalSeconds > 30)
                    {
                        file.Delete();
                    }
                }
            }

            if (intMinute == 0 && intSecond == 10 && intHour == 0 && Tools.special.Length > 0)
            {
                var _m    = MahuaRobotManager.Instance.CreateSession().MahuaApi;
                int count = Tools.GetXmlNumber("daily_sign_in_count_all", System.DateTime.Today.AddDays(-1).ToString());
                _m.SendGroupMessage("241464054", "新的一天已经到来了哦,现在时间是\r\n" + DateTime.Now.ToString() + "\r\n昨日一共有" + count + "人签到哦");
                _m.SendGroupMessage("567145439", DateTime.Now.ToString() + "\r\n今天一共有" + count + "人签到哦");
            }
            if (intMinute == 0 && intSecond == 10 && intHour == 4 && Tools.special.Length > 0)
            {
                var _m = MahuaRobotManager.Instance.CreateSession().MahuaApi;
                _m.SendGroupMessage("567145439", "服务器备份已开始,硬盘可用空间:\r\n" +
                                    "服务器盘剩余空间:" + ((float)Tools.GetHardDiskFreeSpace("D") / 1024).ToString(".00") + "GB\r\n" +
                                    "备份盘剩余空间:" + ((float)Tools.GetHardDiskFreeSpace("E") / 1024).ToString(".00") + "GB");
                System.Diagnostics.Process.Start(@"D:\backup.bat");
            }
            if (intMinute == 0 && intSecond == 10 && intHour == 5 && Tools.special.Length > 0)
            {
                var _m = MahuaRobotManager.Instance.CreateSession().MahuaApi;
                _m.SendGroupMessage("567145439", "服务器备份肯定已经结束了,硬盘可用空间:\r\n" +
                                    "服务器盘剩余空间:" + ((float)Tools.GetHardDiskFreeSpace("D") / 1024).ToString(".00") + "GB\r\n" +
                                    "备份盘剩余空间:" + ((float)Tools.GetHardDiskFreeSpace("E") / 1024).ToString(".00") + "GB");
                if (Tools.GetHardDiskFreeSpace("E") < 1024 * 10)
                {
                    _m.SendGroupMessage("567145439", Tools.At(Tools.adminNumber) + "警告:服务器备份盘可用空间仅剩余" +
                                        ((float)Tools.GetHardDiskFreeSpace("E") / 1024).ToString(".00") + "G!请及时清理多于文件!");
                }
            }

            if (intMinute == 0 && intSecond == 0 && intHour == 1)
            {
                var _m = MahuaRobotManager.Instance.CreateSession().MahuaApi;
                _m.SendGroupMessage(Tools.mainGroupNumber, "开始文件自动清理任务");
                int records = 0, imageall = 0, imgdel = 0;

                DirectoryInfo    dir   = new DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "data/record/");
                FileSystemInfo[] files = dir.GetFileSystemInfos();
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i] as FileInfo;
                    //是文件
                    if (file != null)
                    {
                        file.Delete();
                        records++;
                    }
                }

                DirectoryInfo    imgdir   = new DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "data/image/");
                FileSystemInfo[] imgfiles = imgdir.GetFileSystemInfos();
                for (int i = 0; i < imgfiles.Length; i++)
                {
                    FileInfo file = imgfiles[i] as FileInfo;
                    //是文件
                    if (file != null)
                    {
                        string img   = file.Name.Substring(0, file.Name.IndexOf("."));
                        bool   match = false;
                        imageall++;
                        foreach (string group in Tools.GetGroupList())
                        {
                            if (XmlSolve.IsAnswer(group, img))
                            {
                                match = true;
                                break;
                            }
                        }
                        if (XmlSolve.IsAnswer("common", img))
                        {
                            match = true;
                        }
                        if (!match)
                        {
                            imgdel++;
                            file.Delete();
                        }
                    }
                }

                _m.SendGroupMessage(Tools.mainGroupNumber, "任务执行完毕\r\n共删除" + records + "个语音文件\r\n"
                                    + "删除" + imageall + "张图片中的" + imgdel + "张");
            }
        }