Compare commits

..

14 Commits

Author SHA1 Message Date
linyuchen
debe3a8597 chore: version 3.26.1 2024-05-24 08:54:23 +08:00
linyuchen
f36c5e849f Merge pull request #234 from LLOneBot/dev
fix: #215 get_forward_msg params missing id(onebot11)
2024-05-24 08:52:34 +08:00
linyuchen
abbd6797c4 fix: #215 get_forward_msg params missing id(onebot11) 2024-05-24 08:50:22 +08:00
linyuchen
fdb7784a7d Merge pull request #233 from LLOneBot/dev
[Feature] OneBot11消息构造添加raw字段,单条转发消息接口返回message_id
2024-05-24 08:40:44 +08:00
linyuchen
92b49015b0 feat: Forward single msg return message_id 2024-05-24 08:36:42 +08:00
linyuchen
1765ffff7b style: format 2024-05-24 08:15:08 +08:00
linyuchen
3024316b5b feat: #232 /get_msg, /get_group_msg_history add raw message 2024-05-24 08:11:38 +08:00
linyuchen
9a0d89bfbf Update README.md 2024-05-19 07:52:12 +08:00
linyuchen
807ef3b700 Merge pull request #228 from LLOneBot/dev
feat: Quick operation reply auto quote original message
2024-05-18 16:53:37 +08:00
linyuchen
948f10d4e3 feat: Quick operation reply auto quote original message 2024-05-18 16:51:34 +08:00
linyuchen
0f99b5cb87 Merge pull request #227 from LLOneBot/dev
fix: Send msg timeout minimum
2024-05-18 16:36:30 +08:00
linyuchen
6413b0ff82 fix: Send msg timeout minimum 2024-05-18 16:34:12 +08:00
linyuchen
39713d8e11 Merge branch 'main' into dev 2024-05-18 16:31:22 +08:00
linyuchen
44448895a0 feat: 209 2024-05-18 13:09:45 +08:00
12 changed files with 115 additions and 85 deletions

View File

@@ -1,4 +1,4 @@
# LLOneBot API
# LLOneBot
LiteLoaderQQNT插件使你的NTQQ支持OneBot11协议进行QQ机器人开发

View File

