onebots
Version:
基于icqq的多例oneBot实现
57 lines (56 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.shareMusic = shareMusic;
exports.buildMusic = buildMusic;
const message_1 = require("@icqqjs/icqq/lib/message");
const core_1 = require("@icqqjs/icqq/lib/core");
const process_1 = require("process");
/** 发送音乐分享(允许自定义参数) */
async function shareMusic(music) {
const body = await buildMusic((this.gid || this.uid), this.dm ? 0 : 1, music);
await this.c.sendOidb("OidbSvc.0xb77_9", core_1.pb.encode(body));
}
async function buildMusic(target, bu, music) {
const { appid, package_name, sign, getMusicInfo } = message_1.musicFactory[music.platform];
let style = 4;
try {
let { singer = null, title = null, jumpUrl = null, musicUrl = null, preview = null, } = music.id ? await getMusicInfo(music.id) : {};
singer = music["content"] || music.singer || singer; // 自定义参数优先级高于默认值(gocq的参数名与icqq有区别,做下兼容)
title = music.title || title;
jumpUrl = music.jumpUrl || music["url"] || jumpUrl;
musicUrl = music["voice"] || music["url"] || music.musicUrl || musicUrl;
preview = music["image"] || music.preview || preview;
if (!musicUrl)
style = 0;
return {
1: appid,
2: 1,
3: style,
5: {
1: 1,
2: "0.0.0",
3: package_name,
4: sign,
},
10: typeof bu === "string" ? 3 : bu,
11: target,
12: {
10: title,
11: singer,
12: "[分享]" + title,
13: jumpUrl,
14: preview,
16: musicUrl,
},
19: typeof bu === "string" ? Number(bu) : undefined,
};
}
catch (e) {
throw new Error("unknown music id: " +
music.id +
", in platform: " +
music.platform +
", with title: " +
process_1.title);
}
}