Exemple #1
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            string userName, userId;

            if (OsuId == null)
            {
                BllUserRole        bllUserRole = new BllUserRole();
                List <TblUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId));
                if (userInfo.Count == 0)
                {
                    return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true));
                }
                userId   = userInfo[0].UserId.ToString();
                userName = userInfo[0].CurrentUname;
            }
            else
            {
                int userNum = OldSiteApi.GetUser(OsuId, out var userObj);
                if (userNum == 0)
                {
                    return(new CommonMessageResponse(LoliReply.IdNotFound, messageObj, true));
                }
                if (userNum > 1)
                {
                    // ignored
                }

                userId   = userObj.user_id;
                userName = userObj.username;
            }

            var jsonString = HttpClientUtil.HttpGet("https://syrin.me/pp+/u/" + userId);

            if (jsonString == null)
            {
                return(new CommonMessageResponse("PP+获取超时,请重试…", messageObj, true));
            }

            StringFinder sf = new StringFinder(jsonString);

            sf.FindNext("<div class=\"performance-table\">", false);
            sf.FindNext("</div>");

            string    innerText = sf.Cut().Trim('\n').Trim('\r');
            HtmlTable htmlTable = new HtmlTable(innerText);

            string[,] array = htmlTable.GetArray();

            Dictionary <string, int> dValue = new Dictionary <string, int>();

            for (var i = 0; i < array.GetLength(0); i++)
            {
                for (var j = 0; j < array.GetLength(1); j += 2)
                {
                    string key   = array[i, j].Trim(':').Replace("Aim (", "").Replace(")", "");
                    int    value = int.Parse(array[i, j + 1].Replace(",", "").Trim('p'));
                    dValue.Add(key, value);
                }
            }

            var cqImg = new FileImage(Draw(userName, dValue)).ToString();

            return(new CommonMessageResponse(cqImg, messageObj));
        }
Exemple #2
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            string id;
            string uname;

            if (OsuId == null)
            {
                BllUserRole        bllUserRole = new BllUserRole();
                List <TblUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId));
                if (userInfo.Count == 0)
                {
                    return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true));
                }

                id    = userInfo[0].UserId.ToString();
                uname = userInfo[0].CurrentUname;
            }
            else
            {
                int userNum = OldSiteApi.GetUser(OsuId, out var userObj);
                if (userNum == 0)
                {
                    return(new CommonMessageResponse(LoliReply.IdNotFound, messageObj, true));
                }
                if (userNum > 1)
                {
                    // ignored
                }

                id    = userObj.user_id;
                uname = userObj.username;
            }

            List <KudosuInfo> totalList = new List <KudosuInfo>();
            List <KudosuInfo> tmpList;
            int       page  = 0;
            const int count = 20;

            do
            {
                string json =
                    HttpClientUtil.HttpGet("https://osu.ppy.sh/users/" + id + "/kudosu?offset=" + page + "&limit=" +
                                           count);
                Logger.Debug("GET JSON");

                tmpList = JsonConvert.DeserializeObject <List <KudosuInfo> >(json);
                totalList.AddRange(tmpList);
                page += count;

                if (totalList.Count != 0)
                {
                    continue;
                }

                return(new CommonMessageResponse("此人一张图都没摸过……", messageObj, true));
            } while (tmpList.Count != 0);

            List <KdInfo> kdInfoList = new List <KdInfo>();
            int           pastMonth  = -1;
            KdInfo        info       = null;

            totalList.Reverse();
            foreach (var item in totalList)
            {
                if (item.Created_At.Month != pastMonth)
                {
                    if (pastMonth != -1)
                    {
                        kdInfoList.Add(info);
                    }
                    info = new KdInfo
                    {
                        Time = item.Created_At
                    };
                    pastMonth = item.Created_At.Month;
                }

                if (info != null)
                {
                    info.Count++;
                }
            }

            if (info != null)
            {
                kdInfoList.Add(info);
            }

            var cqImg = new FileImage(Draw(kdInfoList, uname)).ToString();

            return(new CommonMessageResponse(cqImg, messageObj));
        }