@@ -1,10 +1,10 @@
{
"manifest_version": 4,
"type": "extension",
"name": "LLOneBot v3.26.0",
"name": "LLOneBot v3.26.1",
"slug": "LLOneBot",
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
"version": "3.26.0",
"version": "3.26.1",
"icon": "./icon.jpg",
"authors": [
{

View File

@@ -142,7 +142,8 @@ function onLoad() {
.catch((e) => {
log('保存设置失败', e.stack)
})
} else {
}
else {
}
})
.catch((err) => {
@@ -169,12 +170,8 @@ function onLoad() {
OB11Constructor.message(message)
.then((msg) => {
if (debug) {
msg.raw = message
} else {
if (msg.message.length === 0) {
return
}
if (!debug && msg.message.length === 0) {
return
}
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
if (isSelfMsg && !reportSelfMessage) {
@@ -210,7 +207,8 @@ function onLoad() {
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent
if (isGroup) {
pokeEvent = new OB11GroupPokeEvent(parseInt(id))
} else {
}
else {
pokeEvent = new OB11FriendPokeEvent(parseInt(id))
}
postOb11Event(pokeEvent)
@@ -323,10 +321,12 @@ function onLoad() {
: 'set'
// member1.role = notify.type == GroupNotifyTypes.ADMIN_SET ? GroupMemberRole.admin : GroupMemberRole.normal;
postOb11Event(groupAdminNoticeEvent, true)
} else {
}
else {
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)
try {
const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid)
@@ -348,7 +348,8 @@ function onLoad() {
} catch (e) {
log('获取群通知的成员信息失败', notify, e.stack.toString())
}
} else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
}
else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
log('有加群请求')
let groupRequestEvent = new OB11GroupRequestEvent()
groupRequestEvent.group_id = parseInt(notify.group.groupCode)
@@ -363,7 +364,8 @@ function onLoad() {
groupRequestEvent.comment = notify.postscript
groupRequestEvent.flag = notify.seq
postOb11Event(groupRequestEvent)
} else if (notify.type == GroupNotifyTypes.INVITE_ME) {
}
else if (notify.type == GroupNotifyTypes.INVITE_ME) {
log('收到邀请我加群通知')
let groupInviteEvent = new OB11GroupRequestEvent()
groupInviteEvent.group_id = parseInt(notify.group.groupCode)
@@ -380,7 +382,8 @@ function onLoad() {
log('解析群通知失败', e.stack.toString())
}
}
} else if (payload.doubt) {
}
else if (payload.doubt) {
// 可能有群管理员变动
}
})
@@ -473,7 +476,8 @@ function onLoad() {
getUserNick().then()
start().then()
} else {
}
else {
setTimeout(init, 1000)
}
}

View File

@@ -15,6 +15,54 @@ export interface Peer {
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 {
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {
// 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) {
const peerUid = peer.peerUid
// 等待上一个相同的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()
}
const waiter = sendWaiter(peer, waitComplete, timeout);
callNTQQApi({
methodName: NTQQApiMethod.SEND_MSG,
args: [
@@ -174,11 +177,12 @@ export class NTQQMsgApi {
null,
],
}).then()
return await checkSendComplete()
return await waiter;
}
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,
args: [
{
@@ -190,7 +194,8 @@ export class NTQQMsgApi {
},
null,
],
})
}).then().catch(log)
return await waiter;
}
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {

View File

@@ -6,7 +6,8 @@ import { OB11Constructor } from '../../constructor'
import { ActionName } from '../types'
interface Payload {
message_id: string // long msg id
message_id: string // long msg idgocq
id?: string // long msg id, onebot11
}
interface Response {
@@ -16,7 +17,11 @@ interface Response {
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any> {
actionName = ActionName.GoCQHTTP_GetForwardMsg
protected async _handle(payload: Payload): Promise<any> {
const rootMsg = await dbUtil.getMsgByLongId(payload.message_id)
const message_id = payload.id || payload.message_id
if (!message_id) {
throw Error('message_id不能为空')
}
const rootMsg = await dbUtil.getMsgByLongId(message_id)
if (!rootMsg) {
throw Error('msg not found')
}

View File

@@ -1,5 +1,5 @@
import BaseAction from '../BaseAction'
import { handleQuickOperation, QuickOperation, QuickOperationEvent } from '../../server/quick-operation'
import { handleQuickOperation, QuickOperation, QuickOperationEvent } from '../quick-operation'
import { log } from '@/common/utils'
import { ActionName } from '../types'

View File

@@ -11,7 +11,11 @@ interface Payload {
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> {
if (payload.user_id) {
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() }
}
protected async _handle(payload: Payload): Promise<null> {
protected async _handle(payload: Payload): Promise<Response> {
const msg = await dbUtil.getMsgByShortId(payload.message_id)
const peer = await this.getTargetPeer(payload)
await NTQQMsgApi.forwardMsg(
const sentMsg = await NTQQMsgApi.forwardMsg(
{
chatType: msg.chatType,
peerUid: msg.peerUid,
@@ -30,7 +34,8 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
peer,
[msg.msgId],
)
return null
const ob11MsgId = await dbUtil.addMsg(sentMsg)
return {message_id: ob11MsgId}
}
}

View File

@@ -327,7 +327,7 @@ export async function sendMsg(
}
}
log('发送消息总大小', totalSize, 'bytes')
let timeout = ((totalSize / 1024 / 512) * 1000) || 5000 // 512kb/s
let timeout = ((totalSize / 1024 / 512) * 1000) + 5000 // 512kb/s
log('设置消息超时时间', timeout)
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout)
log('消息发送结果', returnMsg)

View File

@@ -1,14 +1,14 @@
// handle quick action, create at 2024-5-18 10:54:39 by linyuchen
import { OB11Message, OB11MessageAt, OB11MessageData } from '../types'
import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from '../types'
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
import { dbUtil } from '@/common/db'
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, Peer } from '@/ntqqapi/api'
import { ChatType, Group, GroupRequestOperateTypes } from '@/ntqqapi/types'
import { getGroup, getUidByUin } from '@/common/data'
import { convertMessage2List, createSendElements, sendMsg } from '../action/msg/SendMsg'
import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg'
import { isNull, log } from '@/common/utils'
@@ -80,7 +80,14 @@ async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMes
}
if (reply) {
let group: Group = null
let replyMessage: OB11MessageData[] = []
let replyMessage: OB11MessageData[] = [
{
type: OB11MessageDataType.reply,
data: {
id: msg.message_id.toString(),
},
}
]
if (msg.message_type == 'group') {
group = await getGroup(msg.group_id.toString())

View File

@@ -55,6 +55,7 @@ export class OB11Constructor {
let config = getConfigUtil().getConfig()
const {
enableLocalFile2Url,
debug,
ob11: { messagePostFormat },
} = config
const message_type = msg.chatType == ChatType.group ? 'group' : 'private'
@@ -78,8 +79,11 @@ export class OB11Constructor {
message_format: messagePostFormat === 'string' ? 'string' : 'array',
post_type: selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE,
}
if (debug) {
resMsg.raw = msg
}
if (msg.chatType == ChatType.group) {
resMsg.sub_type = 'normal' // 这里go-cqhttp是group而onebot11标准是normal, 蛋疼
resMsg.sub_type = 'normal'
resMsg.group_id = parseInt(msg.peerUin)
const member = await getGroupMember(msg.peerUin, msg.senderUin)
if (member) {
@@ -155,16 +159,16 @@ export class OB11Constructor {
else if (element.picElement) {
message_data['type'] = 'image'
// message_data["data"]["file"] = element.picElement.sourcePath
let fileName = element.picElement.fileName;
const sourcePath = element.picElement.sourcePath;
if (element.picElement.picType === PicType.gif && !fileName.endsWith('.gif')){
fileName += ".gif";
let fileName = element.picElement.fileName
const sourcePath = element.picElement.sourcePath
if (element.picElement.picType === PicType.gif && !fileName.endsWith('.gif')) {
fileName += '.gif'
}
message_data['data']['file'] = fileName
// message_data["data"]["path"] = element.picElement.sourcePath
// 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_size'] = element.picElement.fileSize
dbUtil

View File

@@ -7,7 +7,7 @@ import { wsReply } from './ws/reply'
import { log } from '@/common/utils'
import { getConfigUtil } from '@/common/config'
import crypto from 'crypto'
import { handleQuickOperation, QuickOperationEvent } from './quick-operation'
import { handleQuickOperation, QuickOperationEvent } from '../action/quick-operation'
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent

View File

@@ -1 +1 @@
export const version = '3.26.0'
export const version = '3.26.1'