mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: the name attribute of the at message segment
This commit is contained in:
parent
d0967785de
commit
71aedca4c6
@ -109,33 +109,42 @@ export class OB11Constructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let element of msg.elements) {
|
for (let element of msg.elements) {
|
||||||
let message_data: OB11MessageData | any = {
|
let message_data: OB11MessageData = {
|
||||||
data: {},
|
data: {} as any,
|
||||||
type: 'unknown',
|
type: 'unknown' as any,
|
||||||
}
|
}
|
||||||
if (element.textElement && element.textElement?.atType !== AtType.notAt) {
|
if (element.textElement && element.textElement?.atType !== AtType.notAt) {
|
||||||
message_data['type'] = OB11MessageDataType.at
|
let qq: string
|
||||||
|
let name: string | undefined
|
||||||
if (element.textElement.atType == AtType.atAll) {
|
if (element.textElement.atType == AtType.atAll) {
|
||||||
// message_data["data"]["mention"] = "all"
|
// message_data["data"]["mention"] = "all"
|
||||||
message_data['data']['qq'] = 'all'
|
qq = 'all'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let atUid = element.textElement.atNtUid
|
const { atNtUid, content } = element.textElement
|
||||||
let atQQ = element.textElement.atUid
|
let atQQ = element.textElement.atUid
|
||||||
if (!atQQ || atQQ === '0') {
|
if (!atQQ || atQQ === '0') {
|
||||||
const atMember = await getGroupMember(msg.peerUin, atUid)
|
const atMember = await getGroupMember(msg.peerUin, atNtUid)
|
||||||
if (atMember) {
|
if (atMember) {
|
||||||
atQQ = atMember.uin
|
atQQ = atMember.uin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (atQQ) {
|
if (atQQ) {
|
||||||
// message_data["data"]["mention"] = atQQ
|
// message_data["data"]["mention"] = atQQ
|
||||||
message_data['data']['qq'] = atQQ
|
qq = atQQ
|
||||||
|
name = content.replace('@', '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message_data = {
|
||||||
|
type: OB11MessageDataType.at,
|
||||||
|
data: {
|
||||||
|
qq,
|
||||||
|
name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (element.textElement) {
|
else if (element.textElement) {
|
||||||
message_data['type'] = 'text'
|
message_data['type'] = OB11MessageDataType.text
|
||||||
let text = element.textElement.content
|
let text = element.textElement.content
|
||||||
if (!text.trim()) {
|
if (!text.trim()) {
|
||||||
continue
|
continue
|
||||||
@ -143,7 +152,7 @@ export class OB11Constructor {
|
|||||||
message_data['data']['text'] = text
|
message_data['data']['text'] = text
|
||||||
}
|
}
|
||||||
else if (element.replyElement) {
|
else if (element.replyElement) {
|
||||||
message_data['type'] = 'reply'
|
message_data['type'] = OB11MessageDataType.reply
|
||||||
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
||||||
try {
|
try {
|
||||||
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
||||||
@ -159,7 +168,7 @@ export class OB11Constructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (element.picElement) {
|
else if (element.picElement) {
|
||||||
message_data['type'] = 'image'
|
message_data['type'] = OB11MessageDataType.image
|
||||||
// message_data["data"]["file"] = element.picElement.sourcePath
|
// message_data["data"]["file"] = element.picElement.sourcePath
|
||||||
let fileName = element.picElement.fileName
|
let fileName = element.picElement.fileName
|
||||||
const sourcePath = element.picElement.sourcePath
|
const sourcePath = element.picElement.sourcePath
|
||||||
@ -204,9 +213,9 @@ export class OB11Constructor {
|
|||||||
message_data['data']['file_size'] = videoOrFileElement.fileSize
|
message_data['data']['file_size'] = videoOrFileElement.fileSize
|
||||||
if (element.videoElement) {
|
if (element.videoElement) {
|
||||||
message_data['data']['url'] = await NTQQFileApi.getVideoUrl({
|
message_data['data']['url'] = await NTQQFileApi.getVideoUrl({
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
}, msg.msgId, element.elementId,
|
}, msg.msgId, element.elementId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
dbUtil
|
dbUtil
|
||||||
@ -296,7 +305,7 @@ export class OB11Constructor {
|
|||||||
message_data['type'] = OB11MessageDataType.forward
|
message_data['type'] = OB11MessageDataType.forward
|
||||||
message_data['data']['id'] = msg.msgId
|
message_data['data']['id'] = msg.msgId
|
||||||
}
|
}
|
||||||
if (message_data.type !== 'unknown' && message_data.data) {
|
if ((message_data.type as string) !== 'unknown' && message_data.data) {
|
||||||
const cqCode = encodeCQCode(message_data)
|
const cqCode = encodeCQCode(message_data)
|
||||||
if (messagePostFormat === 'string') {
|
if (messagePostFormat === 'string') {
|
||||||
(resMsg.message as string) += cqCode
|
(resMsg.message as string) += cqCode
|
||||||
|
@ -61,15 +61,15 @@ export function encodeCQCode(data: OB11MessageData) {
|
|||||||
let result = '[CQ:' + data.type
|
let result = '[CQ:' + data.type
|
||||||
for (const name in data.data) {
|
for (const name in data.data) {
|
||||||
const value = data.data[name]
|
const value = data.data[name]
|
||||||
|
if (value === undefined) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Check if the value can be converted to a string
|
result += `,${name}=${CQCodeEscape(value)}`
|
||||||
value.toString();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If it can't be converted, skip this name-value pair
|
// If it can't be converted, skip this name-value pair
|
||||||
// console.warn(`Skipping problematic name-value pair. Name: ${name}, Value: ${value}`);
|
continue
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
result += `,${name}=${CQCodeEscape(value)}`
|
|
||||||
}
|
}
|
||||||
result += ']'
|
result += ']'
|
||||||
return result
|
return result
|
||||||
|
@ -195,6 +195,7 @@ export interface OB11MessageAt {
|
|||||||
type: OB11MessageDataType.at
|
type: OB11MessageDataType.at
|
||||||
data: {
|
data: {
|
||||||
qq: string | 'all'
|
qq: string | 'all'
|
||||||
|
name?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +242,20 @@ export interface OB11MessageJson {
|
|||||||
data: { data: string /* , config: { token: string } */ }
|
data: { data: string /* , config: { token: string } */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface OB11MessageMarkdown {
|
||||||
|
type: OB11MessageDataType.markdown
|
||||||
|
data: {
|
||||||
|
data: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OB11MessageForward {
|
||||||
|
type: OB11MessageDataType.forward
|
||||||
|
data: {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export type OB11MessageData =
|
export type OB11MessageData =
|
||||||
| OB11MessageText
|
| OB11MessageText
|
||||||
| OB11MessageFace
|
| OB11MessageFace
|
||||||
@ -258,6 +273,8 @@ export type OB11MessageData =
|
|||||||
| OB11MessagePoke
|
| OB11MessagePoke
|
||||||
| OB11MessageDice
|
| OB11MessageDice
|
||||||
| OB11MessageRPS
|
| OB11MessageRPS
|
||||||
|
| OB11MessageMarkdown
|
||||||
|
| OB11MessageForward
|
||||||
|
|
||||||
export interface OB11PostSendMsg {
|
export interface OB11PostSendMsg {
|
||||||
message_type?: 'private' | 'group'
|
message_type?: 'private' | 'group'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user