public static void ReceiveVoice(string fileName, string postfixName) { if (ProxyType == CQProxyType.UDP) { CQLogger.GetInstance().AddLog(String.Format("[↓][语音] QQ:{0} {1}", fileName, postfixName)); string content = String.Format("ReceiveVoice|{0}|{1}", fileName, postfixName); CQUDPProxy.GetInstance().SendMessage(content); } }
/// <summary> /// 创建一个实例。 /// </summary> /// <returns>一个 <see cref="CQUDPProxy"/> 实例。</returns> public static CQUDPProxy GetInstance() { if (instance == null) { instance = new CQUDPProxy(); } return(instance); }
/// <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()); }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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())); } }
/// <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())); } }
public static List <CQGroupMemberInfo> GetGroupMemberList(long groupNumber) { List <CQGroupMemberInfo> list = new List <CQGroupMemberInfo>(); if (ProxyType == CQProxyType.UDP) { try { CQLogger.GetInstance().AddLog(String.Format("[↓][帐号] 群:{0} 取群成员列表", groupNumber)); string content = String.Format("GetGroupMemberListRequest|{0}", groupNumber); string result = CQUDPProxy.GetInstance().GetStringMessage(content); string[] msQQIds = result.GetMidStrings("\"uin\":", "}"); string[] msQQNames = result.GetMidStrings("\"nick\":\"", "\",\"uin\":"); string[] msIsAdmins = result.GetMidStrings("\"ismanager\":", ","); string[] msIsCreators = result.GetMidStrings("\"iscreator\":", ","); if (msQQIds.Length == msQQNames.Length && msQQNames.Length == msIsAdmins.Length && msIsAdmins.Length == msIsCreators.Length) { for (int i = 0; i < msQQIds.Length; i++) { CQGroupMemberInfo info = new CQGroupMemberInfo(); info.GroupNumber = groupNumber; info.QQNumber = Convert.ToInt64(msQQIds[i]); info.QQName = msQQNames[i]; int isAdmin = Convert.ToInt32(msIsAdmins[i]); int isCreator = Convert.ToInt32(msIsCreators[i]); info.Authority = isCreator == 1 ? "群主" : isAdmin == 1 ? "管理" : "成员"; list.Add(info); } } } catch { } } return(list); }
/// <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(""); }
/// <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); }
public static List <CQGroupInfo> GetGroupList() { List <CQGroupInfo> list = new List <CQGroupInfo>(); if (ProxyType == CQProxyType.UDP) { try { CQLogger.GetInstance().AddLog(String.Format("[↓][帐号] 取群列表")); string content = String.Format("GetGroupListRequest"); string result = CQUDPProxy.GetInstance().GetStringMessage(content); string[] msGroupIds = result.GetMidStrings("\"groupid\":", ",\"groupname\":\""); string[] msGroupNames = result.GetMidStrings("groupname\":\"", "\""); if (msGroupIds.Length == msGroupNames.Length) { for (int i = 0; i < msGroupIds.Length; i++) { CQGroupInfo info = new CQGroupInfo(); info.GroupNumber = Convert.ToInt64(msGroupIds[i]); info.GroupName = msGroupNames[i]; list.Add(info); } } } catch { } } return(list); }