mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
optimize
This commit is contained in:
@@ -3,7 +3,6 @@ import ffmpeg from 'fluent-ffmpeg'
|
|||||||
import fsPromise from 'node:fs/promises'
|
import fsPromise from 'node:fs/promises'
|
||||||
import { decode, encode, getDuration, getWavFileInfo, isWav, isSilk, EncodeResult } from 'silk-wasm'
|
import { decode, encode, getDuration, getWavFileInfo, isWav, isSilk, EncodeResult } from 'silk-wasm'
|
||||||
import { TEMP_DIR } from '../globalVars'
|
import { TEMP_DIR } from '../globalVars'
|
||||||
import { getConfigUtil } from '../config'
|
|
||||||
import { randomUUID } from 'node:crypto'
|
import { randomUUID } from 'node:crypto'
|
||||||
import { Readable } from 'node:stream'
|
import { Readable } from 'node:stream'
|
||||||
import { Context } from 'cordis'
|
import { Context } from 'cordis'
|
||||||
@@ -38,7 +37,7 @@ function convert(ctx: Context, input: Input, options: FFmpegOptions, outputPath?
|
|||||||
if (options.output) {
|
if (options.output) {
|
||||||
command = command.outputOptions(options.output)
|
command = command.outputOptions(options.output)
|
||||||
}
|
}
|
||||||
const ffmpegPath = getConfigUtil().getConfig().ffmpeg
|
const ffmpegPath: string | undefined = ctx.config.ffmpeg
|
||||||
if (ffmpegPath) {
|
if (ffmpegPath) {
|
||||||
command = command.setFfmpegPath(ffmpegPath)
|
command = command.setFfmpegPath(ffmpegPath)
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -175,6 +175,9 @@ function onLoad() {
|
|||||||
debug: config.debug!,
|
debug: config.debug!,
|
||||||
reportSelfMessage: config.reportSelfMessage!,
|
reportSelfMessage: config.reportSelfMessage!,
|
||||||
msgCacheExpire: config.msgCacheExpire!,
|
msgCacheExpire: config.msgCacheExpire!,
|
||||||
|
musicSignUrl: config.musicSignUrl,
|
||||||
|
enableLocalFile2Url: config.enableLocalFile2Url!,
|
||||||
|
ffmpeg: config.ffmpeg,
|
||||||
})
|
})
|
||||||
ctx.start()
|
ctx.start()
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG_CONFIRMED, (event, config: LLOBConfig) => {
|
ipcMain.on(CHANNEL_SET_CONFIG_CONFIRMED, (event, config: LLOBConfig) => {
|
||||||
|
@@ -52,6 +52,9 @@ class Core extends Service {
|
|||||||
MessageUnique.init(selfInfo.uin)
|
MessageUnique.init(selfInfo.uin)
|
||||||
this.registerListener()
|
this.registerListener()
|
||||||
this.ctx.logger.info(`LLOneBot/${version}`)
|
this.ctx.logger.info(`LLOneBot/${version}`)
|
||||||
|
this.ctx.on('llonebot/config-updated', input => {
|
||||||
|
Object.assign(this.config, input)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerListener() {
|
private registerListener() {
|
||||||
|
@@ -147,7 +147,7 @@ export namespace SendElementEntities {
|
|||||||
filePath,
|
filePath,
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
videoInfo = await getVideoInfo(path)
|
videoInfo = await getVideoInfo(ctx, path)
|
||||||
ctx.logger.info('视频信息', videoInfo)
|
ctx.logger.info('视频信息', videoInfo)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ctx.logger.info('获取视频信息失败', e)
|
ctx.logger.info('获取视频信息失败', e)
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import fsPromise from 'node:fs/promises'
|
import fsPromise from 'node:fs/promises'
|
||||||
import { getConfigUtil } from '@/common/config'
|
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { Peer, ElementType } from '@/ntqqapi/types'
|
import { Peer, ElementType } from '@/ntqqapi/types'
|
||||||
import { MessageUnique } from '@/common/utils/messageUnique'
|
import { MessageUnique } from '@/common/utils/messageUnique'
|
||||||
@@ -20,7 +19,7 @@ export interface GetFileResponse {
|
|||||||
export abstract class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
export abstract class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||||
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/onebot11/action/file/GetFile.ts#L44
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/onebot11/action/file/GetFile.ts#L44
|
||||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||||
const { enableLocalFile2Url } = getConfigUtil().getConfig()
|
const { enableLocalFile2Url } = this.adapter.config
|
||||||
|
|
||||||
let fileCache = await MessageUnique.getFileCacheById(String(payload.file))
|
let fileCache = await MessageUnique.getFileCacheById(String(payload.file))
|
||||||
if (!fileCache?.length) {
|
if (!fileCache?.length) {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile'
|
import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { decodeSilk } from '@/common/utils/audio'
|
import { decodeSilk } from '@/common/utils/audio'
|
||||||
import { getConfigUtil } from '@/common/config'
|
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ export default class GetRecord extends GetFileBase {
|
|||||||
res.file = await decodeSilk(this.ctx, res.file!, payload.out_format)
|
res.file = await decodeSilk(this.ctx, res.file!, payload.out_format)
|
||||||
res.file_name = path.basename(res.file)
|
res.file_name = path.basename(res.file)
|
||||||
res.file_size = fs.statSync(res.file).size.toString()
|
res.file_size = fs.statSync(res.file).size.toString()
|
||||||
if (getConfigUtil().getConfig().enableLocalFile2Url) {
|
if (this.adapter.config.enableLocalFile2Url) {
|
||||||
res.base64 = fs.readFileSync(res.file, 'base64')
|
res.base64 = fs.readFileSync(res.file, 'base64')
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
@@ -13,10 +13,9 @@ import {
|
|||||||
OB11MessageNode,
|
OB11MessageNode,
|
||||||
OB11PostSendMsg,
|
OB11PostSendMsg,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
|
import fs from 'node:fs'
|
||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { ActionName, BaseCheckResult } from '../types'
|
import { ActionName, BaseCheckResult } from '../types'
|
||||||
import fs from 'node:fs'
|
|
||||||
import { getConfigUtil } from '@/common/config'
|
|
||||||
import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '@/common/utils/sign'
|
import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '@/common/utils/sign'
|
||||||
import { Peer } from '@/ntqqapi/types/msg'
|
import { Peer } from '@/ntqqapi/types/msg'
|
||||||
import { MessageUnique } from '@/common/utils/messageUnique'
|
import { MessageUnique } from '@/common/utils/messageUnique'
|
||||||
@@ -76,7 +75,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
|
|||||||
else if (this.getSpecialMsgNum(messages, OB11MessageDataType.music)) {
|
else if (this.getSpecialMsgNum(messages, OB11MessageDataType.music)) {
|
||||||
const music = messages[0] as OB11MessageMusic
|
const music = messages[0] as OB11MessageMusic
|
||||||
if (music) {
|
if (music) {
|
||||||
const { musicSignUrl } = getConfigUtil().getConfig()
|
const { musicSignUrl } = this.adapter.config
|
||||||
if (!musicSignUrl) {
|
if (!musicSignUrl) {
|
||||||
throw '音乐签名地址未配置'
|
throw '音乐签名地址未配置'
|
||||||
}
|
}
|
||||||
|
@@ -342,10 +342,13 @@ class OneBot11Adapter extends Service {
|
|||||||
Object.assign(this.config, {
|
Object.assign(this.config, {
|
||||||
...config.ob11,
|
...config.ob11,
|
||||||
heartInterval: config.heartInterval,
|
heartInterval: config.heartInterval,
|
||||||
token: config.token!,
|
token: config.token,
|
||||||
debug: config.debug!,
|
debug: config.debug,
|
||||||
reportSelfMessage: config.reportSelfMessage!,
|
reportSelfMessage: config.reportSelfMessage,
|
||||||
msgCacheExpire: config.msgCacheExpire!,
|
msgCacheExpire: config.msgCacheExpire,
|
||||||
|
musicSignUrl: config.musicSignUrl,
|
||||||
|
enableLocalFile2Url: config.enableLocalFile2Url,
|
||||||
|
ffmpeg: config.ffmpeg
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,6 +420,9 @@ namespace OneBot11Adapter {
|
|||||||
debug: boolean
|
debug: boolean
|
||||||
reportSelfMessage: boolean
|
reportSelfMessage: boolean
|
||||||
msgCacheExpire: number
|
msgCacheExpire: number
|
||||||
|
musicSignUrl?: string
|
||||||
|
enableLocalFile2Url: boolean
|
||||||
|
ffmpeg?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user