Exemple #3
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            _cm = messageObj;
            if (List)
            {
                if (_cm.PermissionLevel == PermissionLevel.Root)
                {
                    BllUserRole   bllUserRole = new BllUserRole();
                    List <string> strs        = new List <string>();
                    foreach (var item in _matchList)
                    {
                        var    userInfo = bllUserRole.GetUserRoleByQq(long.Parse(item.Qq))[0];
                        string osuName  = userInfo.CurrentUname;
                        string id       = item.SetId;
                        string status;

                        if (item.TargetQq == null)
                        {
                            status = "等待匹配";
                        }
                        else
                        {
                            var    info = bllUserRole.GetUserRoleByQq(long.Parse(item.TargetQq))[0];
                            string name = info.CurrentUname;
                            status = $"已经和{name}匹配";
                        }

                        if (id == null)
                        {
                            strs.Add(osuName + ": 闲置中。");
                        }
                        else
                        {
                            strs.Add($"{osuName}  地图号: s/{id} {status}");
                        }
                    }

                    return(new CommonMessageResponse(string.Join("\r\n", strs), _cm));
                }
                else
                {
                    return(new CommonMessageResponse(LoliReply.RootOnly, _cm));
                }
            }

            if (_cm.MessageType != MessageType.Private)
            {
                return(new CommonMessageResponse(LoliReply.PrivateOnly, _cm));
            }

            try
            {
                using (_session = new Session(DefaultTimeout, _cm.Identity, _cm.UserId))
                {
                    BllUserRole        bllUserRole = new BllUserRole();
                    List <TblUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId));
                    if (userInfo.Count == 0)
                    {
                        return(new CommonMessageResponse("这个功能是需要绑定osu id的,请使用/setid完成绑定", messageObj, true));
                    }

                    _osuId = userInfo[0].UserId.ToString();

                    try
                    {
                        // Init
                        if (!_matchList.Select(q => q.Qq).Contains(_cm.UserId))
                        {
                            const string intro = @"这是一个利用我进行自动化管理的M4M平台,只需将图的链接给我,你无需自己各处求摸。
我会地合理地从库中挑选,并与你和另一人互相推荐,以达成自动匹配M4M的目的。
每个人只能给我一张图,第二张图会覆盖第一张图,所以有什么图需摸要记得更新哦!
最重要的一点:这仅仅是一个平台,真正的交流还需面对面进行。";
                            SendMessage(new CommonMessageResponse(intro, _cm));

                            _matchList.Add(new MatchInfo(_cm.UserId));
                            SaveMatchList(); //apply

                            Thread.Sleep(8000);
                        }

                        // Load
                        _myInfo             = _matchList.FirstOrDefault(q => q.Qq == _cm.UserId);
                        _myInfo.IsOperating = true;
                        _myInfo.LastUse     = DateTime.Now;
                        if (PluginManager.ApplicationList.FirstOrDefault(o => o.GetType() == typeof(M4MMatchNotice)) is M4MMatchNotice plugin)
                        {
                            if (M4MMatchNotice.Tipped.ContainsKey(_myInfo.Qq))
                            {
                                M4MMatchNotice.Tipped[_myInfo.Qq] = DateTime.Now;
                            }
                            else
                            {
                                M4MMatchNotice.Tipped.TryAdd(_myInfo.Qq, DateTime.Now);
                            }
                            plugin.SaveSettings();
                        }
                        // Confirm
                        if (Confirm)
                        {
                            if (_myInfo.TargetQq == null)
                            {
                                return(new CommonMessageResponse("你尚且还没有正在进行的匹配。", _cm));
                            }

                            var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);
                            if (DateTime.Now - oInfo.LastConfirmedTime < new TimeSpan(3, 0, 0))
                            {
                                return(new CommonMessageResponse("你已在三小时之内发出过核对确认,请稍后再试。", _cm));
                            }
                            oInfo.RequestBeConfirmed();
                            SaveMatchList(); //apply

                            string nick = CqApi.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家";
                            SendMessage(new CommonMessageResponse($"你已经确认了{nick}({oInfo.Qq})的摸,请及时完成自己的摸!", _cm));

                            string nick2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家";
                            SendMessage(new CommonMessageResponse($"{nick2}({_myInfo.Qq})已经确认查收了你的摸。",
                                                                  new Identity(oInfo.Qq, MessageType.Private)));

                            if (oInfo.LastConfirmedTime == null || _myInfo.LastConfirmedTime == null)
                            {
                                return(null);
                            }
                            Thread.Sleep(2000);
                            oInfo.FinishedSet.Add(_myInfo.SetId);
                            _myInfo.FinishedSet.Add(oInfo.SetId);
                            oInfo.Finish();
                            _myInfo.Finish();
                            SendMessage(new CommonMessageResponse(
                                            $"你与{nick}({oInfo.Qq})的M4M ({oInfo.SetUrl}) 已完成,合作愉快!",
                                            new Identity(_myInfo.Qq, MessageType.Private)));
                            SendMessage(new CommonMessageResponse(
                                            $"你与{nick2}({_myInfo.Qq})的M4M ({_myInfo.SetUrl}) 已完成,合作愉快!",
                                            new Identity(oInfo.Qq, MessageType.Private)));
                            SaveMatchList(); //apply
                            return(null);
                        }
                        // Finish
                        else if (Finish)
                        {
                            var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);
                            if (DateTime.Now - _myInfo.LastNoticeTime < new TimeSpan(3, 0, 0))
                            {
                                return(new CommonMessageResponse("你已在三小时之内发出过完成提醒,请稍后再试。", _cm));
                            }
                            _myInfo.RequestFinishMatch();
                            SaveMatchList(); //apply

                            string nick2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家";
                            SendMessage(new CommonMessageResponse(
                                            $"{nick2}({_myInfo.Qq})已经摸完了你的图:\r\n" +
                                            $"{oInfo.SetUrl}\r\n" +
                                            $"正在等待你的摸。\r\n" +
                                            $"请检查他的modding情况,回复 \"/m4m -确认\" 查收。\r\n" +
                                            $"若对方没有摸完,请不要查收。若有疑问请相互交流。",
                                            new Identity(oInfo.Qq, MessageType.Private)));
                            return(new CommonMessageResponse("已发送完成请求。", _cm));
                        }
                        // Cancel
                        else if (Cancel)
                        {
                            var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);

                            if (oInfo.MatchTime == null)
                            {
                                oInfo.MatchTime = DateTime.Now; // 临时补救
                            }
                            if (DateTime.Now - oInfo.MatchTime < new TimeSpan(7, 0, 0, 0))
                            {
                                return(new CommonMessageResponse("取消失败,仅匹配持续一周以上才可取消。", _cm));
                            }

                            string nick  = CqApi.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家";
                            string nick2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家";

                            oInfo.FinishedSet.Add(_myInfo.SetId);
                            _myInfo.FinishedSet.Add(oInfo.SetId);
                            oInfo.Finish();
                            _myInfo.Finish();
                            SendMessage(new CommonMessageResponse(
                                            $"你与{nick}({oInfo.Qq})的M4M ({oInfo.SetUrl}) 已强制取消。",
                                            new Identity(_myInfo.Qq, MessageType.Private)));
                            SendMessage(new CommonMessageResponse(
                                            $"你与{nick2}({_myInfo.Qq})的M4M ({_myInfo.SetUrl}) 已强制取消。",
                                            new Identity(oInfo.Qq, MessageType.Private)));
                            SaveMatchList(); //apply
                            return(null);
                        }

                        // No set after load
                        if (_myInfo.Set == null)
                        {
                            return(SessionNoMap());
                        }

                        // Matched Main
                        string info;
                        if (_myInfo.TargetQq != null)
                        {
                            var    oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq);
                            string nick  = CqApi.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家";
                            info = $"你已经成功和{nick}({oInfo.Qq})匹配\r\n" +
                                   $"· 你的信息:\r\n" +
                                   $"    地图地址:{_myInfo.SetUrl}\r\n" +
                                   $"    备注:{_myInfo.Mark}\r\n" +
                                   $"· 他的信息:\r\n" +
                                   $"    地图地址:{oInfo.SetUrl} \r\n" +
                                   $"    备注:{oInfo.Mark}\r\n" +
                                   $"当你摸图完成时,请使用 \"/m4m -完成\" 提醒对方审阅。\r\n" +
                                   $"当对方向你提出审阅请求后,请使用 \"/m4m -确认\" 完成审阅。\r\n" +
                                   $"若匹配持续超过一周,可使用  \"/m4m -取消\" 强制取消,且下次不会匹配到此图。";
                            return(new CommonMessageResponse(info, _cm));
                        }

                        // Main
                        info = $"· 你的信息:\r\n" +
                               $"    地图地址:{_myInfo.SetUrl} \r\n" +
                               $"    备注:{_myInfo.Mark}\r\n" +
                               $"· 从下面的选项中选择一个你想进行的操作:\r\n" +
                               $">【1】删除已发布的地图。\r\n" +
                               $">【2】管理摸图偏好(当前:{_myInfo.GetPreferenceString()})。\r\n" +
                               $">【3】开始进行m4m匹配。";

                        SendMessage(new CommonMessageResponse(info, _cm));
                        CommonMessage cmMain = SessionCondition("1", "2", "3");
                        switch (cmMain.Message)
                        {
                        case "1":
                            SendMessage(new CommonMessageResponse("删除现有地图,确认吗?\r\n" +
                                                                  "【1】是 【2】否", _cm));
                            CommonMessage cmPub = SessionCondition("1", "2");
                            if (cmPub.Message == "1")
                            {
                                _myInfo.RemoveSet();
                                SaveMatchList();     //apply
                                return(new CommonMessageResponse("删除成功。使用/m4m重新发布地图。", _cm));
                            }
                            else
                            {
                                return(new CommonMessageResponse("你已取消操作。", _cm));
                            }

                        case "2":
                            if (SessionMode(out var sessionNoMap))
                            {
                                return(sessionNoMap);
                            }
                            return(null);

                        case "3":     // core
                            MatchInfo[] fullList = _matchList.Where(i =>
                                                                    i.Qq != _myInfo.Qq && i.TargetQq == null && i.Set != null && !i.IsOperating &&
                                                                    DateTime.Now - i.LastUse < new TimeSpan(7, 0, 0, 0)).ToArray();
                            if (fullList.Length == 0)
                            {
                                return(new CommonMessageResponse("目前没有可匹配的用户,也有可能是可匹配的用户同时在浏览m4m菜单。请等待他人匹配或稍后重试。", _cm));
                            }

                            MatchInfo[] canModList = fullList.Where(i =>
                                                                    i.Preference.Have(_myInfo.Modes) == 1 &&
                                                                    _myInfo.Preference.Have(i.Modes) == 1 &&
                                                                    !i.FinishedSet.Contains(_myInfo.SetId) &&
                                                                    !_myInfo.FinishedSet.Contains(i.SetId)).ToArray();
                            if (canModList.Length == 0)
                            {
                                return(new CommonMessageResponse("目前没有与你情况相符合的用户,请等待他人匹配或稍后重试。", _cm));
                            }

                            MatchInfo[] bestList = new MatchInfo[0];
                            int         count    = 0;
                            while (bestList.Length == 0 && count < 120)
                            {
                                bestList = canModList.Where(i =>
                                                            Math.Abs(_myInfo.GetPreferanceTotalLength(i) -
                                                                     i.GetPreferanceTotalLength(_myInfo)) < count).ToArray();
                                count += 10;
                                Thread.Sleep(1);
                            }

                            MatchInfo matchInfo;

                            if (bestList.Length < 1)
                            {
                                SendMessage(new CommonMessageResponse("目前没有最佳的匹配,继续尝试不佳的匹配吗?\r\n" +
                                                                      "【1】是 【2】否", _cm));
                                CommonMessage cmContinue = SessionCondition("1", "2");
                                if (cmContinue.Message == "1")
                                {
                                    MatchInfo[] notBestList = new MatchInfo[0];
                                    int         c           = count;
                                    while (notBestList.Length == 0 && c < 10000)
                                    {
                                        notBestList = canModList.Where(i =>
                                                                       Math.Abs(_myInfo.GetPreferanceTotalLength(i) -
                                                                                i.GetPreferanceTotalLength(_myInfo)) < c).ToArray();
                                        c += 50;
                                        Thread.Sleep(1);
                                    }

                                    matchInfo = notBestList[Rnd.Next(notBestList.Length)];
                                }
                                else
                                {
                                    return(new CommonMessageResponse("你已取消操作。请等待他人匹配或稍后重试。", _cm));
                                }
                            }
                            else
                            {
                                matchInfo = bestList[Rnd.Next(bestList.Length)];
                            }

                            var    data1 = CqApi.GetStrangerInfo(matchInfo.Qq).Data;
                            var    data2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data;
                            string sub1 = "Ta", sub2 = "Ta";
                            string nick1 = "玩家", nick2 = "玩家";
                            if (data1 != null)
                            {
                                if (data1.Sex == "male")
                                {
                                    sub1 = "他";
                                }
                                else if (data1.Sex == "female")
                                {
                                    sub1 = "她";
                                }
                                nick1 = data1.Nickname;
                            }

                            if (data2 != null)
                            {
                                if (data2.Sex == "male")
                                {
                                    sub2 = "他";
                                }
                                else if (data2.Sex == "female")
                                {
                                    sub2 = "她";
                                }
                                nick2 = data2.Nickname;
                            }

                            _myInfo.Start(matchInfo.Qq);
                            matchInfo.Start(_myInfo.Qq);
                            SaveMatchList();     //apply

                            const string tip = "当你选择完成摸图时,对方会收到一条消息确认你的mod,反之亦然。" +
                                               "当双方互批完成时,M4M成功结束!\r\n" +
                                               "若有疑问,请与对方互相协商。详细情况请使用 \"/m4m\"。";

                            SendMessage(new CommonMessageResponse($"{nick2}({_myInfo.Qq}) 与你成功匹配\r\n" +
                                                                  $"{sub2}的地图:{_myInfo.SetUrl}\r\n" +
                                                                  $"{sub2}的备注:{_myInfo.Mark}\r\n" + tip,
                                                                  new Identity(matchInfo.Qq, MessageType.Private)));

                            return(new CommonMessageResponse($"你与{nick1}({matchInfo.Qq}) 成功匹配\r\n" +
                                                             $"{sub1}的地图:{matchInfo.SetUrl}\r\n" +
                                                             $"{sub1}的备注:{matchInfo.Mark}\r\n" + tip, _cm));

                        default:
                            return(new CommonMessageResponse("你开始了?走了.jpg", _cm));
                        }
                    }
                    catch (TimeoutException)
                    {
                        return(new CommonMessageResponse("由于长时间未操作,已经自动取消m4m状态。", _cm));
                    }
                }
            }
            catch (NotSupportedException)
            {
                return(new CommonMessageResponse("你已在进行m4m状态中。", messageObj, true));
            }
            finally
            {
                if (_myInfo != null)
                {
                    _myInfo.IsOperating = false;
                    SaveMatchList(); //apply
                }
            }
        }
