Compare commits

..

5 Commits

Author SHA1 Message Date
linyuchen
0a3ae76b89 v1.2.7 2024-01-20 23:24:49 +08:00
linyuchen
ddd60a6a79 fix voice record type 2024-01-20 23:24:24 +08:00
linyuchen
e4d8c5e72e Merge remote-tracking branch 'origin/main' 2024-01-20 22:28:03 +08:00
linyuchen
6d33fb8b14 check gif 2024-01-20 08:38:14 +08:00
linyuchen
2350e4dc75 Update README.md 2024-01-13 18:27:30 +08:00
6 changed files with 22 additions and 8 deletions

View File

@@ -56,3 +56,6 @@
![](doc/image/example.jpg)
*暂时不支持`"message": "hello"`这种message为字符串的形式*
## onebot11文档
<https://11.onebot.dev/>

View File

@@ -4,7 +4,7 @@
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi",
"version": "1.2.6",
"version": "1.2.7",
"thumbnail": "./icon.png",
"author": {
"name": "linyuchen",

View File

@@ -114,7 +114,7 @@ export type SendMessage = {
text: string, // 纯文本
}
} | {
type: "image" | "voice",
type: "image" | "voice" | "record",
file: string, // 本地路径
data?: {
file: string // 本地路径

View File

@@ -17,7 +17,7 @@ import {
} from "../common/IPCChannel";
import {ConfigUtil} from "./config";
import {startExpress} from "./HttpServer";
import {log} from "./utils";
import {isGIF, log} from "./utils";
import {friends, groups, selfInfo} from "./data";
const fs = require('fs');
@@ -55,7 +55,10 @@ function onLoad(plugin: any) {
let buffer = await blob.arrayBuffer();
fs.writeFileSync(arg.localFilePath, Buffer.from(buffer));
}
// todo: 需要识别gif格式
if (isGIF(arg.localFilePath)) {
fs.renameSync(arg.localFilePath, arg.localFilePath + ".gif");
arg.localFilePath += ".gif";
}
return arg.localFilePath;
})
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {

View File

@@ -5,4 +5,12 @@ export function log(msg: any) {
fs.appendFile("./llonebot.log", currentDateTime + ":" + msg + "\n", (err: any) => {
})
}
export function isGIF(path: string) {
const buffer = Buffer.alloc(4);
const fd = fs.openSync(path, 'r');
fs.readSync(fd, buffer, 0, 4, 0);
fs.closeSync(fd);
return buffer.toString() === 'GIF8'
}

View File

@@ -227,23 +227,23 @@ async function listenSendMessage(postData: PostDataSendMsg) {
message.content = `@${atMember.cardName || atMember.nick}`
} else if (message.type == "text") {
message.content = message.data?.text || message.content
} else if (message.type == "image" || message.type == "voice") {
} else if (message.type == "image" || message.type == "voice" || message.type == "record") {
// todo: 收到的应该是uri格式的需要转成本地的, uri格式有三种http, file, base64
let url = message.data?.file || message.file
let uri = new URL(url);
let ext: string;
if (message.type == "image") {
// todo: 需要识别gif格式
ext = ".png"
}
if (message.type == "voice") {
if (message.type == "voice" || message.type == "record") {
message.type = "voice"
ext = ".amr"
}
let localFilePath = `${Date.now()}${ext}`
if (uri.protocol == "file:") {
localFilePath = url.split("file://")[1]
} else {
await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
localFilePath = await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
}
message.file = localFilePath
sendFiles.push(localFilePath);