예제 #1
0
파일: SetId.cs 프로젝트: fengyeju/Daylily
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var    routeMsg = scope.RouteMessage;
            string userName = Decode(UserName);

            if (string.IsNullOrEmpty(userName))
            {
                return(routeMsg.ToSource(DefaultReply.ParamMissing));
            }

            BllUserRole      bllUserRole = new BllUserRole();
            OldSiteApiClient client      = new OldSiteApiClient();
            int userNum = client.GetUser(UserComponent.FromUserName(UserName), out var userObj);

            if (userNum == 0)
            {
                return(routeMsg.ToSource(DefaultReply.IdNotFound, true));
            }
            if (userNum > 1)
            {
                // ignored
            }

            var role = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId));

            if (role.Count != 0)
            {
                if (role[0].CurrentUname == userObj.UserName)
                {
                    return(routeMsg.ToSource("我早就认识你啦.", true));
                }
                string msg = role[0].CurrentUname + ",我早就认识你啦. 有什么问题请找Mother Ship(扔锅)";
                return(routeMsg.ToSource(msg, true));
            }

            var newRole = new TableUserRole
            {
                UserId        = userObj.UserId,
                Role          = "creep",
                QQ            = long.Parse(routeMsg.UserId),
                LegacyUname   = "[]",
                CurrentUname  = userObj.UserName,
                IsBanned      = false,
                RepeatCount   = 0,
                SpeakingCount = 0,
                Mode          = 0,
            };
            var exist = bllUserRole.GetUserRoleByUid(userObj.UserId);

            if (exist != null && exist.Count > 0)
            {
                return(routeMsg.ToSource("这个账号已经被QQ: " + exist.First().QQ + "绑定啦,请联系妈船或对方QQ哦."));
            }
            int c = bllUserRole.InsertUserRole(newRole);

            return(c < 1
                ? routeMsg.ToSource("由于各种强大的原因,绑定失败..")
                : routeMsg.ToSource("明白了," + userObj.UserName + ",多好的名字呢."));
        }
예제 #2
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;
            }

            var eloInfo = EloApiClient.GetEloByUid(long.Parse(id));

            switch (eloInfo.Result.ToLower())
            {
            case "fail" when eloInfo.Message.ToLower() == "unranked":
                return(routeMsg.ToSource(uname + "大概没有参加什么mapping赛事..所以没有数据..",
                                         true));

            case "fail":
                return(routeMsg.ToSource("未知错误..查询不到..", true));

            default:
                return(routeMsg.ToSource(
                           $"{eloInfo.User.Name},有elo点{Math.Round(eloInfo.User.Elo, 2)},当前#{eloInfo.User.Ranking}.", true));
            }
        }
예제 #3
0
파일: PpPlus.cs 프로젝트: fengyeju/Daylily
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var              routeMsg = scope.RouteMessage;
            string           userName, userId;
            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));
                }
                userId   = userInfo[0].UserId.ToString();
                userName = 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
                }

                userId   = userObj.UserId.ToString();
                userName = userObj.UserName;
            }

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

            if (jsonString == null)
            {
                return(routeMsg
                       .ToSource("PP+获取超时,请重试…", true)
                       .ForceToSend());
            }

            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(routeMsg
                   .ToSource(cqImg)
                   .ForceToSend());
        }
