mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
38 lines
818 B
TypeScript
38 lines
818 B
TypeScript
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 type MusicSignPostData = IdMusicSignPostData | CustomMusicSignPostData
|
|
|
|
export class MusicSign {
|
|
private readonly url: string
|
|
|
|
constructor(url: string) {
|
|
this.url = url
|
|
}
|
|
|
|
async sign(postData: MusicSignPostData): 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
|
|
}
|
|
}
|