mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge pull request #233 from LLOneBot/dev
[Feature] OneBot11消息构造添加raw字段,单条转发消息接口返回message_id
This commit is contained in:
commit
fdb7784a7d
@ -142,7 +142,8 @@ function onLoad() {
|
|||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
log('保存设置失败', e.stack)
|
log('保存设置失败', e.stack)
|
||||||
})
|
})
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -169,12 +170,8 @@ function onLoad() {
|
|||||||
|
|
||||||
OB11Constructor.message(message)
|
OB11Constructor.message(message)
|
||||||
.then((msg) => {
|
.then((msg) => {
|
||||||
if (debug) {
|
if (!debug && msg.message.length === 0) {
|
||||||
msg.raw = message
|
return
|
||||||
} else {
|
|
||||||
if (msg.message.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
||||||
if (isSelfMsg && !reportSelfMessage) {
|
if (isSelfMsg && !reportSelfMessage) {
|
||||||
@ -210,7 +207,8 @@ function onLoad() {
|
|||||||
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent
|
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent
|
||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
pokeEvent = new OB11GroupPokeEvent(parseInt(id))
|
pokeEvent = new OB11GroupPokeEvent(parseInt(id))
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
pokeEvent = new OB11FriendPokeEvent(parseInt(id))
|
pokeEvent = new OB11FriendPokeEvent(parseInt(id))
|
||||||
}
|
}
|
||||||
postOb11Event(pokeEvent)
|
postOb11Event(pokeEvent)
|
||||||
@ -323,10 +321,12 @@ function onLoad() {
|
|||||||
: 'set'
|
: 'set'
|
||||||
// member1.role = notify.type == GroupNotifyTypes.ADMIN_SET ? GroupMemberRole.admin : GroupMemberRole.normal;
|
// member1.role = notify.type == GroupNotifyTypes.ADMIN_SET ? GroupMemberRole.admin : GroupMemberRole.normal;
|
||||||
postOb11Event(groupAdminNoticeEvent, true)
|
postOb11Event(groupAdminNoticeEvent, true)
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
log('获取群通知的成员信息失败', notify, getGroup(notify.group.groupCode))
|
log('获取群通知的成员信息失败', notify, getGroup(notify.group.groupCode))
|
||||||
}
|
}
|
||||||
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
}
|
||||||
|
else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
||||||
log('有成员退出通知', notify)
|
log('有成员退出通知', notify)
|
||||||
try {
|
try {
|
||||||
const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid)
|
const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid)
|
||||||
@ -348,7 +348,8 @@ function onLoad() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('获取群通知的成员信息失败', notify, e.stack.toString())
|
log('获取群通知的成员信息失败', notify, e.stack.toString())
|
||||||
}
|
}
|
||||||
} else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
|
}
|
||||||
|
else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
|
||||||
log('有加群请求')
|
log('有加群请求')
|
||||||
let groupRequestEvent = new OB11GroupRequestEvent()
|
let groupRequestEvent = new OB11GroupRequestEvent()
|
||||||
groupRequestEvent.group_id = parseInt(notify.group.groupCode)
|
groupRequestEvent.group_id = parseInt(notify.group.groupCode)
|
||||||
@ -363,7 +364,8 @@ function onLoad() {
|
|||||||
groupRequestEvent.comment = notify.postscript
|
groupRequestEvent.comment = notify.postscript
|
||||||
groupRequestEvent.flag = notify.seq
|
groupRequestEvent.flag = notify.seq
|
||||||
postOb11Event(groupRequestEvent)
|
postOb11Event(groupRequestEvent)
|
||||||
} else if (notify.type == GroupNotifyTypes.INVITE_ME) {
|
}
|
||||||
|
else if (notify.type == GroupNotifyTypes.INVITE_ME) {
|
||||||
log('收到邀请我加群通知')
|
log('收到邀请我加群通知')
|
||||||
let groupInviteEvent = new OB11GroupRequestEvent()
|
let groupInviteEvent = new OB11GroupRequestEvent()
|
||||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode)
|
groupInviteEvent.group_id = parseInt(notify.group.groupCode)
|
||||||
@ -380,7 +382,8 @@ function onLoad() {
|
|||||||
log('解析群通知失败', e.stack.toString())
|
log('解析群通知失败', e.stack.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (payload.doubt) {
|
}
|
||||||
|
else if (payload.doubt) {
|
||||||
// 可能有群管理员变动
|
// 可能有群管理员变动
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -473,7 +476,8 @@ function onLoad() {
|
|||||||
|
|
||||||
getUserNick().then()
|
getUserNick().then()
|
||||||
start().then()
|
start().then()
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
setTimeout(init, 1000)
|
setTimeout(init, 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,54 @@ export interface Peer {
|
|||||||
guildId?: ''
|
guildId?: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendWaiter(peer: Peer, waitComplete = true, timeout: number = 10000) {
|
||||||
|
// 等待上一个相同的peer发送完
|
||||||
|
const peerUid = peer.peerUid
|
||||||
|
let checkLastSendUsingTime = 0
|
||||||
|
const waitLastSend = async () => {
|
||||||
|
if (checkLastSendUsingTime > timeout) {
|
||||||
|
throw '发送超时'
|
||||||
|
}
|
||||||
|
let lastSending = sendMessagePool[peer.peerUid]
|
||||||
|
if (lastSending) {
|
||||||
|
// log("有正在发送的消息,等待中...")
|
||||||
|
await sleep(500)
|
||||||
|
checkLastSendUsingTime += 500
|
||||||
|
return await waitLastSend()
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await waitLastSend()
|
||||||
|
|
||||||
|
let sentMessage: RawMessage = null
|
||||||
|
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
||||||
|
delete sendMessagePool[peerUid]
|
||||||
|
sentMessage = rawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
let checkSendCompleteUsingTime = 0
|
||||||
|
const checkSendComplete = async (): Promise<RawMessage> => {
|
||||||
|
if (sentMessage) {
|
||||||
|
if (waitComplete) {
|
||||||
|
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
// log(`给${peerUid}发送消息成功`)
|
||||||
|
}
|
||||||
|
checkSendCompleteUsingTime += 500
|
||||||
|
if (checkSendCompleteUsingTime > timeout) {
|
||||||
|
throw '发送超时'
|
||||||
|
}
|
||||||
|
await sleep(500)
|
||||||
|
return await checkSendComplete()
|
||||||
|
}
|
||||||
|
return checkSendComplete();
|
||||||
|
}
|
||||||
|
|
||||||
export class NTQQMsgApi {
|
export class NTQQMsgApi {
|
||||||
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {
|
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {
|
||||||
// nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览
|
// nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览
|
||||||
@ -116,52 +164,7 @@ export class NTQQMsgApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||||
const peerUid = peer.peerUid
|
const waiter = sendWaiter(peer, waitComplete, timeout);
|
||||||
|
|
||||||
// 等待上一个相同的peer发送完
|
|
||||||
let checkLastSendUsingTime = 0
|
|
||||||
const waitLastSend = async () => {
|
|
||||||
if (checkLastSendUsingTime > timeout) {
|
|
||||||
throw '发送超时'
|
|
||||||
}
|
|
||||||
let lastSending = sendMessagePool[peer.peerUid]
|
|
||||||
if (lastSending) {
|
|
||||||
// log("有正在发送的消息,等待中...")
|
|
||||||
await sleep(500)
|
|
||||||
checkLastSendUsingTime += 500
|
|
||||||
return await waitLastSend()
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await waitLastSend()
|
|
||||||
|
|
||||||
let sentMessage: RawMessage = null
|
|
||||||
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
|
||||||
delete sendMessagePool[peerUid]
|
|
||||||
sentMessage = rawMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
let checkSendCompleteUsingTime = 0
|
|
||||||
const checkSendComplete = async (): Promise<RawMessage> => {
|
|
||||||
if (sentMessage) {
|
|
||||||
if (waitComplete) {
|
|
||||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
// log(`给${peerUid}发送消息成功`)
|
|
||||||
}
|
|
||||||
checkSendCompleteUsingTime += 500
|
|
||||||
if (checkSendCompleteUsingTime > timeout) {
|
|
||||||
throw '发送超时'
|
|
||||||
}
|
|
||||||
await sleep(500)
|
|
||||||
return await checkSendComplete()
|
|
||||||
}
|
|
||||||
|
|
||||||
callNTQQApi({
|
callNTQQApi({
|
||||||
methodName: NTQQApiMethod.SEND_MSG,
|
methodName: NTQQApiMethod.SEND_MSG,
|
||||||
args: [
|
args: [
|
||||||
@ -174,11 +177,12 @@ export class NTQQMsgApi {
|
|||||||
null,
|
null,
|
||||||
],
|
],
|
||||||
}).then()
|
}).then()
|
||||||
return await checkSendComplete()
|
return await waiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
const waiter = sendWaiter(destPeer, true, 10000);
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.FORWARD_MSG,
|
methodName: NTQQApiMethod.FORWARD_MSG,
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
@ -190,7 +194,8 @@ export class NTQQMsgApi {
|
|||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
],
|
],
|
||||||
})
|
}).then().catch(log)
|
||||||
|
return await waiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
|
@ -11,7 +11,11 @@ interface Payload {
|
|||||||
user_id?: number
|
user_id?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
class ForwardSingleMsg extends BaseAction<Payload, null> {
|
interface Response {
|
||||||
|
message_id: number
|
||||||
|
}
|
||||||
|
|
||||||
|
class ForwardSingleMsg extends BaseAction<Payload, Response> {
|
||||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||||
if (payload.user_id) {
|
if (payload.user_id) {
|
||||||
return { chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString()) }
|
return { chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString()) }
|
||||||
@ -19,10 +23,10 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
|
|||||||
return { chatType: ChatType.group, peerUid: payload.group_id.toString() }
|
return { chatType: ChatType.group, peerUid: payload.group_id.toString() }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
const msg = await dbUtil.getMsgByShortId(payload.message_id)
|
const msg = await dbUtil.getMsgByShortId(payload.message_id)
|
||||||
const peer = await this.getTargetPeer(payload)
|
const peer = await this.getTargetPeer(payload)
|
||||||
await NTQQMsgApi.forwardMsg(
|
const sentMsg = await NTQQMsgApi.forwardMsg(
|
||||||
{
|
{
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
@ -30,7 +34,8 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
|
|||||||
peer,
|
peer,
|
||||||
[msg.msgId],
|
[msg.msgId],
|
||||||
)
|
)
|
||||||
return null
|
const ob11MsgId = await dbUtil.addMsg(sentMsg)
|
||||||
|
return {message_id: ob11MsgId}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ export class OB11Constructor {
|
|||||||
let config = getConfigUtil().getConfig()
|
let config = getConfigUtil().getConfig()
|
||||||
const {
|
const {
|
||||||
enableLocalFile2Url,
|
enableLocalFile2Url,
|
||||||
|
debug,
|
||||||
ob11: { messagePostFormat },
|
ob11: { messagePostFormat },
|
||||||
} = config
|
} = config
|
||||||
const message_type = msg.chatType == ChatType.group ? 'group' : 'private'
|
const message_type = msg.chatType == ChatType.group ? 'group' : 'private'
|
||||||
@ -78,8 +79,11 @@ export class OB11Constructor {
|
|||||||
message_format: messagePostFormat === 'string' ? 'string' : 'array',
|
message_format: messagePostFormat === 'string' ? 'string' : 'array',
|
||||||
post_type: selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE,
|
post_type: selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE,
|
||||||
}
|
}
|
||||||
|
if (debug) {
|
||||||
|
resMsg.raw = msg
|
||||||
|
}
|
||||||
if (msg.chatType == ChatType.group) {
|
if (msg.chatType == ChatType.group) {
|
||||||
resMsg.sub_type = 'normal' // 这里go-cqhttp是group,而onebot11标准是normal, 蛋疼
|
resMsg.sub_type = 'normal'
|
||||||
resMsg.group_id = parseInt(msg.peerUin)
|
resMsg.group_id = parseInt(msg.peerUin)
|
||||||
const member = await getGroupMember(msg.peerUin, msg.senderUin)
|
const member = await getGroupMember(msg.peerUin, msg.senderUin)
|
||||||
if (member) {
|
if (member) {
|
||||||
@ -155,16 +159,16 @@ export class OB11Constructor {
|
|||||||
else if (element.picElement) {
|
else if (element.picElement) {
|
||||||
message_data['type'] = 'image'
|
message_data['type'] = '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
|
||||||
if (element.picElement.picType === PicType.gif && !fileName.endsWith('.gif')){
|
if (element.picElement.picType === PicType.gif && !fileName.endsWith('.gif')) {
|
||||||
fileName += ".gif";
|
fileName += '.gif'
|
||||||
}
|
}
|
||||||
message_data['data']['file'] = fileName
|
message_data['data']['file'] = fileName
|
||||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
// message_data["data"]["path"] = element.picElement.sourcePath
|
||||||
// let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
// let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
||||||
|
|
||||||
message_data['data']['url'] = await NTQQFileApi.getImageUrl(element.picElement, msg.chatType);
|
message_data['data']['url'] = await NTQQFileApi.getImageUrl(element.picElement, msg.chatType)
|
||||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||||
message_data['data']['file_size'] = element.picElement.fileSize
|
message_data['data']['file_size'] = element.picElement.fileSize
|
||||||
dbUtil
|
dbUtil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user