예제 #4
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            if (List)
            {
                UserId[] subscribedUsers = GetSubscribed(routeMsg.CoolQIdentity)
                                           .Select(k => new UserId(k))
                                           .OrderBy(k => k.IdOrName)
                                           .ToArray();
                int    count   = subscribedUsers.Length;
                string subject = routeMsg.MessageType == MessageType.Private ? "你" : "本群";
                if (count == 0)
                {
                    return(routeMsg.ToSource($"{subject}没有订阅任何mapper。"));
                }
                var names = _client.GetUserNameByUid(subscribedUsers);
                return(routeMsg.ToSource($"以下是{subject}的订阅名单,共计{count}个:\r\n{string.Join("\r\n", names)}"));
            }

            if (SubscribeMapper != null)
            {
                if (routeMsg.MessageType == MessageType.Group && routeMsg.CurrentAuthority == Authority.Public)
                {
                    return(routeMsg.ToSource(DefaultReply.AdminOnly + "个人推送请私聊."));
                }

                var subscribedUsers = GetSubscribed(routeMsg.CoolQIdentity)
                                      .Select(k => new UserId(k))
                                      .OrderBy(k => k.IdOrName)
                                      .ToArray();
                int subedCount = subscribedUsers.Length;
                if (routeMsg.MessageType == MessageType.Private && subedCount >= PrivateMax)
                {
                    return(routeMsg.ToSource(
                               string.Format("你已经订阅了{0}个mapper啦,人家已经装不下的说:{1}", subedCount,
                                             string.Join(", ", _client.GetUserNameByUid(subscribedUsers)))));
                }

                if (routeMsg.MessageType != MessageType.Private && subedCount >= GroupMax)
                {
                    return(routeMsg.ToSource(
                               string.Format("这个群已经订阅了{0}个mapper啦,人家已经装不下的说:{1}", subedCount,
                                             string.Join(", ", _client.GetUserNameByUid(subscribedUsers)))));
                }

                int count = _client.GetUser(UserComponent.FromUserName(SubscribeMapper), out var userObj);
                if (count == 0)
                {
                    return(routeMsg.ToSource($"找不到指定mapper: \"{SubscribeMapper}\".."));
                }

                if (count > 1)
                {
                    return(routeMsg.ToSource($"找到{count}个mapper..人家不懂是要找哪一个"));
                }

                long   mapperId   = userObj.UserId;
                string mapperName = userObj.UserName;

                if (!_userDic.ContainsKey(mapperId))
                {
                    _userDic.TryAdd(mapperId, new List <CoolQIdentity>());
                }
                if (_userDic[mapperId].Contains(routeMsg.CoolQIdentity))
                {
                    string subject = routeMsg.MessageType == MessageType.Private ? "你" : "本群";
                    return(routeMsg.ToSource($"{subject}已经订阅过{mapperName}啦.."));
                }

                _userDic[mapperId].Add(routeMsg.CoolQIdentity);
                SaveSettings(_userDic, "userDictionary");
                string sub = routeMsg.MessageType == MessageType.Private ? "私聊提醒你" : "在本群提醒";
                return(routeMsg
                       .ToSource($"{mapperName}订阅成功啦!今后他qualified、rank或love或上传图后会主动{sub}。")
                       .ForceToSend());
            }

            if (UnsubscribeMapper != null)
            {
                if (routeMsg.MessageType == MessageType.Group && routeMsg.CurrentAuthority == Authority.Public)
                {
                    return(routeMsg.ToSource(DefaultReply.AdminOnly + "个人推送请私聊."));
                }

                int count = _client.GetUser(UserComponent.FromUserName(UnsubscribeMapper), out var userObj);
                if (count == 0)
                {
                    return(routeMsg.ToSource("找不到指定mapper.."));
                }

                if (count > 1)
                {
                    return(routeMsg.ToSource($"找到{count}个mapper.."));
                }

                long   mapperId   = userObj.UserId;
                string mapperName = userObj.UserName;
                if (!_userDic.ContainsKey(mapperId) || !_userDic[mapperId].Contains(routeMsg.CoolQIdentity))
                {
                    string subject = routeMsg.MessageType == MessageType.Private ? "你" : "本群";
                    return(routeMsg.ToSource($"目前这个mapper没有被{subject}订阅.."));
                }

                _userDic[mapperId].Remove(routeMsg.CoolQIdentity);
                if (_userDic[mapperId].Count == 0)
                {
                    _userDic.Remove(mapperId, out _);
                }

                SaveSettings(_userDic, "userDictionary");
                string sub = routeMsg.MessageType == MessageType.Private ? "为你" : "在本群";
                return(routeMsg.ToSource($"订阅取消成功,今后不再{sub}推送{mapperName}的有关动态。"));
            }

            return(routeMsg.ToSource(DefaultReply.ParamMissing));
        }
예제 #5
0
파일: Kudosu.cs 프로젝트: fengyeju/Daylily
        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));
        }