Example #1
0
File: CQ.cs Project: zzzzzga/CQP
 /// <summary>
 /// 获取酷Q插件App的目;如果是UDP方式,返回的则为酷Q主目录。
 /// </summary>
 /// <returns></returns>
 public static string GetCQAppFolder()
 {
     if (ProxyType == CQProxyType.UDP)
     {
         return(AppDomain.CurrentDomain.BaseDirectory);
     }
     else
     {
         return(CQAPI.GetCQAppFolder(CQAPI.GetAuthCode()));
     }
 }
Example #2
0
File: CQ.cs Project: zzzzzga/CQP
        /// <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());
        }
Example #3
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置匿名群员禁言。
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="anomymous">被操作的匿名成员名称。</param>
        /// <param name="time">禁言时长(以秒为单位)</param>
        public static void SetGroupAnonymousMemberGag(long groupNumber, string anomymous, long time)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][禁言] 群:{0} 匿名:{1} 时长:{2}", groupNumber, anomymous, time));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupAnonymousMemberGag|{0}|{1}|{2}", groupNumber, anomymous.Replace("|", "$内容分割$"), time);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupAnonymousBan(CQAPI.GetAuthCode(), groupNumber, anomymous, time);
            }
        }
Example #4
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置讨论组退出。
        /// </summary>
        /// <param name="discussNumber">讨论组号码。</param>
        public static void SetDiscussExit(long discussNumber)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][退组] 组:{0}", discussNumber));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetDiscussExit|{0}", discussNumber);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetDiscussLeave(CQAPI.GetAuthCode(), discussNumber);
            }
        }
Example #5
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群匿名设置。
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="allow">开启或关闭匿名功能。</param>
        public static void SetGroupAllowAnonymous(long groupNumber, bool allow)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][禁言] 群:{0} QQ:{1}", groupNumber, allow ? "开启匿名" : "关闭匿名"));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupAllowAnonymous|{0}|{1}", groupNumber, allow);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupAnonymous(CQAPI.GetAuthCode(), groupNumber, allow ? 1 : 0);
            }
        }
Example #6
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置全群禁言。
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="gag">设置或关闭全群禁言。</param>
        public static void SetGroupAllGag(long groupNumber, bool gag)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][禁言] 群:{0} QQ:{1}", groupNumber, gag ? "全员禁言" : "取消全员禁言"));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupAllGag|{0}|{1}", groupNumber, gag);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupWholeBan(CQAPI.GetAuthCode(), groupNumber, gag ? 1 : 0);
            }
        }
Example #7
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群管理员。
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="qqNumber">被操作的QQ号码。</param>
        /// <param name="admin">是否设置为管理员。</param>
        public static void SetGroupAdministrator(long groupNumber, long qqNumber, bool admin)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][管理] 群:{0} QQ:{1}", groupNumber, qqNumber, admin ? "提升为管理员" : "降为成员"));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupAdministrator|{0}|{1}|{2}", groupNumber, qqNumber, admin);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupAdmin(CQAPI.GetAuthCode(), groupNumber, qqNumber, admin ? 1 : 0);
            }
        }
Example #8
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群添加请求。
        /// </summary>
        /// <param name="react">请求反馈标识。</param>
        /// <param name="requestType">请求类型。</param>
        /// <param name="reactType">反馈类型。</param>
        /// <param name="reason">加群原因。</param>
        public static void SetGroupAddRequest(string react, CQRequestType requestType, CQReactType reactType, string reason = "")
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][请群] {0} {1} {2}", react, requestType, reactType));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupAddRequest|{0}|{1}|{2}|{3}", react, (int)requestType, (int)reactType, reason.Replace("|", "$内容分割$"));
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupAddRequestV2(CQAPI.GetAuthCode(), react, (int)requestType, (int)reactType, reason);
            }
        }
Example #9
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群员移除。
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="qqNumber">被操作的QQ号码。</param>
        /// <param name="refuse">是否拒绝再次加群。</param>
        public static void SetGroupMemberRemove(long groupNumber, long qqNumber, bool refuse = false)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][踢人] 群:{0} QQ:{1}", groupNumber, qqNumber));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupMemberRemove|{0}|{1}|{2}", groupNumber, qqNumber, refuse);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupKick(CQAPI.GetAuthCode(), groupNumber, qqNumber, refuse ? 1 : 0);
            }
        }
Example #10
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群成员专属头衔
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="qqNumber">被操作的QQ号码。</param>
        /// <param name="newName">头衔名称。</param>
        /// <param name="time">过期时间(以秒为单位)。</param>
        public static void SetGroupHonorName(long groupNumber, long qqNumber, string newName, int time)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][头衔] 群:{0} QQ:{1} {2}", groupNumber, qqNumber, newName));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupHonor|{0}|{1}|{2}|{3}", groupNumber, qqNumber, newName.Replace("|", "$内容分割$"), time);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupSpecialTitle(CQAPI.GetAuthCode(), groupNumber, qqNumber, newName, time);
            }
        }
