mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor
This commit is contained in:
parent
a7bb55b31c
commit
387c9dcb52
@ -38,7 +38,7 @@ export class ConfigUtil {
|
||||
}
|
||||
|
||||
reloadConfig(): Config {
|
||||
let ob11Default: OB11Config = {
|
||||
const ob11Default: OB11Config = {
|
||||
httpPort: 3000,
|
||||
httpHosts: [],
|
||||
httpSecret: '',
|
||||
@ -52,7 +52,7 @@ export class ConfigUtil {
|
||||
enableHttpHeart: false,
|
||||
enableQOAutoQuote: false
|
||||
}
|
||||
let defaultConfig: Config = {
|
||||
const defaultConfig: Config = {
|
||||
enableLLOB: true,
|
||||
ob11: ob11Default,
|
||||
heartInterval: 60000,
|
||||
@ -83,7 +83,6 @@ export class ConfigUtil {
|
||||
this.checkOldConfig(jsonData.ob11, jsonData, 'httpPort', 'http')
|
||||
this.checkOldConfig(jsonData.ob11, jsonData, 'httpHosts', 'hosts')
|
||||
this.checkOldConfig(jsonData.ob11, jsonData, 'wsPort', 'wsPort')
|
||||
// console.log("get config", jsonData);
|
||||
this.config = jsonData
|
||||
return this.config
|
||||
}
|
||||
@ -95,15 +94,15 @@ export class ConfigUtil {
|
||||
}
|
||||
|
||||
private checkOldConfig(
|
||||
currentConfig: Config | OB11Config,
|
||||
oldConfig: Config | OB11Config,
|
||||
currentKey: string,
|
||||
oldKey: string,
|
||||
currentConfig: OB11Config,
|
||||
oldConfig: Config,
|
||||
currentKey: 'httpPort' | 'httpHosts' | 'wsPort',
|
||||
oldKey: 'http' | 'hosts' | 'wsPort',
|
||||
) {
|
||||
// 迁移旧的配置到新配置,避免用户重新填写配置
|
||||
const oldValue = oldConfig[oldKey]
|
||||
if (oldValue) {
|
||||
currentConfig[currentKey] = oldValue
|
||||
currentConfig[currentKey] = oldValue as any
|
||||
delete oldConfig[oldKey]
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,12 @@ export interface Config {
|
||||
ignoreBeforeLoginMsg?: boolean
|
||||
/** 单位为秒 */
|
||||
msgCacheExpire?: number
|
||||
/** @deprecated */
|
||||
http?: string
|
||||
/** @deprecated */
|
||||
hosts?: string[]
|
||||
/** @deprecated */
|
||||
wsPort?: string
|
||||
}
|
||||
|
||||
export interface LLOneBotError {
|
||||
|
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
@ -4,4 +4,6 @@ import { Dict } from 'cosmokit'
|
||||
declare global {
|
||||
var llonebot: LLOneBot
|
||||
var LiteLoader: Dict
|
||||
var authData: Dict | undefined
|
||||
var navigation: Dict | undefined
|
||||
}
|
@ -22,7 +22,7 @@ import { encodeSilk } from '../common/utils/audio'
|
||||
import { Context } from 'cordis'
|
||||
import { isNullable } from 'cosmokit'
|
||||
|
||||
export const mFaceCache = new Map<string, string>() // emojiId -> faceName
|
||||
//export const mFaceCache = new Map<string, string>() // emojiId -> faceName
|
||||
|
||||
export namespace SendElementEntities {
|
||||
export function text(content: string): SendTextElement {
|
||||
@ -295,7 +295,7 @@ export namespace SendElementEntities {
|
||||
}
|
||||
}
|
||||
|
||||
export function mface(emojiPackageId: number, emojiId: string, key: string, faceName: string): SendMarketFaceElement {
|
||||
export function mface(emojiPackageId: number, emojiId: string, key: string, summary: string): SendMarketFaceElement {
|
||||
return {
|
||||
elementType: ElementType.MFACE,
|
||||
marketFaceElement: {
|
||||
@ -304,7 +304,7 @@ export namespace SendElementEntities {
|
||||
emojiPackageId,
|
||||
emojiId,
|
||||
key,
|
||||
faceName: faceName || mFaceCache.get(emojiId) || '[商城表情]',
|
||||
faceName: summary || '[商城表情]',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -108,10 +108,10 @@ interface InvokeOptions<ReturnType> {
|
||||
}
|
||||
|
||||
export function invoke<
|
||||
R extends Awaited<ReturnType<NTService[S][M] extends (...args: any) => any ? NTService[S][M] : any>>,
|
||||
R extends Awaited<ReturnType<Extract<NTService[S][M], (...args: any) => any>>>,
|
||||
S extends keyof NTService = any,
|
||||
M extends keyof NTService[S] & string = any
|
||||
>(method: `${unknown extends `${S}/${M}` ? `${S}/${M}` : string}`, args: unknown[], options: InvokeOptions<R> = {}) {
|
||||
>(method: Extract<unknown, `${S}/${M}`> | string, args: unknown[], options: InvokeOptions<R> = {}) {
|
||||
const className = options.className ?? NTClass.NT_API
|
||||
const channel = options.channel ?? NTChannel.IPC_UP_2
|
||||
const timeout = options.timeout ?? 5000
|
||||
|
@ -275,7 +275,7 @@ export interface PicElement {
|
||||
thumbPath: Map<number, string>
|
||||
picWidth: number
|
||||
picHeight: number
|
||||
fileSize: number
|
||||
fileSize: string
|
||||
fileName: string
|
||||
fileUuid: string
|
||||
md5HexStr?: string
|
||||
|
@ -11,7 +11,8 @@ import {
|
||||
NodeIKernelTipOffService,
|
||||
NodeIKernelSearchService
|
||||
} from './services'
|
||||
import os from 'node:os'
|
||||
import { constants } from 'node:os'
|
||||
import { Dict } from 'cosmokit'
|
||||
const Process = require('node:process')
|
||||
|
||||
export interface NodeIQQNTWrapperSession {
|
||||
@ -72,7 +73,7 @@ const constructor = [
|
||||
|
||||
Process.dlopenOrig = Process.dlopen
|
||||
|
||||
Process.dlopen = function (module, filename, flags = os.constants.dlopen.RTLD_LAZY) {
|
||||
Process.dlopen = function (module: Dict, filename: string, flags = constants.dlopen.RTLD_LAZY) {
|
||||
const dlopenRet = this.dlopenOrig(module, filename, flags)
|
||||
for (let export_name in module.exports) {
|
||||
module.exports[export_name] = new Proxy(module.exports[export_name], {
|
||||
|
@ -14,8 +14,8 @@ export default class Debug extends BaseAction<Payload, any> {
|
||||
const { ntMsgApi, ntFileApi, ntFileCacheApi, ntFriendApi, ntGroupApi, ntUserApi, ntWindowApi } = this.ctx
|
||||
const ntqqApi = [ntMsgApi, ntFriendApi, ntGroupApi, ntUserApi, ntFileApi, ntFileCacheApi, ntWindowApi]
|
||||
for (const ntqqApiClass of ntqqApi) {
|
||||
const method = ntqqApiClass[payload.method] as Function
|
||||
if (method) {
|
||||
const method = ntqqApiClass[payload.method as keyof typeof ntqqApiClass]
|
||||
if (method && method instanceof Function) {
|
||||
const result = method.apply(ntqqApiClass, payload.args)
|
||||
if (method.constructor.name === 'AsyncFunction') {
|
||||
return await result
|
||||
|
@ -8,7 +8,7 @@ interface ReturnType {
|
||||
export default class CanSendRecord extends BaseAction<any, ReturnType> {
|
||||
actionName = ActionName.CanSendRecord
|
||||
|
||||
protected async _handle(payload): Promise<ReturnType> {
|
||||
protected async _handle(payload: void): Promise<ReturnType> {
|
||||
return {
|
||||
yes: true,
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import { OB11Message } from '../types'
|
||||
import { OB11BaseEvent } from '../event/OB11BaseEvent'
|
||||
import { handleQuickOperation, QuickOperationEvent } from '../helper/quickOperation'
|
||||
import { OB11HeartbeatEvent } from '../event/meta/OB11HeartbeatEvent'
|
||||
import { Dict } from 'cosmokit'
|
||||
|
||||
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
||||
|
||||
@ -159,7 +160,7 @@ class OB11HttpPost {
|
||||
|
||||
public async emitEvent(event: OB11BaseEvent | OB11Message) {
|
||||
const msgStr = JSON.stringify(event)
|
||||
const headers = {
|
||||
const headers: Dict = {
|
||||
'Content-Type': 'application/json',
|
||||
'x-self-id': selfInfo.uin,
|
||||
}
|
||||
|
@ -70,8 +70,8 @@ class OB11WebSocket {
|
||||
return
|
||||
}
|
||||
socket.send(JSON.stringify(data))
|
||||
if (data['post_type']) {
|
||||
this.ctx.logger.info('WebSocket 事件上报', socket.url ?? '', data['post_type'])
|
||||
if ('post_type' in data) {
|
||||
this.ctx.logger.info('WebSocket 事件上报', socket.url ?? '', data.post_type)
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,8 +192,8 @@ class OB11WebSocketReverse {
|
||||
return
|
||||
}
|
||||
socket.send(JSON.stringify(data))
|
||||
if (data['post_type']) {
|
||||
this.ctx.logger.info('WebSocket 事件上报', socket.url ?? '', data['post_type'])
|
||||
if ('post_type' in data) {
|
||||
this.ctx.logger.info('WebSocket 事件上报', socket.url ?? '', data.post_type)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ export function decodeCQCode(source: string): OB11MessageData[] {
|
||||
return elements
|
||||
}
|
||||
|
||||
export function encodeCQCode(data: OB11MessageData) {
|
||||
export function encodeCQCode(input: OB11MessageData) {
|
||||
const CQCodeEscapeText = (text: string) => {
|
||||
return text.replace(/\&/g, '&').replace(/\[/g, '[').replace(/\]/g, ']')
|
||||
}
|
||||
@ -53,21 +53,20 @@ export function encodeCQCode(data: OB11MessageData) {
|
||||
return text.replace(/\&/g, '&').replace(/\[/g, '[').replace(/\]/g, ']').replace(/,/g, ',')
|
||||
}
|
||||
|
||||
if (data.type === 'text') {
|
||||
return CQCodeEscapeText(data.data.text)
|
||||
if (input.type === 'text') {
|
||||
return CQCodeEscapeText(input.data.text)
|
||||
}
|
||||
|
||||
let result = '[CQ:' + data.type
|
||||
for (const name in data.data) {
|
||||
const value = data.data[name]
|
||||
let result = '[CQ:' + input.type
|
||||
for (const [key, value] of Object.entries(input.data)) {
|
||||
if (value === undefined) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
const text = value.toString()
|
||||
result += `,${name}=${CQCodeEscape(text)}`
|
||||
result += `,${key}=${CQCodeEscape(text)}`
|
||||
} catch (error) {
|
||||
// If it can't be converted, skip this name-value pair
|
||||
// If it can't be converted, skip this key-value pair
|
||||
}
|
||||
}
|
||||
result += ']'
|
||||
|
@ -37,7 +37,6 @@ import { OB11GroupTitleEvent } from './event/notice/OB11GroupTitleEvent'
|
||||
import { OB11GroupCardEvent } from './event/notice/OB11GroupCardEvent'
|
||||
import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'
|
||||
import { OB11GroupMsgEmojiLikeEvent } from './event/notice/OB11MsgEmojiLikeEvent'
|
||||
import { mFaceCache } from '../ntqqapi/entities'
|
||||
import { OB11FriendAddNoticeEvent } from './event/notice/OB11FriendAddNoticeEvent'
|
||||
import { OB11FriendRecallNoticeEvent } from './event/notice/OB11FriendRecallNoticeEvent'
|
||||
import { OB11GroupRecallNoticeEvent } from './event/notice/OB11GroupRecallNoticeEvent'
|
||||
@ -47,6 +46,7 @@ import { OB11GroupEssenceEvent } from './event/notice/OB11GroupEssenceEvent'
|
||||
import { omit, isNullable } from 'cosmokit'
|
||||
import { Context } from 'cordis'
|
||||
import { selfInfo } from '@/common/globalVars'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
export namespace OB11Entities {
|
||||
export async function message(ctx: Context, msg: RawMessage): Promise<OB11Message> {
|
||||
@ -105,10 +105,7 @@ export namespace OB11Entities {
|
||||
}
|
||||
|
||||
for (let element of msg.elements) {
|
||||
let message_data: OB11MessageData = {
|
||||
data: {} as any,
|
||||
type: 'unknown' as any,
|
||||
}
|
||||
let messageSegment: OB11MessageData | undefined
|
||||
if (element.textElement && element.textElement?.atType !== AtType.notAt) {
|
||||
let qq: string
|
||||
let name: string | undefined
|
||||
@ -129,7 +126,7 @@ export namespace OB11Entities {
|
||||
name = content.replace('@', '')
|
||||
}
|
||||
}
|
||||
message_data = {
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.at,
|
||||
data: {
|
||||
qq: qq!,
|
||||
@ -138,12 +135,16 @@ export namespace OB11Entities {
|
||||
}
|
||||
}
|
||||
else if (element.textElement) {
|
||||
message_data['type'] = OB11MessageDataType.text
|
||||
let text = element.textElement.content
|
||||
const text = element.textElement.content
|
||||
if (!text.trim()) {
|
||||
continue
|
||||
}
|
||||
message_data['data']['text'] = text
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.text,
|
||||
data: {
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element.replyElement) {
|
||||
const { replyElement } = element
|
||||
@ -163,7 +164,7 @@ export namespace OB11Entities {
|
||||
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') {
|
||||
throw new Error('回复消息消息验证失败')
|
||||
}
|
||||
message_data = {
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.reply,
|
||||
data: {
|
||||
id: MessageUnique.createMsg(peer, replyMsg ? replyMsg.msgId : records.msgId).toString()
|
||||
@ -175,18 +176,17 @@ export namespace OB11Entities {
|
||||
}
|
||||
}
|
||||
else if (element.picElement) {
|
||||
message_data['type'] = OB11MessageDataType.image
|
||||
const { picElement } = element
|
||||
/*let fileName = picElement.fileName
|
||||
const isGif = picElement.picType === PicType.gif
|
||||
if (isGif && !fileName.endsWith('.gif')) {
|
||||
fileName += '.gif'
|
||||
}*/
|
||||
message_data['data']['file'] = picElement.fileName
|
||||
message_data['data']['subType'] = picElement.picSubType
|
||||
//message_data['data']['file_id'] = picElement.fileUuid
|
||||
message_data['data']['url'] = await ctx.ntFileApi.getImageUrl(picElement)
|
||||
message_data['data']['file_size'] = picElement.fileSize
|
||||
const fileSize = picElement.fileSize ?? '0'
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.image,
|
||||
data: {
|
||||
file: picElement.fileName,
|
||||
subType: picElement.picSubType,
|
||||
url: await ctx.ntFileApi.getImageUrl(picElement),
|
||||
file_size: fileSize,
|
||||
}
|
||||
}
|
||||
MessageUnique.addFileCache({
|
||||
peerUid: msg.peerUid,
|
||||
msgId: msg.msgId,
|
||||
@ -195,21 +195,26 @@ export namespace OB11Entities {
|
||||
elementId: element.elementId,
|
||||
elementType: element.elementType,
|
||||
fileName: picElement.fileName,
|
||||
fileSize: String(picElement.fileSize || '0'),
|
||||
fileUuid: picElement.fileUuid
|
||||
fileUuid: picElement.fileUuid,
|
||||
fileSize,
|
||||
})
|
||||
}
|
||||
else if (element.videoElement) {
|
||||
message_data['type'] = OB11MessageDataType.video
|
||||
const { videoElement } = element
|
||||
message_data['data']['file'] = videoElement.fileName
|
||||
message_data['data']['path'] = videoElement.filePath
|
||||
//message_data['data']['file_id'] = videoElement.fileUuid
|
||||
message_data['data']['file_size'] = videoElement.fileSize
|
||||
message_data['data']['url'] = await ctx.ntFileApi.getVideoUrl({
|
||||
const videoUrl = await ctx.ntFileApi.getVideoUrl({
|
||||
chatType: msg.chatType,
|
||||
peerUid: msg.peerUid,
|
||||
}, msg.msgId, element.elementId)
|
||||
const fileSize = videoElement.fileSize ?? '0'
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.video,
|
||||
data: {
|
||||
file: videoElement.fileName,
|
||||
url: videoUrl || pathToFileURL(videoElement.filePath).href,
|
||||
path: videoElement.filePath,
|
||||
file_size: fileSize,
|
||||
}
|
||||
}
|
||||
MessageUnique.addFileCache({
|
||||
peerUid: msg.peerUid,
|
||||
msgId: msg.msgId,
|
||||
@ -218,17 +223,23 @@ export namespace OB11Entities {
|
||||
elementId: element.elementId,
|
||||
elementType: element.elementType,
|
||||
fileName: videoElement.fileName,
|
||||
fileSize: String(videoElement.fileSize || '0'),
|
||||
fileUuid: videoElement.fileUuid!
|
||||
fileUuid: videoElement.fileUuid!,
|
||||
fileSize,
|
||||
})
|
||||
}
|
||||
else if (element.fileElement) {
|
||||
message_data['type'] = OB11MessageDataType.file
|
||||
const { fileElement } = element
|
||||
message_data['data']['file'] = fileElement.fileName
|
||||
message_data['data']['path'] = fileElement.filePath
|
||||
message_data['data']['file_id'] = fileElement.fileUuid
|
||||
message_data['data']['file_size'] = fileElement.fileSize
|
||||
const fileSize = fileElement.fileSize ?? '0'
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.file,
|
||||
data: {
|
||||
file: fileElement.fileName,
|
||||
url: pathToFileURL(fileElement.filePath).href,
|
||||
file_id: fileElement.fileUuid,
|
||||
path: fileElement.filePath,
|
||||
file_size: fileSize,
|
||||
}
|
||||
}
|
||||
MessageUnique.addFileCache({
|
||||
peerUid: msg.peerUid,
|
||||
msgId: msg.msgId,
|
||||
@ -237,17 +248,22 @@ export namespace OB11Entities {
|
||||
elementId: element.elementId,
|
||||
elementType: element.elementType,
|
||||
fileName: fileElement.fileName,
|
||||
fileSize: String(fileElement.fileSize || '0'),
|
||||
fileUuid: fileElement.fileUuid!
|
||||
fileUuid: fileElement.fileUuid!,
|
||||
fileSize,
|
||||
})
|
||||
}
|
||||
else if (element.pttElement) {
|
||||
message_data['type'] = OB11MessageDataType.voice
|
||||
const { pttElement } = element
|
||||
message_data['data']['file'] = pttElement.fileName
|
||||
message_data['data']['path'] = pttElement.filePath
|
||||
//message_data['data']['file_id'] = pttElement.fileUuid
|
||||
message_data['data']['file_size'] = pttElement.fileSize
|
||||
const fileSize = pttElement.fileSize ?? '0'
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.voice,
|
||||
data: {
|
||||
file: pttElement.fileName,
|
||||
url: pathToFileURL(pttElement.filePath).href,
|
||||
path: pttElement.filePath,
|
||||
file_size: fileSize,
|
||||
}
|
||||
}
|
||||
MessageUnique.addFileCache({
|
||||
peerUid: msg.peerUid,
|
||||
msgId: msg.msgId,
|
||||
@ -256,59 +272,91 @@ export namespace OB11Entities {
|
||||
elementId: element.elementId,
|
||||
elementType: element.elementType,
|
||||
fileName: pttElement.fileName,
|
||||
fileSize: String(pttElement.fileSize || '0'),
|
||||
fileUuid: pttElement.fileUuid
|
||||
fileUuid: pttElement.fileUuid,
|
||||
fileSize,
|
||||
})
|
||||
}
|
||||
else if (element.arkElement) {
|
||||
message_data['type'] = OB11MessageDataType.json
|
||||
message_data['data']['data'] = element.arkElement.bytesData
|
||||
const { arkElement } = element
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.json,
|
||||
data: {
|
||||
data: arkElement.bytesData
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element.faceElement) {
|
||||
const faceId = element.faceElement.faceIndex
|
||||
const { faceElement } = element
|
||||
const faceId = faceElement.faceIndex
|
||||
if (faceId === FaceIndex.dice) {
|
||||
message_data['type'] = OB11MessageDataType.dice
|
||||
message_data['data']['result'] = element.faceElement.resultId
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.dice,
|
||||
data: {
|
||||
result: faceElement.resultId!
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (faceId === FaceIndex.RPS) {
|
||||
message_data['type'] = OB11MessageDataType.RPS
|
||||
message_data['data']['result'] = element.faceElement.resultId
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.RPS,
|
||||
data: {
|
||||
result: faceElement.resultId!
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
message_data['type'] = OB11MessageDataType.face
|
||||
message_data['data']['id'] = element.faceElement.faceIndex.toString()
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.face,
|
||||
data: {
|
||||
id: faceId.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element.marketFaceElement) {
|
||||
message_data['type'] = OB11MessageDataType.mface
|
||||
message_data['data']['summary'] = element.marketFaceElement.faceName
|
||||
const md5 = element.marketFaceElement.emojiId
|
||||
const { marketFaceElement } = element
|
||||
const { emojiId } = marketFaceElement
|
||||
// 取md5的前两位
|
||||
const dir = md5.substring(0, 2)
|
||||
const dir = emojiId.substring(0, 2)
|
||||
// 获取组装url
|
||||
// const url = `https://p.qpic.cn/CDN_STATIC/0/data/imgcache/htdocs/club/item/parcel/item/${dir}/${md5}/300x300.gif?max_age=31536000`
|
||||
const url = `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${md5}/raw300.gif`
|
||||
message_data['data']['url'] = url
|
||||
message_data['data']['emoji_id'] = element.marketFaceElement.emojiId
|
||||
message_data['data']['emoji_package_id'] = String(element.marketFaceElement.emojiPackageId)
|
||||
message_data['data']['key'] = element.marketFaceElement.key
|
||||
mFaceCache.set(md5, element.marketFaceElement.faceName!)
|
||||
const url = `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${emojiId}/raw300.gif`
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.mface,
|
||||
data: {
|
||||
summary: marketFaceElement.faceName!,
|
||||
url,
|
||||
emoji_id: emojiId,
|
||||
emoji_package_id: marketFaceElement.emojiPackageId,
|
||||
key: marketFaceElement.key
|
||||
}
|
||||
}
|
||||
//mFaceCache.set(emojiId, element.marketFaceElement.faceName!)
|
||||
}
|
||||
else if (element.markdownElement) {
|
||||
message_data['type'] = OB11MessageDataType.markdown
|
||||
message_data['data']['data'] = element.markdownElement.content
|
||||
const { markdownElement } = element
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.markdown,
|
||||
data: {
|
||||
data: markdownElement.content
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element.multiForwardMsgElement) {
|
||||
message_data['type'] = OB11MessageDataType.forward
|
||||
message_data['data']['id'] = msg.msgId
|
||||
messageSegment = {
|
||||
type: OB11MessageDataType.forward,
|
||||
data: {
|
||||
id: msg.msgId
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((message_data.type as string) !== 'unknown' && message_data.data) {
|
||||
const cqCode = encodeCQCode(message_data)
|
||||
if (messageSegment) {
|
||||
const cqCode = encodeCQCode(messageSegment)
|
||||
if (messagePostFormat === 'string') {
|
||||
(resMsg.message as string) += cqCode
|
||||
} else {
|
||||
(resMsg.message as OB11MessageData[]).push(messageSegment)
|
||||
}
|
||||
else (resMsg.message as OB11MessageData[]).push(message_data)
|
||||
|
||||
resMsg.raw_message += cqCode
|
||||
}
|
||||
}
|
||||
|
@ -133,20 +133,21 @@ export interface OB11MessageMFace {
|
||||
emoji_package_id: number
|
||||
emoji_id: string
|
||||
key: string
|
||||
summary: string
|
||||
summary?: string
|
||||
url?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageDice {
|
||||
type: OB11MessageDataType.dice
|
||||
data: {
|
||||
result: number
|
||||
result: number /* intended */ | string /* in fact */
|
||||
}
|
||||
}
|
||||
export interface OB11MessageRPS {
|
||||
type: OB11MessageDataType.RPS
|
||||
data: {
|
||||
result: number
|
||||
result: number | string
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,6 +172,7 @@ export interface OB11MessageFileBase {
|
||||
name?: string
|
||||
file: string
|
||||
url?: string
|
||||
file_size?: string //扩展
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,14 +186,24 @@ export interface OB11MessageImage extends OB11MessageFileBase {
|
||||
|
||||
export interface OB11MessageRecord extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.voice
|
||||
data: OB11MessageFileBase['data'] & {
|
||||
path?: string //扩展
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageFile extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.file
|
||||
data: OB11MessageFileBase['data'] & {
|
||||
file_id?: string
|
||||
path?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageVideo extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.video
|
||||
data: OB11MessageFileBase['data'] & {
|
||||
path?: string //扩展
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageAt {
|
||||
|
@ -1,8 +1,10 @@
|
||||
import { CheckVersion } from '../common/types'
|
||||
import { CheckVersion, Config } from '../common/types'
|
||||
import { SettingButton, SettingItem, SettingList, SettingSwitch, SettingSelect } from './components'
|
||||
import { version } from '../version'
|
||||
// @ts-ignore
|
||||
import StyleRaw from './style.css?raw'
|
||||
import { version } from '../version'
|
||||
|
||||
type HostsType = 'httpHosts' | 'wsHosts'
|
||||
|
||||
function isEmpty(value: unknown) {
|
||||
return value === undefined || value === null || value === ''
|
||||
@ -10,17 +12,20 @@ function isEmpty(value: unknown) {
|
||||
|
||||
async function onSettingWindowCreated(view: Element) {
|
||||
//window.llonebot.log('setting window created')
|
||||
let config = await window.llonebot.getConfig()
|
||||
let ob11Config = { ...config.ob11 }
|
||||
const config = await window.llonebot.getConfig()
|
||||
const ob11Config = { ...config.ob11 }
|
||||
|
||||
const setConfig = (key: string, value: any) => {
|
||||
const configKey = key.split('.')
|
||||
if (key.indexOf('ob11') === 0) {
|
||||
if (configKey.length === 2) ob11Config[configKey[1]] = value
|
||||
else ob11Config[key] = value
|
||||
if (key.startsWith('ob11')) {
|
||||
if (configKey.length === 2) Object.assign(ob11Config, { [configKey[1]]: value })
|
||||
else Object.assign(ob11Config, { [key]: value })
|
||||
} else {
|
||||
if (configKey.length === 2) config[configKey[0]][configKey[1]] = value
|
||||
else config[key] = value
|
||||
if (configKey.length === 2) {
|
||||
Object.assign(config[configKey[0] as keyof Config[keyof Config]], { [configKey[1]]: value })
|
||||
} else {
|
||||
Object.assign(config, { [key]: value })
|
||||
}
|
||||
if (!['heartInterval', 'token', 'ffmpeg'].includes(key)) {
|
||||
window.llonebot.setConfig(false, config)
|
||||
}
|
||||
@ -244,7 +249,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
window.LiteLoader.api.openExternal('https://llonebot.github.io/')
|
||||
})
|
||||
// 生成反向地址列表
|
||||
const buildHostListItem = (type: string, host: string, index: number, inputAttrs: any = {}) => {
|
||||
const buildHostListItem = (type: HostsType, host: string, index: number, inputAttrs: any = {}) => {
|
||||
const dom = {
|
||||
container: document.createElement('setting-item'),
|
||||
input: document.createElement('input'),
|
||||
@ -276,7 +281,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
|
||||
return dom.container
|
||||
}
|
||||
const buildHostList = (hosts: string[], type: string, inputAttr: any = {}) => {
|
||||
const buildHostList = (hosts: string[], type: HostsType, inputAttr: any = {}) => {
|
||||
const result: HTMLElement[] = []
|
||||
|
||||
hosts.forEach((host, index) => {
|
||||
@ -285,12 +290,12 @@ async function onSettingWindowCreated(view: Element) {
|
||||
|
||||
return result
|
||||
}
|
||||
const addReverseHost = (type: string, doc: Document = document, inputAttr: any = {}) => {
|
||||
const addReverseHost = (type: HostsType, doc: Document = document, inputAttr: any = {}) => {
|
||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`)
|
||||
hostContainerDom?.appendChild(buildHostListItem(type, '', ob11Config[type].length, inputAttr))
|
||||
ob11Config[type].push('')
|
||||
}
|
||||
const initReverseHost = (type: string, doc: Document = document) => {
|
||||
const initReverseHost = (type: HostsType, doc: Document = document) => {
|
||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`)
|
||||
;[...hostContainerDom?.childNodes!].forEach((dom) => dom.remove())
|
||||
buildHostList(ob11Config[type], type).forEach((dom) => {
|
||||
@ -431,7 +436,7 @@ function init() {
|
||||
}
|
||||
|
||||
if (location.hash === '#/blank') {
|
||||
globalThis.navigation.addEventListener('navigatesuccess', init, { once: true })
|
||||
globalThis.navigation?.addEventListener('navigatesuccess', init, { once: true })
|
||||
} else {
|
||||
init()
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "commonjs",
|
||||
"module": "CommonJS",
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"experimentalDecorators": true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user