mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
@@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "实现 OneBot 11 协议,用于 QQ 机器人开发",
|
"description": "实现 OneBot 11 协议,用于 QQ 机器人开发",
|
||||||
"version": "3.31.7",
|
"version": "3.31.8",
|
||||||
"icon": "./icon.webp",
|
"icon": "./icon.webp",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import fastXmlParser from 'fast-xml-parser'
|
import { XMLParser } from 'fast-xml-parser'
|
||||||
import {
|
import {
|
||||||
OB11Group,
|
OB11Group,
|
||||||
OB11GroupMember,
|
OB11GroupMember,
|
||||||
@@ -32,7 +32,6 @@ import { OB11GroupBanEvent } from './event/notice/OB11GroupBanEvent'
|
|||||||
import { OB11GroupUploadNoticeEvent } from './event/notice/OB11GroupUploadNoticeEvent'
|
import { OB11GroupUploadNoticeEvent } from './event/notice/OB11GroupUploadNoticeEvent'
|
||||||
import { OB11GroupNoticeEvent } from './event/notice/OB11GroupNoticeEvent'
|
import { OB11GroupNoticeEvent } from './event/notice/OB11GroupNoticeEvent'
|
||||||
import { calcQQLevel } from '../common/utils/misc'
|
import { calcQQLevel } from '../common/utils/misc'
|
||||||
import { getConfigUtil } from '../common/config'
|
|
||||||
import { OB11GroupTitleEvent } from './event/notice/OB11GroupTitleEvent'
|
import { OB11GroupTitleEvent } from './event/notice/OB11GroupTitleEvent'
|
||||||
import { OB11GroupCardEvent } from './event/notice/OB11GroupCardEvent'
|
import { OB11GroupCardEvent } from './event/notice/OB11GroupCardEvent'
|
||||||
import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'
|
import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'
|
||||||
@@ -47,14 +46,14 @@ import { omit, isNullable, pick } from 'cosmokit'
|
|||||||
import { Context } from 'cordis'
|
import { Context } from 'cordis'
|
||||||
import { selfInfo } from '@/common/globalVars'
|
import { selfInfo } from '@/common/globalVars'
|
||||||
import { pathToFileURL } from 'node:url'
|
import { pathToFileURL } from 'node:url'
|
||||||
|
import OneBot11Adapter from './adapter'
|
||||||
|
|
||||||
export namespace OB11Entities {
|
export namespace OB11Entities {
|
||||||
export async function message(ctx: Context, msg: RawMessage): Promise<OB11Message> {
|
export async function message(ctx: Context, msg: RawMessage): Promise<OB11Message> {
|
||||||
let config = getConfigUtil().getConfig()
|
|
||||||
const {
|
const {
|
||||||
debug,
|
debug,
|
||||||
ob11: { messagePostFormat },
|
messagePostFormat,
|
||||||
} = config
|
} = ctx.config as OneBot11Adapter.Config
|
||||||
const selfUin = selfInfo.uin
|
const selfUin = selfInfo.uin
|
||||||
const resMsg: OB11Message = {
|
const resMsg: OB11Message = {
|
||||||
self_id: parseInt(selfUin),
|
self_id: parseInt(selfUin),
|
||||||
@@ -96,10 +95,10 @@ export namespace OB11Entities {
|
|||||||
resMsg.sub_type = 'group'
|
resMsg.sub_type = 'group'
|
||||||
const ret = await ctx.ntMsgApi.getTempChatInfo(ChatType2.KCHATTYPETEMPC2CFROMGROUP, msg.senderUid)
|
const ret = await ctx.ntMsgApi.getTempChatInfo(ChatType2.KCHATTYPETEMPC2CFROMGROUP, msg.senderUid)
|
||||||
if (ret?.result === 0) {
|
if (ret?.result === 0) {
|
||||||
resMsg.group_id = parseInt(ret.tmpChatInfo!.groupCode)
|
resMsg.temp_source = Number(ret.tmpChatInfo?.groupCode)
|
||||||
resMsg.sender.nickname = ret.tmpChatInfo!.fromNick
|
resMsg.sender.nickname = ret.tmpChatInfo?.fromNick!
|
||||||
} else {
|
} else {
|
||||||
resMsg.group_id = 284840486 //兜底数据
|
resMsg.temp_source = 284840486 //兜底数据
|
||||||
resMsg.sender.nickname = '临时会话'
|
resMsg.sender.nickname = '临时会话'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -515,7 +514,7 @@ export namespace OB11Entities {
|
|||||||
// <url jp= \"\" msgseq=\"74711\" col=\"3\" txt=\"消息:\"/>
|
// <url jp= \"\" msgseq=\"74711\" col=\"3\" txt=\"消息:\"/>
|
||||||
// <face type=\"1\" id=\"76\"> </face>
|
// <face type=\"1\" id=\"76\"> </face>
|
||||||
// </gtip>",
|
// </gtip>",
|
||||||
const emojiLikeData = new fastXmlParser.XMLParser({
|
const emojiLikeData = new XMLParser({
|
||||||
ignoreAttributes: false,
|
ignoreAttributes: false,
|
||||||
attributeNamePrefix: '',
|
attributeNamePrefix: '',
|
||||||
}).parse(xmlElement.content)
|
}).parse(xmlElement.content)
|
||||||
|
@@ -93,6 +93,7 @@ export interface OB11Message {
|
|||||||
font: number
|
font: number
|
||||||
post_type?: EventType
|
post_type?: EventType
|
||||||
raw?: RawMessage
|
raw?: RawMessage
|
||||||
|
temp_source?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OB11ForwardMessage extends OB11Message {
|
export interface OB11ForwardMessage extends OB11Message {
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = '3.31.7'
|
export const version = '3.31.8'
|
||||||
|
Reference in New Issue
Block a user