Compare commits

...
12 Commits
Author SHA1 Message Date
shanmite 77245c0391 env.js 2023-06-30 08:44:57 +08:00
shanmite c0dbdee343 proxy all 2023-06-29 16:40:01 +08:00
shanmite a0a2502148 test case 2023-06-29 15:37:49 +08:00
shanmite 41b036966e ci: fix pkg.yml 2023-06-29 08:01:24 +08:00
shanmite c282d8492d docs: 更新CHANGELOG 2023-06-28 16:06:23 +08:00
shanmite 5a3c16d20d fix: 专栏获取内容不正确,需要排除推荐内容 (#293)
Fixed #293
2023-06-28 15:28:27 +08:00
shanmite 75383e8faa docs: 更新CHANGELOG 2023-05-16 09:56:09 +08:00
shanmite 29645bc4e7 fixed: 话题搜索功能已失效 #285
Fixed #285
2023-05-16 09:55:08 +08:00
shanmite d950a59b4d fix: is_imitator导致错误评论 2023-05-15 11:24:09 +08:00
shanmite d3e3436075 docs: 更新CHANGELOG 2023-05-15 10:49:26 +08:00
shanmite 3828a0f054 fix: Cannot read properties of null (#284)
Fixed #284
2023-05-15 10:47:57 +08:00
shanmite 67313f4a23 feat: 专栏里的动态链接识别优化 (#283)
Fixed #283
2023-05-05 10:20:17 +08:00
12 changed files with 139 additions and 21 deletions
-2
View File
@@ -49,7 +49,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
file: "dist/*.zip"
delete_file: "dist/*.zip"
tag_name: "v2"
overwrite: true
arm64:
@@ -78,6 +77,5 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
file: "dist/*.zip"
delete_file: "dist/*.zip"
tag_name: "v2"
overwrite: true
+17
View File
@@ -1,5 +1,22 @@
<!-- markdownlint-disable MD036 MD024-->
# CHANGELOG
## 主要变化(2.7.11)
* 5a3c16d fix: 专栏获取内容不正确,需要排除推荐内容 (#293)
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
## 主要变化(2.7.10)
* 29645bc fixed: 话题搜索功能已失效 #285
* d950a59 fix: is_imitator导致错误评论
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
## 主要变化(2.7.9)
* 3828a0f fix: Cannot read properties of null (#284)
* 67313f4 feat: 专栏里的动态链接识别优化 (#283)
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
## 主要变化(2.7.8)
* ad6af97 feat: 专栏短链接识别 (#263)
* b6c56c5 feat: 取关分区支持设置多分区 (#281)
+8
View File
@@ -7,6 +7,10 @@ module.exports = Object.freeze({
* - `CLEAR` 是否启用清理功能
* - `ENABLE_MULTIPLE_ACCOUNT` 是否启用多账号
* - `MULTIPLE_ACCOUNT_PARM` 多账号参数(JSON格式)
* ## 代理相关
* - `ENABLE_PROXY` 启用代理
* - `XMDL_ORDERNNO` 熊猫动态代理订单号
* - `XMDL_SECRET` 熊猫动态代理密钥
* ## 调试相关
* - `LOTTERY_LOG_LEVEL` 输出日志等级 Error<Warn<Info<Debug 1<2<3<4
* - `NOT_GO_LOTTERY` 关闭抽奖行为
@@ -25,6 +29,10 @@ module.exports = Object.freeze({
ENABLE_MULTIPLE_ACCOUNT: false,
ENABLE_PROXY: "",
XMDL_ORDERNNO: "",
XMDL_SECRET: "",
MULTIPLE_ACCOUNT_PARM: "",
LOTTERY_LOG_LEVEL: 3,
NOT_GO_LOTTERY: ""
+3 -4
View File
@@ -396,8 +396,7 @@ class Monitor extends Searcher {
|| (hasOfficialLottery && model[0] === '1')
|| (!hasOfficialLottery && model[1] === '1' && has_key_words),
isSendChat =
(is_imitator && lottery_info_type === 'uid' && chatmodel !== '00')
|| (hasOfficialLottery && chatmodel[0] === '1')
(hasOfficialLottery && chatmodel[0] === '1')
|| (!hasOfficialLottery && chatmodel[1] === '1'),
{ blacklist: remote_blacklist } = use_public_blacklist === false
? { blacklist: "" }
@@ -488,7 +487,7 @@ class Monitor extends Searcher {
let
/**转发评语 */
RandomStr = getRandomOne(relays)
RandomStr = (getRandomOne(relays) || "!!!")
.replace(/\$\{uname\}/g, uname_map[real_uid] || uname),
/**控制字段 */
new_ctrl = [];
@@ -541,7 +540,7 @@ class Monitor extends Searcher {
/* 是否评论 */
if (isSendChat) {
onelotteryinfo.rid = rid
onelotteryinfo.chat = getRandomOne(chats)
onelotteryinfo.chat = (getRandomOne(chats) || "!!!")
.replace(/\$\{uname\}/g, uname_map[real_uid] || uname)
}
+10 -3
View File
@@ -186,6 +186,12 @@ function modifyDynamicRes(res) {
log.warn('处理动态数据', '未找到任何动态信息')
}
if (typeof has_more === "undefined"
&& typeof offset === "undefined") {
log.error('处理动态数据', '该功能已失效');
return null;
}
const
/**
* 字符串offset防止损失精度
@@ -353,6 +359,8 @@ class Searcher {
* @returns {Promise<LotteryInfo[] | null>}
*/
async getLotteryInfoByTag(tag_name) {
log.info('获取动态', `开始获取带话题#${tag_name}#的动态信息`);
const
tag_id = await bili.getTagIDByTagName(tag_name),
hotdy = await bili.getHotDynamicInfoByTagID(tag_id),
@@ -360,7 +368,6 @@ class Searcher {
if (modDR === null) return null;
log.info('获取动态', `开始获取带话题#${tag_name}#的动态信息`);
log.info('获取动态', '成功获取热门动态');
/**
@@ -425,8 +432,8 @@ class Searcher {
continue
}
const
content = await bili.getOneArticleByCv(id),
dyids = content.match(/(?<=t.bilibili.com\/)[0-9]+/g) || [],
content = (await bili.getOneArticleByCv(id) || "").split("推荐文章")[0],
dyids = content.match(/[0-9]{18}/g) || [],
short_ids = content.match(/(?<=b23.tv\/)[a-zA-Z0-9]{7}/g) || [],
short_id_set = [...new Set(short_ids)],
short_ids_to_dyids = await Promise.all(short_id_set.map(bili.shortDynamicIdToDyid)),
+26
View File
@@ -0,0 +1,26 @@
const { log } = require('../utils');
const crypto = require('crypto');
/**
* [熊猫代理](http://www.xiongmaodaili.com)
* @returns {import("../net/http").ProxyConfig}
*/
function xiongmaodaili() {
log.info("熊猫代理", "开始")
let timestamp = parseInt(new Date().getTime() / 1000);
let orderno = process.env["XMDL_ORDERNNO"];
let secret = process.env["XMDL_SECRET"];
let txt = 'orderno=' + orderno + ',secret=' + secret + ',timestamp=' + timestamp;
let md5 = crypto.createHash('md5');
let sign = md5.update(txt).digest('hex').toUpperCase();
return {
url: "http://dtan.xiongmaodaili.com:8088",
auth_headers: [
["Proxy-Authorization", 'sign=' + sign + '&orderno=' + orderno + "&timestamp=" + timestamp]
]
}
}
module.exports = { xiongmaodaili }
+14 -5
View File
@@ -1,7 +1,8 @@
const GlobalVar = require('../data/global_var');
const { strToJson, log } = require('../utils');
const { strToJson, log, hasEnv } = require('../utils');
const { send } = require('./http');
const API = require('./api.bili');
const proxies = require("../helper/proxies");
class Line {
/**
@@ -88,7 +89,7 @@ class Line {
*/
function get({ url, config, contents, query }) {
return new Promise((resolve) => {
send({
let ro = {
url,
method: 'GET',
config,
@@ -100,7 +101,11 @@ function get({ url, config, contents, query }) {
contents,
success: res => resolve(res.body),
failure: err => resolve(err)
})
}
if (hasEnv("ENABLE_PROXY")) {
ro.proxy = proxies.xiongmaodaili();
}
send(ro)
})
}
@@ -111,7 +116,7 @@ function get({ url, config, contents, query }) {
*/
function post({ url, config, contents, query }) {
return new Promise((resolve) => {
send({
let ro = {
url,
method: 'POST',
config,
@@ -124,7 +129,11 @@ function post({ url, config, contents, query }) {
contents,
success: res => resolve(res.body),
failure: err => resolve(err)
})
};
if (hasEnv("ENABLE_PROXY")) {
ro.proxy = proxies.xiongmaodaili();
}
send(ro)
})
}
+18 -5
View File
@@ -20,12 +20,16 @@
* @property {boolean} [redirect] 是否重定向
* @property {number} [retry_times] 重试次数
*
* @typedef ProxyConfig
* @property {string} url https?://{IP}:{PORT}
* @property {[[string, string]]} auth_headers [[k,v],[k,v]]
*
* @typedef {object} RequestOptions Http请求选项
* @property {string} [method] 请求方法
* @property {string} url 完整链接
* @property {boolean} [stream] 是否流式数据
* @property {RequestConfig} [config] 设置
* @property {string} [proxy] HTTP代理 IP:PORT
* @property {ProxyConfig} [proxy] HTTP代理 IP:PORT
* @property {Object.<string, string|number>} [query] 查询选项
* @property {Object.<string, string|number> | string} [contents] 内容
* @property {HttpHeaders} [headers] 请求头
@@ -34,7 +38,9 @@
*/
const { request: http_request } = require('http');
const { HttpProxyAgent } = require('http-proxy-agent');
const { request: https_request } = require('https');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { stringify } = require('querystring');
/**默认编码 */
@@ -64,7 +70,10 @@ function send(detail) {
const { timeout, wait, retry, redirect, retry_times } = config;
const thisURL = new URL(url)
, content = formatContents(headers["content-type"], contents)
, request = (thisURL.protocol === 'https:') && !proxy ? https_request : http_request;
, request = (thisURL.protocol === 'https:') ? https_request : http_request;
/**
* @type {import("https").RequestOptions}
*/
let options = {
timeout,
method: method.toUpperCase(),
@@ -80,9 +89,13 @@ function send(detail) {
options.headers['content-length'] = Buffer.byteLength(content, 'utf-8').toString();
}
if (proxy) {
options.headers.host = thisURL.host;
options.path = thisURL.href;
[options.host, options.port] = proxy.split(':');
options.agent = (thisURL.protocol === 'https:')
? new HttpsProxyAgent(proxy.url)
: new HttpProxyAgent(proxy.url);
for (const ah of proxy.auth_headers) {
options.headers[ah[0]] = ah[1]
}
options.rejectUnauthorized = false
}
const req = request(options, res => {
let protodata = '';
+3 -1
View File
@@ -1,6 +1,6 @@
{
"name": "lottery-auto-script",
"version": "2.7.8",
"version": "2.7.11",
"description": "自动参与B站动态抽奖",
"main": "main.js",
"scripts": {
@@ -42,6 +42,8 @@
},
"dependencies": {
"chalk": "^4.1.2",
"http-proxy-agent": "^7.0.0",
"https-proxy-agent": "^7.0.0",
"nodemailer": "^6.7.0"
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ const { parseDynamicCard } = require('../lib/core/searcher');
(async () => {
assert(await bili_client.getMyinfo());
await util.par_run([0, 1, 2, 3, 4, 6], [
await util.par_run([0, 1, 2, 3, 4, 5], [
// 0
async () => {
assert.equal((await bili_client.getTopRcmd()).length, 10)
+1
View File
@@ -7,6 +7,7 @@ log._level = 2
env.init()
global_var.init(process.env["COOKIE"], 1)
fs.readdirSync(module.path)
.filter(file => file.endsWith(".test.js"))
.forEach(file => require(`${module.path}/${file}`))
+38
View File
@@ -0,0 +1,38 @@
const util = require('./util');
const crypto = require('crypto');
const { send } = require('../lib/net/http');
(async () => {
await util.par_run([], [
// 0
async () => {
let timestamp = parseInt(new Date().getTime() / 1000);
let orderno = process.env["XMDL_ORDERNNO"];
let secret = process.env["XMDL_SECRET"];
if (orderno && secret) {
let txt = 'orderno=' + orderno + ',secret=' + secret + ',timestamp=' + timestamp;
let md5 = crypto.createHash('md5');
let sign = md5.update(txt).digest('hex').toUpperCase();
console.log(await new Promise((resolve) => {
send({
url: "https://api.bilibili.com/client_info",
proxy: {
url: "http://dtan.xiongmaodaili.com:8088",
auth_headers: [
["Proxy-Authorization", 'sign=' + sign + '&orderno=' + orderno + "&timestamp=" + timestamp]
]
},
config: {
retry: false
},
success: (res) => { resolve(JSON.parse(res.body)) },
failure: resolve
})
}));
console.log("proxy.test ... ok!");
}
},
])
})()