mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
尝试发送语音
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2023 by Night-stars-1, All Rights Reserved.
|
* Copyright (c) 2023 by Night-stars-1, All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
const plugin_path = LiteLoader.plugins.LLAPI.path.plugin;
|
const plugin_path = LiteLoader.plugins.LLAPI.path.plugin;
|
||||||
const ipcRenderer = LLAPI_PRE.ipcRenderer_LL;
|
const ipcRenderer = LLAPI_PRE.ipcRenderer_LL;
|
||||||
const ipcRenderer_on = LLAPI_PRE.ipcRenderer_LL_on;
|
const ipcRenderer_on = LLAPI_PRE.ipcRenderer_LL_on;
|
||||||
@@ -344,6 +346,7 @@ class Api extends EventEmitter {
|
|||||||
elements.map(async (element) => {
|
elements.map(async (element) => {
|
||||||
if (element.type == "text") return destructor.destructTextElement(element);
|
if (element.type == "text") return destructor.destructTextElement(element);
|
||||||
else if (element.type == "image") return destructor.destructImageElement(element, await media.prepareImageElement(element.file));
|
else if (element.type == "image") return destructor.destructImageElement(element, await media.prepareImageElement(element.file));
|
||||||
|
else if (element.type == "voice") return destructor.destructPttElement(element, await media.prepareVoiceElement(element.file));
|
||||||
else if (element.type == "face") return destructor.destructFaceElement(element);
|
else if (element.type == "face") return destructor.destructFaceElement(element);
|
||||||
else if (element.type == "raw") return destructor.destructRawElement(element);
|
else if (element.type == "raw") return destructor.destructRawElement(element);
|
||||||
else return null;
|
else return null;
|
||||||
@@ -645,6 +648,14 @@ class Destructor {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destructPttElement(element, pttElement) {
|
||||||
|
return {
|
||||||
|
elementType: 4,
|
||||||
|
elementId: "",
|
||||||
|
pttElement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
destructFaceElement(element) {
|
destructFaceElement(element) {
|
||||||
return {
|
return {
|
||||||
elementType: 6,
|
elementType: 6,
|
||||||
@@ -811,6 +822,41 @@ class Destructor {
|
|||||||
const destructor = new Destructor();
|
const destructor = new Destructor();
|
||||||
|
|
||||||
class Media {
|
class Media {
|
||||||
|
async prepareVoiceElement(file) {
|
||||||
|
const type = await ntCall("ns-fsApi", "getFileType", [file]);
|
||||||
|
const md5 = await ntCall("ns-fsApi", "getFileMd5", [file]);
|
||||||
|
const fileName = `${md5}.${type.ext}`;
|
||||||
|
const filePath = await ntCall("ns-ntApi", "nodeIKernelMsgService/getRichMediaFilePath", [
|
||||||
|
{
|
||||||
|
md5HexStr: md5,
|
||||||
|
fileName: fileName,
|
||||||
|
elementType: 4,
|
||||||
|
elementSubType: 0,
|
||||||
|
thumbSize: 0,
|
||||||
|
needCreate: true,
|
||||||
|
fileType: 1, // 这个未知
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const fileSize = await ntCall("ns-fsApi", "getFileSize", [file]);
|
||||||
|
return {
|
||||||
|
canConvert2Text: true,
|
||||||
|
fileName: fileName,
|
||||||
|
filePath: filePath,
|
||||||
|
md5HexStr: md5,
|
||||||
|
fileId: 0,
|
||||||
|
fileSubId: '',
|
||||||
|
fileSize: fileSize,
|
||||||
|
duration: 2,
|
||||||
|
formatType: 1,
|
||||||
|
voiceType: 1,
|
||||||
|
voiceChangeType: 0,
|
||||||
|
playState: 1,
|
||||||
|
waveAmplitudes: [
|
||||||
|
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async prepareImageElement(file) {
|
async prepareImageElement(file) {
|
||||||
const type = await ntCall("ns-fsApi", "getFileType", [file]);
|
const type = await ntCall("ns-fsApi", "getFileType", [file]);
|
||||||
const md5 = await ntCall("ns-fsApi", "getFileMd5", [file]);
|
const md5 = await ntCall("ns-fsApi", "getFileMd5", [file]);
|
||||||
|
@@ -203,7 +203,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
else if (message.type == "text"){
|
else if (message.type == "text"){
|
||||||
message.content = message.data?.text || message.content
|
message.content = message.data?.text || message.content
|
||||||
}
|
}
|
||||||
else if (message.type == "image"){
|
else if (message.type == "image" || message.type == "voice"){
|
||||||
message.file = message.data?.file || message.file
|
message.file = message.data?.file || message.file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
src/types.ts
24
src/types.ts
@@ -59,6 +59,28 @@ export type MessageElement = {
|
|||||||
fileSize: number
|
fileSize: number
|
||||||
fileName: string
|
fileName: string
|
||||||
fileUuid: string
|
fileUuid: string
|
||||||
|
},
|
||||||
|
pttElement: {
|
||||||
|
canConvert2Text: boolean
|
||||||
|
duration: number // 秒数
|
||||||
|
fileBizId: null
|
||||||
|
fileId: number // 0
|
||||||
|
fileName: string // "e4d09c784d5a2abcb2f9980bdc7acfe6.amr"
|
||||||
|
filePath: string // "/Users/C5366155/Library/Containers/com.tencent.qq/Data/Library/Application Support/QQ/nt_qq_a6b15c9820595d25a56c1633ce19ad40/nt_data/Ptt/2023-11/Ori/e4d09c784d5a2abcb2f9980bdc7acfe6.amr"
|
||||||
|
fileSize: string // "4261"
|
||||||
|
fileSubId: string // "0"
|
||||||
|
fileUuid: string // "90j3z7rmRphDPrdVgP9udFBaYar#oK0TWZIV"
|
||||||
|
formatType: string // 1
|
||||||
|
invalidState: number // 0
|
||||||
|
md5HexStr: string // "e4d09c784d5a2abcb2f9980bdc7acfe6"
|
||||||
|
playState: number // 0
|
||||||
|
progress: number // 0
|
||||||
|
text: string // ""
|
||||||
|
transferStatus: number // 0
|
||||||
|
translateStatus: number // 0
|
||||||
|
voiceChangeType: number // 0
|
||||||
|
voiceType: number // 0
|
||||||
|
waveAmplitudes: number[]
|
||||||
}
|
}
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
@@ -78,7 +100,7 @@ export type SendMessage = {
|
|||||||
text: string, // 纯文本
|
text: string, // 纯文本
|
||||||
}
|
}
|
||||||
} | {
|
} | {
|
||||||
type: "image",
|
type: "image" | "voice",
|
||||||
file: string, // 本地路径
|
file: string, // 本地路径
|
||||||
data?: {
|
data?: {
|
||||||
file: string // 本地路径
|
file: string // 本地路径
|
||||||
|
@@ -3,6 +3,7 @@ const baseConfig = require('./webpack.base.config.js')
|
|||||||
baseConfig.target = 'electron-main'
|
baseConfig.target = 'electron-main'
|
||||||
baseConfig.entry = {
|
baseConfig.entry = {
|
||||||
main: './src/main.ts',
|
main: './src/main.ts',
|
||||||
|
// preload: './src/preload.ts',
|
||||||
}
|
}
|
||||||
baseConfig.output.libraryTarget = 'commonjs2'
|
baseConfig.output.libraryTarget = 'commonjs2'
|
||||||
baseConfig.output.chunkFormat = 'commonjs'
|
baseConfig.output.chunkFormat = 'commonjs'
|
||||||
|
Reference in New Issue
Block a user