From fa91a2126d44331926dce401be76dd22e832b4b0 Mon Sep 17 00:00:00 2001 From: amadeus5201 <1491459939@qq.com> Date: Sat, 11 Jan 2025 14:51:28 +0800 Subject: [PATCH] =?UTF-8?q?feat=3D>=E5=A2=9E=E5=8A=A0=E5=A4=9A=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E7=9A=84=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env.example.js | 6 +++++- lib/net/bili.js | 27 +++++++++++++++++++++++---- main.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/env.example.js b/env.example.js index f237ed1..9feef3c 100644 --- a/env.example.js +++ b/env.example.js @@ -64,7 +64,11 @@ module.exports = Object.freeze({ NUMBER: 1, CLEAR: true, WAIT: 60 * 1000, - ACCOUNT_UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' + ACCOUNT_UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', + PROXY_HOST:'',//代理ip + PROXY_PORT:'',//代理ip端口 + PROXY_USER:'',//代理ip账号 + PROXY_PASS:'',//代理ip密码 } ], diff --git a/lib/net/bili.js b/lib/net/bili.js index 0cc02a5..f4f0bf8 100644 --- a/lib/net/bili.js +++ b/lib/net/bili.js @@ -80,6 +80,16 @@ class Line { } } } +function getIp({ url }) { + return new Promise((resolve) => { + send({ + url, + method: 'GET', + success: res => resolve(res.body), + failure: err => resolve(err) + }); + }); +} /** * GET请求 @@ -132,6 +142,11 @@ function post({ url, config, contents, query }) { * 网络请求 */ const bili_client = { + async getIpInfo() { + return await getIp({ + url: 'https://myip.qq.com/' + }); + }, /** * 判断是否成功登录 * @returns {Promise} @@ -186,7 +201,11 @@ const bili_client = { const items = res.data.items; if (items.length !== 0) { items.forEach(i => { - const { at_time, item, user } = i, { nickname: up_uname } = user, { business, uri: url, source_content } = item; + const { at_time, item, user } = i, { nickname: up_uname } = user, { + business, + uri: url, + source_content + } = item; atInfo.push({ at_time, up_uname, @@ -583,7 +602,7 @@ const bili_client = { * @param {number} uid * @returns {Promise} */ - (uid) => get({ + (uid) => get({ url: API.WEB_INTERFACE_CARD, query: { mid: uid, @@ -598,7 +617,7 @@ const bili_client = { * @param {number} uid * @returns {Promise} */ - (uid) => get({ + (uid) => get({ url: API.RELATION_STAT, query: { vmid: uid @@ -609,7 +628,7 @@ const bili_client = { * @param {number} uid * @returns {Promise} */ - (uid) => get({ + (uid) => get({ url: 'https://tenapi.cn/bilibilifo/', query: { uid diff --git a/main.js b/main.js index 8655623..5b0e8d7 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,17 @@ -const { version: ve, env_file, config_file, log, hasEnv, delay, hasFileOrDir, clearLotteryInfo } = require('./lib/utils'); +const { + version: ve, + env_file, + config_file, + log, + hasEnv, + delay, + hasFileOrDir, + clearLotteryInfo +} = require('./lib/utils'); +const { getIpInfo } = require("./lib/net/bili"); +const { HttpsProxyAgent } = require("https-proxy-agent"); +const request = require("https"); const metainfo = [ ' _ _ _ _____ _ _ ', ' | | | | | | / ____| (_) | | ', @@ -23,6 +35,15 @@ let ck_flag = 0; /** * @returns {Promise} 错误信息 */ +async function printIpInfo(beforeProxy) { + const printMessage = beforeProxy ? '当前IP----->' : '代理后IP=======>'; + await getIpInfo().then(res => { + console.log(printMessage + res); + }).catch((err) => { + console.error('获取' + printMessage + '地址失败', err); + }); +} + async function main() { const { COOKIE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env; if (ENABLE_MULTIPLE_ACCOUNT) { @@ -32,12 +53,24 @@ async function main() { process.env.ENABLE_MULTIPLE_ACCOUNT = ''; + const request = require('https'); for (const acco of muti_acco) { process.env.COOKIE = acco.COOKIE; process.env.NUMBER = acco.NUMBER; process.env.CLEAR = acco.CLEAR; process.env.NOTE = acco.NOTE; process.env.ACCOUNT_UA = acco.ACCOUNT_UA; + + if (acco.PROXY_HOST) { + await printIpInfo(true); + //http://ip:port + //http://user:pwd@ip:port' + const proxyUrl = acco.PROXY_USER + ? 'http://' + acco.PROXY_USER + ':' + acco.PROXY_PASS + '@' + acco.PROXY_HOST + ':' + acco.PROXY_PORT + : 'http://' + acco.PROXY_HOST + ':' + acco.PROXY_PORT; + request.globalAgent = new HttpsProxyAgent(proxyUrl); + await printIpInfo(false); + } const err_msg = await main(); if (err_msg) { return err_msg; @@ -50,6 +83,7 @@ async function main() { } } + /**多账号状态还原 */ process.env.ENABLE_MULTIPLE_ACCOUNT = ENABLE_MULTIPLE_ACCOUNT; } else if (COOKIE) { @@ -65,7 +99,12 @@ async function main() { const mode = process.env.lottery_mode; const help_msg = '用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tacount 查看帐号信息\n\tclear 清理动态和关注\n\tlogin 扫码登录更新CK\n\tupdate 检查更新\n\thelp 帮助信息'; if (await checkCookie(NUMBER)) { - const { lottery_loop_wait, check_loop_wait, clear_loop_wait, save_lottery_info_to_file } = require('./lib/data/config'); + const { + lottery_loop_wait, + check_loop_wait, + clear_loop_wait, + save_lottery_info_to_file + } = require('./lib/data/config'); ck_flag = 1; switch (mode) { case 'start':