feat: support for at message segment specifying name

This commit is contained in:
idranme 2024-08-09 18:02:52 +08:00
parent b02cd3af00
commit be1b9c21c1
No known key found for this signature in database
GPG Key ID: 926F7B5B668E495F
6 changed files with 21 additions and 18 deletions

View File

@ -13,13 +13,10 @@ import {
CHANNEL_UPDATE,
} from '../common/channels'
import { ob11WebsocketServer } from '../onebot11/server/ws/WebsocketServer'
import { DATA_DIR, qqPkgInfo } from '../common/utils'
import { DATA_DIR } from '../common/utils'
import {
friendRequests,
getFriend,
getGroup,
getGroupMember,
groups,
llonebotError,
selfInfo,
uidMaps,
@ -27,9 +24,7 @@ import {
import { hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook, startHook } from '../ntqqapi/hook'
import { OB11Constructor } from '../onebot11/constructor'
import {
ChatType,
FriendRequestNotify,
GroupMemberRole,
GroupNotifies,
GroupNotifyTypes,
RawMessage,

View File

@ -358,8 +358,9 @@ export class NTQQMsgApi {
})
})
}
static async getMsgsBySeqAndCount(peer: Peer, seq: string, count: number, desc: boolean, z: boolean) {
const session = getSession()
return await session?.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z);
return await session?.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z)!
}
}

View File

@ -221,7 +221,7 @@ export class NTQQUserApi {
static async getUidByUinV1(Uin: string) {
const session = getSession()
// 通用转换开始尝试
let uid = (await session?.getUixConvertService().getUid([Uin])!).uidInfo.get(Uin);
let uid = (await session?.getUixConvertService().getUid([Uin]))?.uidInfo.get(Uin)
// Uid 好友转
if (!uid) {
friends.forEach((t) => {
@ -251,11 +251,11 @@ export class NTQQUserApi {
static async getUidByUinV2(Uin: string) {
const session = getSession()
let uid = (await session?.getProfileService().getUidByUin('FriendsServiceImpl', [Uin])!).get(Uin)
let uid = (await session?.getProfileService().getUidByUin('FriendsServiceImpl', [Uin]))?.get(Uin)
if (uid) return uid
uid = (await session?.getGroupService().getUidByUins([Uin])!).uids.get(Uin)
uid = (await session?.getGroupService().getUidByUins([Uin]))?.uids.get(Uin)
if (uid) return uid
uid = (await session?.getUixConvertService().getUid([Uin])!).uidInfo.get(Uin)
uid = (await session?.getUixConvertService().getUid([Uin]))?.uidInfo.get(Uin)
if (uid) return uid
console.log((await NTQQFriendApi.getBuddyIdMapCache(true)))
uid = (await NTQQFriendApi.getBuddyIdMapCache(true)).getValue(Uin)//从Buddy缓存获取Uid
@ -263,7 +263,7 @@ export class NTQQUserApi {
uid = (await NTQQFriendApi.getBuddyIdMap(true)).getValue(Uin)
if (uid) return uid
let unveifyUid = (await NTQQUserApi.getUserDetailInfoByUinV2(Uin)).detail.uid//从QQ Native 特殊转换
if (unveifyUid.indexOf("*") == -1) uid = unveifyUid
if (unveifyUid.indexOf('*') == -1) uid = unveifyUid
//if (uid) return uid
return uid
}

View File

@ -44,12 +44,12 @@ export class SendMsgElementConstructor {
}
}
static at(atUid: string, atNtUid: string, atType: AtType, atName: string): SendTextElement {
static at(atUid: string, atNtUid: string, atType: AtType, display: string): SendTextElement {
return {
elementType: ElementType.TEXT,
elementId: '',
textElement: {
content: `@${atName}`,
content: display,
atType,
atUid,
atTinyId: '',

View File

@ -109,15 +109,22 @@ export async function createSendElements(
}
}
if (isAdmin && remainAtAllCount > 0) {
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员'))
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '@全体成员'))
}
}
else if (peer.chatType === ChatType.group) {
// const atMember = group?.members.find(m => m.uin == atQQ)
const atMember = await getGroupMember(peer.peerUid, atQQ)
if (atMember) {
const display = `@${atMember.cardName || atMember.nick}`
sendElements.push(
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick),
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, display),
)
} else {
const atNmae = sendMsg.data?.name
const uid = await NTQQUserApi.getUidByUin(atQQ) || ''
const display = atNmae ? `@${atNmae}` : ''
sendElements.push(
SendMsgElementConstructor.at(atQQ, uid, AtType.atUser, display),
)
}
}

View File

@ -554,7 +554,7 @@ export class OB11Constructor {
if (msgList[0].senderUin === '0') {
msgList[0].senderUin = postMsg?.senderUin ?? selfInfo.uin
}
return new OB11GroupEssenceEvent(parseInt(msg.peerUid), postMsg?.msgShortId!, parseInt(msgList[0].senderUin))
return new OB11GroupEssenceEvent(parseInt(msg.peerUid), postMsg?.msgShortId!, parseInt(msgList[0].senderUin!))
// 获取MsgSeq+Peer可获取具体消息
}
if (grayTipElement.jsonGrayTipElement.busiId == 2407) {