This commit is contained in:
idranme
2024-09-08 20:50:22 +08:00
parent 1bcdbba29a
commit dc25d83778
6 changed files with 36 additions and 29 deletions

View File

@@ -23,7 +23,7 @@
"cosmokit": "^1.6.2",
"express": "^4.19.2",
"fast-xml-parser": "^4.5.0",
"file-type": "^19.4.1",
"file-type": "^19.5.0",
"fluent-ffmpeg": "^2.1.3",
"minato": "^3.5.1",
"silk-wasm": "^3.6.1",

View File

@@ -252,4 +252,8 @@ export class NTQQMsgApi extends Service {
}
}, null])
}
async setMsgRead(peer: Peer) {
return await invoke('nodeIKernelMsgService/setMsgRead', [{ peer }, null])
}
}

View File

@@ -100,18 +100,19 @@ export namespace SendElementEntities {
}
export async function file(ctx: Context, filePath: string, fileName = '', folderId = ''): Promise<SendFileElement> {
const { fileName: _fileName, path, fileSize } = await ctx.ntFileApi.uploadFile(filePath, ElementType.FILE)
if (fileSize === 0) {
throw '文件异常,大小为 0'
const fileSize = (await stat(filePath)).size.toString()
if (fileSize === '0') {
ctx.logger.warn(`文件${fileName}异常,大小为 0`)
throw new Error('文件异常,大小为 0')
}
const element: SendFileElement = {
elementType: ElementType.FILE,
elementId: '',
fileElement: {
fileName: fileName || _fileName,
folderId: folderId,
filePath: path!,
fileSize: fileSize.toString(),
fileName,
folderId,
filePath,
fileSize,
},
}
return element

View File

@@ -1,14 +1,23 @@
import BaseAction from '../BaseAction'
import { ActionName } from '../types'
import { MessageUnique } from '@/common/utils/messageUnique'
interface Payload {
message_id: number
message_id: number | string
}
export class MarkMsgAsRead extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_MarkMsgAsRead
protected async _handle() {
protected async _handle(payload: Payload) {
if (!payload.message_id) {
throw new Error('参数 message_id 不能为空')
}
const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)
if (!msg) {
throw new Error('msg not found')
}
await this.ctx.ntMsgApi.setMsgRead(msg.Peer)
return null
}
}

View File

@@ -15,6 +15,9 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_SendGroupNotice
async _handle(payload: Payload) {
if(!payload.content){
throw new Error('参数 content 不能为空')
}
const groupCode = payload.group_id.toString()
const pinned = Number(payload.pinned ?? 0)
const confirmRequired = Number(payload.confirm_required ?? 1)

View File

@@ -1,8 +1,6 @@
import fs from 'node:fs'
import BaseAction from '../BaseAction'
import { ActionName } from '../types'
import { SendElementEntities } from '@/ntqqapi/entities'
import { SendFileElement } from '@/ntqqapi/types'
import { uri2local } from '@/common/utils'
import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
@@ -18,15 +16,11 @@ export class UploadGroupFile extends BaseAction<UploadGroupFilePayload, null> {
actionName = ActionName.GoCQHTTP_UploadGroupFile
protected async _handle(payload: UploadGroupFilePayload): Promise<null> {
let file = payload.file
if (fs.existsSync(file)) {
file = `file://${file}`
const { success, errMsg, path } = await uri2local(payload.file)
if (!success) {
throw new Error(errMsg)
}
const downloadResult = await uri2local(file)
if (!downloadResult.success) {
throw new Error(downloadResult.errMsg)
}
const sendFileEle = await SendElementEntities.file(this.ctx, downloadResult.path, payload.name, payload.folder_id)
const sendFileEle = await SendElementEntities.file(this.ctx, path, payload.name, payload.folder_id)
const peer = await createPeer(this.ctx, payload, CreatePeerMode.Group)
await sendMsg(this.ctx, peer, [sendFileEle], [])
return null
@@ -43,16 +37,12 @@ export class UploadPrivateFile extends BaseAction<UploadPrivateFilePayload, null
actionName = ActionName.GoCQHTTP_UploadPrivateFile
protected async _handle(payload: UploadPrivateFilePayload): Promise<null> {
const { success, errMsg, path } = await uri2local(payload.file)
if (!success) {
throw new Error(errMsg)
}
const sendFileEle = await SendElementEntities.file(this.ctx, path, payload.name)
const peer = await createPeer(this.ctx, payload, CreatePeerMode.Private)
let file = payload.file
if (fs.existsSync(file)) {
file = `file://${file}`
}
const downloadResult = await uri2local(file)
if (!downloadResult.success) {
throw new Error(downloadResult.errMsg)
}
const sendFileEle: SendFileElement = await SendElementEntities.file(this.ctx, downloadResult.path, payload.name)
await sendMsg(this.ctx, peer, [sendFileEle], [])
return null
}