public string GetGroupMemberInfo(long groupCode, long account) { var info = _onebot.GetGroupMembersAsync(groupCode, true).GetAwaiter().GetResult()?.ToList() .FirstOrDefault(v => v.Userid == account); if (info == null) { return(string.Empty); } using (var ms = new MemoryStream()) using (var packet = new BytesPacket(ms)) return(packet.Also(p => WriteMemberInfo(p, info)).ToBase64()); }
public string GetGroupMemberList(long groupCode) { var list = _onebot.GetGroupMembersAsync(groupCode, true).GetAwaiter().GetResult()?.ToList(); if (list == null) { return(string.Empty); } using (var ms = new MemoryStream()) using (var packet = new BytesPacket(ms)) { packet.WriteInt32(list.Count); list.ForEach(info => WriteMemberInfo(packet, info)); return(packet.ToBase64()); } }
public string GetGroupList() { var list = _onebot.GetGroupListAsync().GetAwaiter().GetResult()?.ToList(); if (list == null) { return(string.Empty); } using (var ms = new MemoryStream()) using (var packet = new BytesPacket(ms)) { packet.WriteInt32(list.Count); list.ForEach(info => packet.WriteShortPacket(p => p.WriteInt64(info.GroupId).WriteString(info.GroupName))); return(packet.ToBase64()); } }
private static void WriteMemberInfo(BytesPacket packet, GroupMemberInfo info) => packet.WriteShortPacket(p => p .WriteInt64(info.GroupId) .WriteInt64(info.Userid) .WriteString(info.Nickname) .WriteString(info.CardName) .WriteInt32(0) .WriteInt32(info.Age) .WriteString(info.Area) .WriteInt32((int)info.JoinTime) .WriteInt32((int)info.LastSentTime) .WriteString(info.Title) .WriteInt32(info.Role == "owner" ? 3 : info.Role == "admin" ? 2 : 1) .WriteBool(false) .WriteString(info.Title) .WriteInt32((int)info.TitleExpireTime) .WriteBool(true) );
public string GetGroupInfo(long groupCode) { var info = _onebot.GetGroupInfoAsync(groupCode).GetAwaiter().GetResult(); if (info == default) { return(string.Empty); } using (var ms = new MemoryStream()) using (var packet = new BytesPacket(ms)) { return(packet .WriteInt64(info.GroupId) .WriteString(info.GroupName) .WriteInt32(info.MemberCount) .WriteInt32(info.MaxMemberCount) .ToBase64()); } }
/// <summary> /// 加载CQ的插件 /// </summary> /// <param name="adapter"></param> public void LoadCQPlugins(IOnebotAdapter adapter) { CQAppManager.Api = new CQApiAdapter(adapter); CQAppManager.Manager.LoadApps("apps", "data"); CQAppManager.Manager.EnableApps(); // --- 转发事件 --- adapter.OnGroupMessage += token => { CQAppManager.Manager.InvokeGroupMsgEvent(1, token["message_id"].ToObject <int>(), token["group_id"].ToObject <long>(), token.SelectToken("sender.user_id").ToObject <long>(), "", OnebotTools.ParseMessageToString(token["message"]), 0); }; adapter.OnPrivateMessage += token => { var subType = token["sub_type"]?.ToString() == "friend" ? 11 : 2; CQAppManager.Manager.InvokePrivateMsgEvent(subType, token["message_id"].ToObject <int>(), token["user_id"].ToObject <long>(), OnebotTools.ParseMessageToString(token["message"]), 0); }; adapter.OnGroupUpload += token => { var file = token["file"]?.ToObject <GroupFileInfo>(); if (file == null) { return; } using (var ms = new MemoryStream()) using (var packet = new BytesPacket(ms)) { var encode = packet .WriteString(file.Id) .WriteString(file.Name) .WriteInt64(file.Size) .WriteInt32(file.Busid) .ToBase64(); CQAppManager.Manager.InvokeGroupUploadEvent(token["group_id"].ToObject <long>(), token["user_id"].ToObject <long>(), token["time"].ToObject <long>(), encode); } }; }