Exemple #4
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var              routeMsg = scope.RouteMessage;
            string           id;
            string           uname;
            OldSiteApiClient client = new OldSiteApiClient();

            if (UserName == null)
            {
                BllUserRole          bllUserRole = new BllUserRole();
                List <TableUserRole> userInfo    = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId));
                if (userInfo.Count == 0)
                {
                    return(routeMsg.ToSource(DefaultReply.IdNotBound, true));
                }

                id    = userInfo[0].UserId.ToString();
                uname = userInfo[0].CurrentUname;
            }
            else
            {
                int userNum = client.GetUser(UserComponent.FromUserName(UserName), out var userObj);
                if (userNum == 0)
                {
                    return(routeMsg.ToSource(DefaultReply.IdNotFound, true));
                }
                if (userNum > 1)
                {
                    // ignored
                }

                id    = userObj.UserId.ToString();
                uname = userObj.UserName;
            }

            List <KudosuInfo> totalList = new List <KudosuInfo>();
            List <KudosuInfo> tmpList;
            int       page  = 0;
            const int count = 20;

            do
            {
                string json =
                    HttpClient.HttpGet("https://osu.ppy.sh/users/" + id + "/kudosu?offset=" + page + "&limit=" +
                                       count);
                Logger.Debug("GET JSON");

                tmpList = JsonConvert.DeserializeObject <List <KudosuInfo> >(json);
                totalList.AddRange(tmpList);
                page += count;

                if (totalList.Count != 0)
                {
                    continue;
                }

                return(routeMsg.ToSource("此人一张图都没摸过……", true));
            } while (tmpList.Count != 0);

            List <KdInfo> kdInfoList = new List <KdInfo>();
            int           pastMonth  = -1;
            KdInfo        info       = null;

            totalList.Reverse();
            foreach (var item in totalList)
            {
                if (item.Created_At.Month != pastMonth)
                {
                    if (pastMonth != -1)
                    {
                        kdInfoList.Add(info);
                    }
                    info = new KdInfo
                    {
                        Time = item.Created_At
                    };
                    pastMonth = item.Created_At.Month;
                }

                if (info != null)
                {
                    info.Count++;
                }
            }

            if (info != null)
            {
                kdInfoList.Add(info);
            }

            var cqImg = new FileImage(Draw(kdInfoList, uname)).ToString();

            return(routeMsg.ToSource(cqImg));
        }