Example #11
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群成员名片
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="qqNumber">被操作的QQ号码。</param>
        /// <param name="newName">新的群名称。</param>
        public static void SetGroupNickName(long groupNumber, long qqNumber, string newName)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][名片] 群:{0} QQ:{1} {2}", groupNumber, qqNumber, newName));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupNickName|{0}|{1}|{2}", groupNumber, qqNumber, newName.Replace("|", "$内容分割$"));
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupCard(CQAPI.GetAuthCode(), groupNumber, qqNumber, newName);
            }
        }
Example #12
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群员禁言。
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="qqNumber">被操作的QQ号码。</param>
        /// <param name="time">禁言时长(以秒为单位)</param>
        public static void SetGroupMemberGag(long groupNumber, long qqNumber, long time)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][禁言] 群:{0} QQ:{1} Time:{2}", groupNumber, qqNumber, time));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupMemberGag|{0}|{1}|{2}", groupNumber, qqNumber, time);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupBan(CQAPI.GetAuthCode(), groupNumber, qqNumber, time);
            }
        }
Example #13
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 发送赞(本地C++模式调用一次只能发送一个赞)。
        /// </summary>
        /// <param name="qqNumber">被操作的QQ。</param>
        /// <param name="count">发赞次数。</param>
        public static void SendPraise(long qqNumber, int count = 1)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][发赞] QQ:{0} {1}次", qqNumber, count));

            if (ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SendGood|{0}|{1}", qqNumber, count);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SendLike(CQAPI.GetAuthCode(), qqNumber);
            }
        }
Example #14
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 发送讨论组消息。
        /// </summary>
        /// <param name="discussNumber">讨论组号码。</param>
        /// <param name="message">论组消息内容。</param>
        public static void SendDiscussMessage(long discussNumber, string message)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][讨论] QQ:{0} {1}", discussNumber, message));

            if (ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SendDiscussMessage|{0}|{1}", discussNumber, message.Replace("|", "$内容分割$"));
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SendDiscussMessage(CQAPI.GetAuthCode(), discussNumber, message);
            }
        }
Example #15
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 置群退出。
        /// </summary>
        /// <param name="groupNumber">群号码。</param>
        /// <param name="dissolution">是否解散。</param>
        public static void SetGroupExit(long groupNumber, bool dissolution = false)
        {
            CQLogger.GetInstance().AddLog(String.Format("[↑][退群] 群:{0} {1}", groupNumber, dissolution ? "解散" : ""));

            if (CQ.ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("SetGroupExit|{0}|{1}", groupNumber, dissolution);
                CQUDPProxy.GetInstance().SendMessage(content);
            }
            else
            {
                CQAPI.SetGroupLeave(CQAPI.GetAuthCode(), groupNumber, dissolution ? 1 : 0);
            }
        }
Example #16
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 取取CsrfToken。
        /// </summary>
        /// <returns>登录的CsrfToken。</returns>
        public static int GetCsrfToken()
        {
            CQLogger.GetInstance().AddLog(String.Format("[↓][帐号] 取CsrfToken"));

            if (ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("GetCsrfTokenRequest");
                string result  = CQUDPProxy.GetInstance().GetStringMessage(content);
                return(Convert.ToInt32(result));
            }
            else
            {
                return(CQAPI.GetCsrfToken(CQAPI.GetAuthCode()));
            }
        }
Example #17
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 取Cookies。
        /// </summary>
        /// <returns>登录的Cookies。</returns>
        public static string GetCookies()
        {
            CQLogger.GetInstance().AddLog(String.Format("[↓][帐号] 取Cookies"));


            if (ProxyType == CQProxyType.UDP)
            {
                string content = String.Format("GetCookiesRequest");
                string result  = CQUDPProxy.GetInstance().GetStringMessage(content);
                return(result);
            }
            else
            {
                return(CQAPI.GetCookies(CQAPI.GetAuthCode()));
            }
        }
Example #18
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 取登录昵称。
        /// </summary>
        /// <returns>登录的QQ号码昵称。</returns>
        public static string GetLoginName()
        {
            CQLogger.GetInstance().AddLog(String.Format("[↓][帐号] 取登录昵称"));

            try
            {
                if (ProxyType == CQProxyType.UDP)
                {
                    string content = String.Format("GetLoginNameRequest");
                    string result  = CQUDPProxy.GetInstance().GetStringMessage(content);
                    return(result);
                }
                else
                {
                    return(CQAPI.GetLoginNick(CQAPI.GetAuthCode()));
                }
            }
            catch
            {
            }

            return("");
        }
Example #19
0
File: CQ.cs Project: zzzzzga/CQP
        /// <summary>
        /// 取登录QQ。
        /// </summary>
        /// <returns>登录的QQ号码</returns>
        public static long GetLoginQQ()
        {
            CQLogger.GetInstance().AddLog(String.Format("[↓][帐号] 取登录QQ"));

            try
            {
                if (ProxyType == CQProxyType.UDP)
                {
                    string content = String.Format("GetLoginQQRequest");
                    string result  = CQUDPProxy.GetInstance().GetStringMessage(content);
                    return(Convert.ToInt64(result));
                }
                else
                {
                    return(CQAPI.GetLoginQQ(CQAPI.GetAuthCode()));
                }
            }
            catch
            {
            }

            return(0);
        }