mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🦄 reactor: 仅优化结构,后续易于维护
This commit is contained in:
parent
8d6152e8ef
commit
d7c23f2089
197
apps/tools.js
197
apps/tools.js
@ -1445,38 +1445,34 @@ export class tools extends plugin {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网易云登录状态
|
// 网易云登录状态
|
||||||
async neteaseStatus(e, reck) {
|
async neteaseStatus(e, reck) {
|
||||||
// 优先判断是否使用自建 API
|
// 优先判断是否使用自建 API
|
||||||
let autoSelectNeteaseApi
|
let autoSelectNeteaseApi = this.useLocalNeteaseAPI ? this.neteaseCloudAPIServer : (await this.isOverseasServer() ? NETEASE_SONG_DOWNLOAD : NETEASE_API_CN);
|
||||||
// 判断海外
|
const statusUrl = `${autoSelectNeteaseApi}/login/status`;
|
||||||
const isOversea = await this.isOverseasServer();
|
|
||||||
if (this.useLocalNeteaseAPI) {
|
try {
|
||||||
// 使用自建 API
|
const statusResponse = await axios.get(statusUrl, {
|
||||||
autoSelectNeteaseApi = this.neteaseCloudAPIServer
|
headers: {
|
||||||
} else {
|
"User-Agent": COMMON_USER_AGENT,
|
||||||
// 自动选择 API
|
"Cookie": reck ? reck : this.neteaseCookie,
|
||||||
autoSelectNeteaseApi = isOversea ? NETEASE_SONG_DOWNLOAD : NETEASE_API_CN;
|
},
|
||||||
|
});
|
||||||
|
const userInfo = statusResponse.data?.data?.profile;
|
||||||
|
if (!userInfo) {
|
||||||
|
e.reply('暂未登录,请发 #RNQ 或者 #rnq 进行登陆绑定ck');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const statusUrl = autoSelectNeteaseApi + '/login/status'
|
|
||||||
axios.get(statusUrl, {
|
const vipResponse = await axios.get(`${autoSelectNeteaseApi}/vip/info?uid=${userInfo.userId}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": COMMON_USER_AGENT,
|
"User-Agent": COMMON_USER_AGENT,
|
||||||
"Cookie": reck ? reck : this.neteaseCookie
|
"Cookie": reck ? reck : this.neteaseCookie,
|
||||||
},
|
},
|
||||||
}).then(res => {
|
});
|
||||||
// logger.info('登录状态', res.data)
|
const vipInfo = vipResponse.data?.data;
|
||||||
const userInfo = res.data.data.profile
|
|
||||||
if (userInfo) {
|
const checkVipStatus = async (vipLevel, expireTime, nickname, avatarUrl) => {
|
||||||
axios.get(`${autoSelectNeteaseApi}/vip/info?uid=${userInfo.userId}`, {
|
|
||||||
headers: {
|
|
||||||
"User-Agent": COMMON_USER_AGENT,
|
|
||||||
"Cookie": reck ? reck : this.neteaseCookie
|
|
||||||
},
|
|
||||||
}).then(async res => {
|
|
||||||
// logger.info('vip信息', res.data)
|
|
||||||
const vipInfo = res.data.data
|
|
||||||
const checkVipStatus = async (vipLevel, expireTime, nickname, avatarUrl, e) => {
|
|
||||||
const expireDate = new Date(expireTime);
|
const expireDate = new Date(expireTime);
|
||||||
if (expireDate > Date.now()) {
|
if (expireDate > Date.now()) {
|
||||||
const vipLevelData = vipLevel.split("\n");
|
const vipLevelData = vipLevel.split("\n");
|
||||||
@ -1485,131 +1481,116 @@ async neteaseStatus(e, reck) {
|
|||||||
nickname,
|
nickname,
|
||||||
vipLevel: vipLevelData[0],
|
vipLevel: vipLevelData[0],
|
||||||
musicQuality: vipLevelData[2],
|
musicQuality: vipLevelData[2],
|
||||||
expireDate: expireDate.toLocaleString()
|
expireDate: expireDate.toLocaleString(),
|
||||||
});
|
});
|
||||||
// e.reply([segment.image(`${avatarUrl}?param=170y170`), `网易云已登录:\n${nickname}\n会员等级:\n${vipLevel}\n会员到期时间:\n${expireDate.toLocaleString()}`]);
|
|
||||||
let img = await puppeteer.screenshot("netease", neteaseData);
|
let img = await puppeteer.screenshot("netease", neteaseData);
|
||||||
e.reply(img, true);
|
e.reply(img, true);
|
||||||
} else {
|
|
||||||
return false; // 返回 false 以继续检查下一个 VIP 状态
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (vipInfo.redplus.vipCode != 0 && await checkVipStatus(`SVIP${vipInfo.redplus.vipLevel}\n最高解析音质:\n jymaster(超清母带)`, vipInfo.redplus.expireTime, userInfo.nickname, userInfo.avatarUrl, e)) {
|
if (vipInfo.redplus.vipCode !== 0 && await checkVipStatus(`SVIP${vipInfo.redplus.vipLevel}\n最高解析音质:\n jymaster(超清母带)`, vipInfo.redplus.expireTime, userInfo.nickname, userInfo.avatarUrl)) {
|
||||||
// SVIP 有效,不执行后续逻辑
|
return;
|
||||||
} else if (vipInfo.associator.vipCode != 0 && await checkVipStatus(`VIP${vipInfo.associator.vipLevel}\n最高解析音质:\n jyeffect(高清环绕音)`, vipInfo.associator.expireTime, userInfo.nickname, userInfo.avatarUrl, e)) {
|
}
|
||||||
// VIP 有效,不执行后续逻辑
|
if (vipInfo.associator.vipCode !== 0 && await checkVipStatus(`VIP${vipInfo.associator.vipLevel}\n最高解析音质:\n jyeffect(高清环绕音)`, vipInfo.associator.expireTime, userInfo.nickname, userInfo.avatarUrl)) {
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 如果都已过期,发送 VIP 已过期信息
|
// 如果都已过期,发送 VIP 已过期信息
|
||||||
const neteaseData = await new NeteaseModel(e).getData({
|
const neteaseData = await new NeteaseModel(e).getData({
|
||||||
avatarUrl: `${userInfo.avatarUrl}?param=170y170`,
|
avatarUrl: `${userInfo.avatarUrl}?param=170y170`,
|
||||||
nickname: userInfo.nickname,
|
nickname: userInfo.nickname,
|
||||||
vipLevel: `${vipInfo.redplus.vipCode != 0 ? `SVIP${vipInfo.associator.vipLevel}(已过期)\n` : vipInfo.associator.vipCode != 0 ? `VIP${vipInfo.associator.vipLevel}(已过期)\n` : '未开通'}`,
|
vipLevel: vipInfo.redplus.vipCode !== 0 ? `SVIP${vipInfo.redplus.vipLevel}(已过期)` : vipInfo.associator.vipCode !== 0 ? `VIP${vipInfo.associator.vipLevel}(已过期)` : '未开通',
|
||||||
musicQuality: 'standard(标准)',
|
musicQuality: 'standard(标准)',
|
||||||
expireDate: `未开通`
|
expireDate: '未开通',
|
||||||
});
|
});
|
||||||
// e.reply([segment.image(`${avatarUrl}?param=170y170`), `网易云已登录:\n${nickname}\n会员等级:\n${vipLevel}\n会员到期时间:\n${expireDate.toLocaleString()}`]);
|
|
||||||
let img = await puppeteer.screenshot("netease", neteaseData);
|
let img = await puppeteer.screenshot("netease", neteaseData);
|
||||||
e.reply(img, true);
|
e.reply(img, true);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('获取网易云状态时出错:', error);
|
||||||
|
e.reply('获取网易云状态时出错,请稍后再试');
|
||||||
}
|
}
|
||||||
})
|
|
||||||
// e.reply([segment.image(userInfo.avatarUrl), `网易云已登录:${userInfo.nickname}\n会员等级:\n`,segment.image(vipInfo.iconUrl)]);
|
|
||||||
} else {
|
|
||||||
e.reply('暂未登录,请发 #RNQ 或者 #rnq 进行登陆绑定ck')
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
// 网易扫码登录
|
|
||||||
async netease_scan(e) {
|
|
||||||
// 优先判断是否使用自建 API
|
|
||||||
let autoSelectNeteaseApi
|
|
||||||
// 判断海外
|
|
||||||
const isOversea = await this.isOverseasServer();
|
|
||||||
if (this.useLocalNeteaseAPI) {
|
|
||||||
// 使用自建 API
|
|
||||||
autoSelectNeteaseApi = this.neteaseCloudAPIServer
|
|
||||||
} else {
|
|
||||||
// 自动选择 API
|
|
||||||
autoSelectNeteaseApi = isOversea ? NETEASE_SONG_DOWNLOAD : NETEASE_API_CN;
|
|
||||||
}
|
|
||||||
// 获取登录key
|
|
||||||
let keyUrl = autoSelectNeteaseApi + '/login/qr/key'
|
|
||||||
axios.get(keyUrl, {
|
|
||||||
headers: {
|
|
||||||
"User-Agent": COMMON_USER_AGENT
|
|
||||||
},
|
|
||||||
}).then(res => {
|
|
||||||
// 获取登录二维码
|
|
||||||
const unikey = res.data.data.unikey
|
|
||||||
let url = autoSelectNeteaseApi + '/login/qr/create?key=' + unikey + "&qrimg=true"
|
|
||||||
axios.get(url, {
|
|
||||||
headers: {
|
|
||||||
"User-Agent": COMMON_USER_AGENT,
|
|
||||||
},
|
|
||||||
}).then(async res => {
|
|
||||||
// logger.info('扫码登录数据', res.data.data)
|
|
||||||
await mkdirIfNotExists(this.defaultPath);
|
|
||||||
const saveCodePath = `${this.defaultPath}NeteaseQrcode.png`;
|
|
||||||
await qrcode.toFile(saveCodePath,res.data.data.qrurl)
|
|
||||||
e.reply([segment.image(saveCodePath), '请在40秒内使用网易云APP进行扫码']);
|
|
||||||
// e.reply([segment.image(res.data.data.qrimg), '请在30秒内使用网易云APP进行扫码']);
|
|
||||||
})
|
|
||||||
|
|
||||||
//最大轮询次数 5s/check
|
// 轮询网易云状态
|
||||||
let pollCount = 0; // 轮询计数器
|
async pollLoginStatus(autoSelectNeteaseApi, unikey, e) {
|
||||||
const maxPolls = 8; // 最大轮询次数
|
let pollCount = 0;
|
||||||
|
const maxPolls = 8;
|
||||||
|
const intervalTime = 5000;
|
||||||
|
|
||||||
const pollRequest = async () => {
|
const pollRequest = async () => {
|
||||||
let pollUrl = autoSelectNeteaseApi + '/login/qr/check?key=' + unikey + '×tamp=' + Date.now();
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(pollUrl, {
|
const pollUrl = `${autoSelectNeteaseApi}/login/qr/check?key=${unikey}×tamp=${Date.now()}`;
|
||||||
headers: {
|
const res = await axios.get(pollUrl, { headers: { "User-Agent": COMMON_USER_AGENT } });
|
||||||
"User-Agent": COMMON_USER_AGENT,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// logger.info('轮询状态', res.data);
|
|
||||||
if (res.data.code == '800') {
|
if (res.data.code == '800') {
|
||||||
e.reply("二维码过期,请重新获取");
|
e.reply("二维码过期,请重新获取");
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.data.code == '803') {
|
if (res.data.code == '803') {
|
||||||
const regex = /music_u=([^;]+)/i; // 使用 'i' 进行不区分大小写匹配
|
const regex = /music_u=([^;]+)/i;
|
||||||
const match = res.data.cookie.match(regex);
|
const match = res.data.cookie.match(regex);
|
||||||
if (match) {
|
if (match) {
|
||||||
try {
|
try {
|
||||||
let ck = match[0] + '; os=pc'
|
const ck = `${match[0]}; os=pc`;
|
||||||
await config.updateField("tools", "neteaseCookie", ck);
|
await config.updateField("tools", "neteaseCookie", ck);
|
||||||
// logger.info('ck------', match[0]);
|
this.neteaseStatus(e, ck);
|
||||||
this.neteaseStatus(e, ck)
|
e.reply(`扫码登录成功,ck已自动保存`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('更新ck时出错:', error);
|
logger.error('更新ck时出错:', error);
|
||||||
e.reply('更新ck时出错,请稍后重试');
|
e.reply('更新ck时出错,请稍后重试');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.reply(`扫码登录成功,ck已自动保存`);
|
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pollCount++;
|
pollCount++;
|
||||||
|
if (pollCount > maxPolls) {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
logger.info('超时轮询已停止');
|
||||||
|
e.reply('扫码超时,请重新获取');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('轮询过程中出错:', error);
|
logger.error('轮询过程中出错:', error);
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
e.reply('轮询过程中发生错误,请稍后再试');
|
e.reply('轮询过程中发生错误,请稍后再试');
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (pollCount > maxPolls) {
|
const intervalId = setInterval(pollRequest, intervalTime);
|
||||||
clearInterval(intervalId); // 停止轮询
|
|
||||||
logger.info('超时轮询已停止');
|
|
||||||
e.reply('扫码超时,请重新获取');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 网易扫码登录
|
||||||
|
async netease_scan(e) {
|
||||||
|
try {
|
||||||
|
// 优先判断是否使用自建 API
|
||||||
|
const isOversea = await this.isOverseasServer();
|
||||||
|
const autoSelectNeteaseApi = this.useLocalNeteaseAPI ? this.neteaseCloudAPIServer : (isOversea ? NETEASE_SONG_DOWNLOAD : NETEASE_API_CN);
|
||||||
|
|
||||||
|
// 获取登录key
|
||||||
|
const keyUrl = `${autoSelectNeteaseApi}/login/qr/key`;
|
||||||
|
const keyResponse = await axios.get(keyUrl, { headers: { "User-Agent": COMMON_USER_AGENT } });
|
||||||
|
const unikey = keyResponse.data.data.unikey;
|
||||||
|
|
||||||
|
// 获取登录二维码
|
||||||
|
const qrUrl = `${autoSelectNeteaseApi}/login/qr/create?key=${unikey}&qrimg=true`;
|
||||||
|
const qrResponse = await axios.get(qrUrl, { headers: { "User-Agent": COMMON_USER_AGENT } });
|
||||||
|
|
||||||
|
await mkdirIfNotExists(this.defaultPath);
|
||||||
|
const saveCodePath = `${this.defaultPath}NeteaseQrcode.png`;
|
||||||
|
await qrcode.toFile(saveCodePath, qrResponse.data.data.qrurl);
|
||||||
|
e.reply([segment.image(saveCodePath), '请在40秒内使用网易云APP进行扫码']);
|
||||||
|
|
||||||
|
// 轮询检查登录状态
|
||||||
|
await this.pollLoginStatus(autoSelectNeteaseApi, unikey, e);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('执行网易云扫码登录时出错:', error);
|
||||||
|
e.reply('执行扫码登录时发生错误,请稍后再试');
|
||||||
}
|
}
|
||||||
const intervalId = setInterval(pollRequest, 5000);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网易云解析
|
// 网易云解析
|
||||||
@ -1963,7 +1944,7 @@ async neteaseStatus(e, reck) {
|
|||||||
await ytDlpHelper(path, url, isOversea, this.myProxy, true, graphics);
|
await ytDlpHelper(path, url, isOversea, this.myProxy, true, graphics);
|
||||||
this.sendVideoToUpload(e, `${ path }/temp.mp4`);
|
this.sendVideoToUpload(e, `${ path }/temp.mp4`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
logger.error(error);
|
||||||
throw error; // Rethrow the error so it can be handled by the caller
|
throw error; // Rethrow the error so it can be handled by the caller
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1991,7 +1972,7 @@ async neteaseStatus(e, reck) {
|
|||||||
// debug专用
|
// debug专用
|
||||||
// fs.writeFile('data.json', JSON.stringify(respJson), (err) => {
|
// fs.writeFile('data.json', JSON.stringify(respJson), (err) => {
|
||||||
// if (err) {
|
// if (err) {
|
||||||
// console.error('Error writing file:', err);
|
// logger.error('Error writing file:', err);
|
||||||
// } else {
|
// } else {
|
||||||
// console.log('JSON saved to file successfully.');
|
// console.log('JSON saved to file successfully.');
|
||||||
// }
|
// }
|
||||||
@ -2146,7 +2127,7 @@ async neteaseStatus(e, reck) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
logger.error(error);
|
||||||
throw error; // Rethrow the error so it can be handled by the caller
|
throw error; // Rethrow the error so it can be handled by the caller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2603,7 +2584,7 @@ async neteaseStatus(e, reck) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
logger.error(error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user