Example #1
0
        /// <summary>
        /// 获取群信息
        /// </summary>
        /// <param name="groupId">群号码</param>
        /// <param name="notCache">不使用缓存, 通常为 <code>false</code>, 仅在必要时使用</param>
        /// <returns>如果成功返回 <see cref="GroupInfo"/>, 若失败返回 null</returns>
        public GroupInfo GetGroupInfo(long groupId, bool notCache = false)
        {
            string result = CQP.CQ_getGroupInfo(_authCode, groupId, false).ToString(_defaultEncoding);

            if (string.IsNullOrEmpty(result))
            {
                return(null);
            }
            #region --其他_转换_文本到群信息--
            using (BinaryReader reader = new BinaryReader(new MemoryStream(Convert.FromBase64String(result))))
            {
                if (reader.Length() < 18)
                {
                    return(null);
                }

                GroupInfo info = new GroupInfo();
                info.Id            = reader.ReadInt64_Ex();
                info.Name          = reader.ReadString_Ex(_defaultEncoding);
                info.CurrentNumber = reader.ReadInt32_Ex();
                info.MaximumNumber = reader.ReadInt32_Ex();
                return(info);
            }
            #endregion
        }
Example #2
0
        /// <summary>
        /// 获取群信息
        /// </summary>
        /// <param name="groupId">目标群号</param>
        /// <param name="notCache">不使用缓存, 通常为 <code>false</code>, 仅在必要时使用</param>
        /// <exception cref="ArgumentOutOfRangeException">参数: groupId 超出范围</exception>
        /// <exception cref="InvalidDataException">数据流格式错误或为 null</exception>
        /// <exception cref="EndOfStreamException">无法读取数据, 因为已读取到数据流末尾</exception>
        /// <returns>获取成功返回 <see cref="GroupInfo"/> 对象, 失败返回 <see langword="null"/></returns>
        public GroupInfo GetGroupInfo(long groupId, bool notCache = false)
        {
            if (groupId < Group.MinValue)
            {
                throw new ArgumentOutOfRangeException("groupId");
            }

            string data = CQP.CQ_getGroupInfo(this.AppInfo.AuthCode, groupId, notCache).ToString(CQApi.DefaultEncoding);

            if (string.IsNullOrEmpty(data))
            {
#if DEBUG
                throw new InvalidDataException("获取的数据流格式无效");
#else
                return(null);
#endif
            }

            try
            {
                return(new GroupInfo(this, data, false));
            }
            catch
            {
#if DEBUG
                throw;
#else
                return(null);
#endif
            }
        }