mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: music card sign
This commit is contained in:
parent
f38e544815
commit
6ff49722d8
@ -52,6 +52,7 @@ export class ConfigUtil {
|
||||
autoDeleteFile: false,
|
||||
autoDeleteFileSecond: 60,
|
||||
enablePoke: false,
|
||||
musicSignUrl: '',
|
||||
}
|
||||
|
||||
if (!fs.existsSync(this.configPath)) {
|
||||
|
@ -28,6 +28,7 @@ export interface Config {
|
||||
autoDeleteFileSecond?: number
|
||||
ffmpeg?: string // ffmpeg路径
|
||||
enablePoke?: boolean
|
||||
musicSignUrl?: string
|
||||
}
|
||||
|
||||
export interface LLOneBotError {
|
||||
|
35
src/common/utils/sign.ts
Normal file
35
src/common/utils/sign.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { log } from './log'
|
||||
|
||||
export interface IdMusicSignPostData {
|
||||
type: 'qq' | '163'
|
||||
id: string | number
|
||||
}
|
||||
|
||||
export interface CustomMusicSignPostData {
|
||||
type: 'custom'
|
||||
url: string
|
||||
audio: string
|
||||
title: string
|
||||
image?: string
|
||||
singer?: string
|
||||
}
|
||||
|
||||
export class MusicSign {
|
||||
private readonly url: string
|
||||
|
||||
constructor(url: string) {
|
||||
this.url = url
|
||||
}
|
||||
|
||||
async sign(postData: CustomMusicSignPostData | IdMusicSignPostData): Promise<any> {
|
||||
const resp = await fetch(this.url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(postData),
|
||||
})
|
||||
if (!resp.ok) throw new Error(resp.statusText)
|
||||
const data = await resp.json()
|
||||
log('音乐消息生成成功', data)
|
||||
return data
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import {
|
||||
OB11MessageData,
|
||||
OB11MessageDataType,
|
||||
OB11MessageMixType,
|
||||
OB11MessageMusic,
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg,
|
||||
} from '../../types'
|
||||
@ -26,12 +27,13 @@ import { ActionName, BaseCheckResult } from '../types'
|
||||
import * as fs from 'node:fs'
|
||||
import { decodeCQCode } from '../../cqcode'
|
||||
import { dbUtil } from '../../../common/db'
|
||||
import { ALLOW_SEND_TEMP_MSG } from '../../../common/config'
|
||||
import { ALLOW_SEND_TEMP_MSG, getConfigUtil } from '../../../common/config'
|
||||
import { log } from '../../../common/utils/log'
|
||||
import { sleep } from '../../../common/utils/helper'
|
||||
import { uri2local } from '../../../common/utils'
|
||||
import { crychic } from '../../../ntqqapi/external/crychic'
|
||||
import { NTQQGroupApi } from '../../../ntqqapi/api'
|
||||
import { MusicSign } from '../../../common/utils/sign'
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
@ -376,16 +378,26 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
} else {
|
||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
||||
const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic
|
||||
const music = messages[0] as OB11MessageMusic
|
||||
if (music) {
|
||||
const { url, audio, title, content, image } = music.data
|
||||
const selfPeer: Peer = { peerUid: selfInfo.uid, chatType: ChatType.friend }
|
||||
// 搞不定!
|
||||
// const musicMsg = await this.send(selfPeer, [this.genMusicElement(url, audio, title, content, image)], [], false)
|
||||
// 转发
|
||||
// const res = await NTQQApi.forwardMsg(selfPeer, peer, [musicMsg.msgId])
|
||||
// log("转发音乐消息成功", res);
|
||||
// return {message_id: musicMsg.msgShortId}
|
||||
const { musicSignUrl } = getConfigUtil().getConfig()
|
||||
if (!musicSignUrl) {
|
||||
throw '音乐签名地址未配置'
|
||||
}
|
||||
const { type } = music.data
|
||||
if (!['qq', '163', 'custom'].includes(type)) {
|
||||
throw `不支持的音乐类型 ${type}`
|
||||
}
|
||||
let jsonContent: string
|
||||
try {
|
||||
jsonContent = await new MusicSign(musicSignUrl).sign(music.data)
|
||||
} catch (e) {
|
||||
throw `签名音乐消息失败:${e}`
|
||||
}
|
||||
messages[0] = {
|
||||
type: OB11MessageDataType.json,
|
||||
data: { data: jsonContent },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { PicSubType, RawMessage } from '../ntqqapi/types'
|
||||
import { EventType } from './event/OB11BaseEvent'
|
||||
import { IdMusicSignPostData, CustomMusicSignPostData } from '../common/utils/sign'
|
||||
|
||||
export interface OB11User {
|
||||
user_id: number
|
||||
@ -219,18 +220,18 @@ export interface OB11MessageNode {
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageIdMusic {
|
||||
type: OB11MessageDataType.music
|
||||
data: IdMusicSignPostData
|
||||
}
|
||||
|
||||
export interface OB11MessageCustomMusic {
|
||||
type: OB11MessageDataType.music
|
||||
data: {
|
||||
type: 'custom'
|
||||
url: string
|
||||
audio: string
|
||||
title: string
|
||||
content?: string
|
||||
image?: string
|
||||
}
|
||||
data: Omit<CustomMusicSignPostData, 'singer'> & { content?: string }
|
||||
}
|
||||
|
||||
export type OB11MessageMusic = OB11MessageIdMusic | OB11MessageCustomMusic
|
||||
|
||||
export interface OB11MessageJson {
|
||||
type: OB11MessageDataType.json
|
||||
data: { config: { token: string } } & any
|
||||
@ -247,6 +248,7 @@ export type OB11MessageData =
|
||||
| OB11MessageFile
|
||||
| OB11MessageVideo
|
||||
| OB11MessageNode
|
||||
| OB11MessageIdMusic
|
||||
| OB11MessageCustomMusic
|
||||
| OB11MessageJson
|
||||
| OB11MessagePoke
|
||||
|
@ -95,7 +95,9 @@ async function onSettingWindowCreated(view: Element) {
|
||||
<setting-text>HTTP 事件上报密钥</setting-text>
|
||||
</div>
|
||||
<div class="q-input">
|
||||
<input id="config-ob11-httpSecret" class="q-input__inner" data-config-key="ob11.httpSecret" type="text" value="${config.ob11.httpSecret}" placeholder="未设置" />
|
||||
<input id="config-ob11-httpSecret" class="q-input__inner" data-config-key="ob11.httpSecret" type="text" value="${
|
||||
config.ob11.httpSecret
|
||||
}" placeholder="未设置" />
|
||||
</div>
|
||||
</setting-item>
|
||||
<setting-item data-direction="row">
|
||||
@ -158,9 +160,17 @@ async function onSettingWindowCreated(view: Element) {
|
||||
),
|
||||
SettingItem(
|
||||
'ffmpeg 路径,发送语音、视频需要,同时保证ffprobe和ffmpeg在一起',
|
||||
` <a href="javascript:LiteLoader.api.openExternal(\'https://llonebot.github.io/zh-CN/guide/ffmpeg\');">下载地址</a> <span id="config-ffmpeg-path-text">, 路径:${!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'}</span>`,
|
||||
` <a href="javascript:LiteLoader.api.openExternal(\'https://llonebot.github.io/zh-CN/guide/ffmpeg\');">下载地址</a> <span id="config-ffmpeg-path-text">, 路径:${
|
||||
!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'
|
||||
}</span>`,
|
||||
SettingButton('选择ffmpeg', 'config-ffmpeg-select'),
|
||||
),
|
||||
SettingItem(
|
||||
'音乐卡片签名地址',
|
||||
null,
|
||||
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="musicSignUrl" type="text" value="${config.musicSignUrl}" placeholder="未设置" /></div>`,
|
||||
'config-musicSignUrl',
|
||||
),
|
||||
SettingItem('', null, SettingButton('保存', 'config-ob11-save', 'primary')),
|
||||
]),
|
||||
SettingList([
|
||||
|
Loading…
x
Reference in New Issue
Block a user