Exemple #1
0
        /// <summary>
        /// 取群成员信息。
        /// <para>
        /// 多线程同步等待,采用阻塞线程的方式等待客户端返回群成员信息,响应时间较慢,建议使用缓存。
        /// </para>
        /// <para>
        /// 缓存时长1天,超过1天的成员,在下次访问时会通过酷Q重新获取最新信息。
        /// </para>
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="qqNumber">被操作的QQ号码。</param>
        /// <param name="cache">是否使用缓存(使用缓存后,当后第一次访问会通过客户端读取,之后每次都通过缓存获得)。</param>
        public static CQGroupMemberInfo GetGroupMemberInfo(long groupNumber, long qqNumber, bool cache = true)
        {
            lock (_syncRoot)
            {
                Dictionary <long, CQGroupMemberInfo> dicMemebers = new Dictionary <long, CQGroupMemberInfo>();

                if (_dicCache.ContainsKey(groupNumber))
                {
                    dicMemebers = _dicCache[groupNumber];
                }
                else
                {
                    _dicCache.Add(groupNumber, dicMemebers);
                }

                CQGroupMemberInfo member = new CQGroupMemberInfo();

                if (dicMemebers.ContainsKey(qqNumber))
                {
                    member = dicMemebers[qqNumber];
                }
                else
                {
                    dicMemebers.Add(qqNumber, member);
                }

                if (!cache || member.RefreshDate.Date.AddDays(1) < DateTime.Now)
                {
                    CQLogger.GetInstance().AddLog(String.Format("[↓][成员] 群:{0} QQ:{1}", groupNumber, qqNumber));
                    string content = String.Empty;

                    if (CQ.ProxyType == CQProxyType.UDP)
                    {
                        content = String.Format("GroupMemberRequest|{0}|{1}", groupNumber, qqNumber);
                        member  = CQUDPProxy.GetInstance().GetGroupMemberInfo(content);
                    }
                    if (CQ.ProxyType == CQProxyType.NativeClr)
                    {
                        content = CQAPI.GetGroupMemberInfo(CQAPI.GetAuthCode(), groupNumber, qqNumber, cache ? 1 : 0);
                        member  = CQMessageAnalysis.AnalyzeGroupMember(content);
                    }

                    if (cache)
                    {
                        dicMemebers[qqNumber] = member;
                    }
                }

                return(member);
            }


            return(new CQGroupMemberInfo());
        }
Exemple #2
0
        /// <summary>
        /// 获取群成员列表,阻塞线程,等待客户端响应(有风险,待测试)。
        /// </summary>
        internal CQGroupMemberInfo GetGroupMemberInfo(string message)
        {
            byte[] data = Encoding.Default.GetBytes(message);
            this.mySocket.SendTo(data, data.Length, SocketFlags.None, RemotePoint);

            myResetEvent.WaitOne(2000);

            try
            {
                CQGroupMemberInfo info = CQMessageAnalysis.AnalyzeGroupMember(this._strMessage);
                this._strMessage = String.Empty;
                return(info);
            }
            catch
            {
                return(new CQGroupMemberInfo());
            }
        }