private static async Task <List <GroupMemberInfo> > GetMemberList(SoraApi session, long groupId) { return((await session.GetGroupMemberList(groupId)).groupMemberList .Select(info => new GroupMemberInfo { GroupId = groupId, QQId = info.UserId, PermitType = info.Role switch { MemberRoleType.Owner => PermitType.Holder, MemberRoleType.Admin => PermitType.Manage, _ => PermitType.None } }).ToList());
public static GreenOnionsMessages ToOnionsMessages(this MessageBody miraiMessage, long senderId, string senderName, long?senderGroup, SoraApi api) { GreenOnionsMessages greenOnionsMessages = new GreenOnionsMessages(); for (int i = 0; i < miraiMessage.Count; i++) { if (miraiMessage[i].Data is AtSegment atMsg) { //获取@群名片 if (long.TryParse(atMsg.Target, out long atId)) { var apiResult = api.GetGroupMemberList(senderGroup.Value).GetAwaiter().GetResult(); List <GroupMemberInfo> groupMemberInfos = apiResult.groupMemberList; GroupMemberInfo targetQQ = groupMemberInfos.Where(m => m.UserId == atId).FirstOrDefault(); string nickName = targetQQ?.Nick; greenOnionsMessages.Add(new GreenOnionsAtMessage(atId, nickName)); } else { greenOnionsMessages.Add(new GreenOnionsAtMessage(atId, atMsg.Name)); } } else if (miraiMessage[i].Data is TextSegment textMsg) { greenOnionsMessages.Add(textMsg.Content); } else if (miraiMessage[i].Data is ImageSegment imageMsg) { greenOnionsMessages.Add(new GreenOnionsImageMessage(imageMsg.Url, imageMsg.ImgFile)); } } greenOnionsMessages.SenderId = senderId; greenOnionsMessages.SenderName = senderName; return(greenOnionsMessages); }
public static async Task <bool> CheckGroupHasUser(this SoraApi api, long group, long user) => Convert.ToBoolean((await api.GetGroupMemberList(group)) .groupMemberList?.Where(x => x.UserId == user).Any());
/// <summary> /// 获取群成员列表 /// </summary> /// <returns> /// <para><see cref="ApiStatusType"/> API执行状态</para> /// <para><see cref="List{GroupMemberInfo}"/> 群成员列表</para> /// </returns> public async ValueTask <(ApiStatus apiStatus, List <GroupMemberInfo> groupMemberList)> GetGroupMemberList( bool useCache = true) { return(await SoraApi.GetGroupMemberList(Id, useCache)); }