File size: 4,779 Bytes
af5a34b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
import _ from 'lodash'
import fs from 'fs'
import { Version } from '../components/index.js'
async function CreateMusicShare(data) {
let appid, appname, appsign, style = 4;
switch (data.subType) {
case 'bilibili':
appid = 100951776, appname = 'tv.danmaku.bili', appsign = '7194d531cbe7960a22007b9f6bdaa38b';
break;
case 'netease':
appid = 100495085, appname = "com.netease.cloudmusic", appsign = "da6b069da1e2982db3e386233f68d76d";
break;
case 'kuwo':
appid = 100243533, appname = "cn.kuwo.player", appsign = "bf9ff4ffb4c558a34ee3fd52c223ebf5";
break;
case 'kugou':
appid = 205141, appname = "com.kugou.android", appsign = "fe4a24d80fcf253a00676a808f62c2c6";
break;
case 'migu':
appid = 1101053067, appname = "cmccwm.mobilemusic", appsign = "6cdc72a439cef99a3418d2a78aa28c73";
break;
case 'qq':
default:
appid = 100497308, appname = "com.tencent.qqmusic", appsign = "cbd27cd7c861227d013a25b2d10f0799";
break;
}
var text = '', title = data.title, singer = data.content, prompt = '[分享]', jumpUrl = data.url, preview = data.image, musicUrl = data.voice;
prompt = '[分享]' + title + '-' + singer;
let recv_uin = 0;
let send_type = 0;
let recv_guild_id = 0;
if (data.message_type === 'group') {//群聊
recv_uin = data.group_id;
send_type = 1;
} else if (data.message_type === 'guild') {//频道
recv_uin = Number(data.channel_id);
recv_guild_id = BigInt(data.guild_id);
send_type = 3;
} else if (data.message_type === 'private') {//私聊
recv_uin = data.user_id;
send_type = 0;
}
let body = {
1: appid,
2: 1,
3: style,
5: {
1: 1,
2: "0.0.0",
3: appname,
4: appsign,
},
6: text,
10: send_type,
11: recv_uin,
12: {
10: title,
11: singer,
12: prompt,
13: jumpUrl,
14: preview,
16: musicUrl,
},
19: recv_guild_id
};
return body;
}
async function SendMusicShare(data) {
let core, bot
if (Version.isTrss) {
bot = Bot[data.bot_id]
core = bot?.core
} else {
bot = Bot
try {
core = (await import('oicq')).core
} catch (error) {
core = null
}
}
if (!core) {
const msg = [data.url]
if (data.message_type === 'group') {//群聊
await bot?.pickGroup?.(data.group_id)?.sendMsg?.(msg)
} else if (data.message_type === 'private') {//私聊
await bot?.pickFriend?.(data.user_id)?.sendMsg?.(msg)
}
return
}
try {
let body = await CreateMusicShare(data)
let payload = await bot.sendOidb("OidbSvc.0xb77_9", core.pb.encode(body));
let result = core.pb.decode(payload);
if (result[3] != 0) {
if (data.message_type === 'group') {//群聊
await bot?.pickGroup(data.group_id).sendMsg('歌曲分享失败:' + result[3])
} else if (data.message_type === 'private') {//私聊
await bot?.pickFriend(data.user_id).sendMsg('歌曲分享失败:' + result[3])
}
// e.reply('歌曲分享失败:' + result[3], true);
}
} catch (error) {
const msg = [data.url]
if (data.message_type === 'group') {//群聊
await bot?.pickGroup?.(data.group_id)?.sendMsg?.(msg)
} else if (data.message_type === 'private') {//私聊
await bot?.pickFriend?.(data.user_id)?.sendMsg?.(msg)
}
return
}
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
const TMP_DIR = process.cwd() + '/plugins/ws-plugin/Temp'
if (!fs.existsSync(TMP_DIR)) fs.mkdirSync(TMP_DIR)
const mimeTypes = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.gif': 'image/gif',
'.ico': 'image/x-icon',
'.txt': 'text/plain',
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
}
function decodeHtml(html) {
var map = {
'&': '&',
'[': '[',
']': ']',
',': ','
};
for (var key in map) {
const value = map[key];
const regex = new RegExp(key, 'g');
html = html.replace(regex, value);
}
return html;
}
export {
SendMusicShare,
sleep,
TMP_DIR,
mimeTypes,
decodeHtml
} |