mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-07-22 21:13:47 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77245c0391 | ||
|
|
c0dbdee343 | ||
|
|
a0a2502148 | ||
|
|
41b036966e | ||
|
|
c282d8492d | ||
|
|
5a3c16d20d | ||
|
|
75383e8faa | ||
|
|
29645bc4e7 | ||
|
|
d950a59b4d | ||
|
|
d3e3436075 | ||
|
|
3828a0f054 | ||
|
|
67313f4a23 | ||
|
|
fd2921cb07 | ||
|
|
ad6af9705f | ||
|
|
b6c56c5061 | ||
|
|
c7bdf74d5c | ||
|
|
2426fe2384 | ||
|
|
d370fef899 | ||
|
|
00174b0fdc | ||
|
|
ea711ae048 | ||
|
|
881923ba54 | ||
|
|
097e2d61e7 | ||
|
|
82d285e841 | ||
|
|
bf4e8945c0 | ||
|
|
9c9bc18a44 |
@@ -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
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
<!-- 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)
|
||||
|
||||
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
|
||||
|
||||
## 主要变化(2.7.7)
|
||||
* 2426fe2 fix: 动态详情获取接口412频繁 (#279)
|
||||
* d370fef fix: 获取动态详情出现undefined (#271)
|
||||
* 00174b0 fix(monitor): L615
|
||||
|
||||
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
|
||||
|
||||
## 主要变化(2.7.6)
|
||||
* 881923b fix: 开奖时间和粉丝数判断逻辑 (#253)
|
||||
* 097e2d6 fix: 筛选掉置顶的评论,与该动态UP的评论 (#252)
|
||||
* 82d285e fix: 充电专属动态 (#251)
|
||||
|
||||
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
|
||||
|
||||
## 主要变化(2.7.5)
|
||||
* 9c9bc18 fix: 查询评论报错 (#250)
|
||||
|
||||
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
|
||||
|
||||
## 主要变化(2.7.4)
|
||||
* 0630c89 feat: 新增设置抄热评屏蔽词 (#239)
|
||||
* 7b9d251 feat: 热评包含发送热评的人的昵称换成自己的昵称 (#239)
|
||||
|
||||
@@ -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: ""
|
||||
|
||||
+6
-5
@@ -6,12 +6,13 @@ const config = require("./data/config");
|
||||
|
||||
/**
|
||||
* 获取关注分区里的uid
|
||||
* @param {string} partition
|
||||
* @returns { Promise<number[]> }
|
||||
*/
|
||||
async function getFollowList() {
|
||||
async function getFollowList(partition) {
|
||||
const
|
||||
{ clear_partition, clear_white_list, get_partition_wait } = config,
|
||||
tagid = await bili.checkMyPartition(clear_partition);
|
||||
{ clear_white_list, get_partition_wait } = config,
|
||||
tagid = await bili.checkMyPartition(partition);
|
||||
let rmup = [];
|
||||
if (typeof tagid === 'undefined') {
|
||||
log.info('获取关注列表', '未能成功获取关注分区id');
|
||||
@@ -32,9 +33,9 @@ async function getFollowList() {
|
||||
* 清理动态和关注
|
||||
*/
|
||||
async function clear() {
|
||||
const { search_wait, clear_white_list, clear_max_day, clear_quick_remove_attention, clear_remove_dynamic, clear_remove_attention, clear_remove_delay, clear_dynamic_type } = config;
|
||||
const { search_wait, clear_white_list, clear_max_day, clear_quick_remove_attention, clear_remove_dynamic, clear_remove_attention, clear_remove_delay, clear_dynamic_type, clear_partition } = config;
|
||||
let success = true;
|
||||
const uid_list = await getFollowList();
|
||||
const uid_list = (await Promise.all(clear_partition.split(',').map(getFollowList))).flat();
|
||||
if (!uid_list.length) {
|
||||
log.info('清理关注', `关注为空`)
|
||||
} else {
|
||||
|
||||
+19
-19
@@ -91,12 +91,6 @@ class Monitor extends Searcher {
|
||||
case 5001:
|
||||
event_bus.emit('Turn_off_the_Monitor', '转发失败')
|
||||
break
|
||||
case 6001:
|
||||
event_bus.emit('Turn_off_the_Monitor', '获取开奖时间失败')
|
||||
break
|
||||
case 7001:
|
||||
event_bus.emit('Turn_off_the_Monitor', '获取关注数失败')
|
||||
break
|
||||
default:
|
||||
event_bus.emit('Turn_off_the_Monitor', `??? 未知错误: ${status}`)
|
||||
break;
|
||||
@@ -135,9 +129,16 @@ class Monitor extends Searcher {
|
||||
if (lottery.isOfficialLottery) {
|
||||
let { ts } = await bili.getLotteryNotice(lottery.dyid);
|
||||
const ts_10 = Date.now() / 1000;
|
||||
if (ts < 0) {
|
||||
status = 6001
|
||||
break;
|
||||
if (ts === -1) {
|
||||
log.warn('过滤', '无法判断开奖时间')
|
||||
await delay(filter_wait)
|
||||
continue
|
||||
}
|
||||
if (ts === -9999) {
|
||||
log.info('过滤', '已撤销抽奖')
|
||||
d_storage.updateDyid(lottery.dyid)
|
||||
await delay(filter_wait)
|
||||
continue
|
||||
}
|
||||
if (ts < ts_10) {
|
||||
log.info('过滤', '已过开奖时间')
|
||||
@@ -155,9 +156,10 @@ class Monitor extends Searcher {
|
||||
const { minfollower } = config
|
||||
if (minfollower > 0) {
|
||||
const followerNum = await bili.getUserInfo(lottery.uid[0]);
|
||||
if (followerNum < 0) {
|
||||
status = 7001
|
||||
break;
|
||||
if (followerNum === -1) {
|
||||
log.warn('过滤', `粉丝数(${followerNum})获取失败`)
|
||||
await delay(filter_wait)
|
||||
continue
|
||||
}
|
||||
if (followerNum < minfollower) {
|
||||
log.info('过滤', `粉丝数(${followerNum})小于指定数量`)
|
||||
@@ -394,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: "" }
|
||||
@@ -486,7 +487,7 @@ class Monitor extends Searcher {
|
||||
|
||||
let
|
||||
/**转发评语 */
|
||||
RandomStr = getRandomOne(relays)
|
||||
RandomStr = (getRandomOne(relays) || "!!!")
|
||||
.replace(/\$\{uname\}/g, uname_map[real_uid] || uname),
|
||||
/**控制字段 */
|
||||
new_ctrl = [];
|
||||
@@ -539,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)
|
||||
}
|
||||
|
||||
@@ -601,17 +602,16 @@ class Monitor extends Searcher {
|
||||
const copy_chat = getRandomOne(
|
||||
(await bili.getChat(rid, chat_type))
|
||||
.filter(it => !(new RegExp(copy_blockword.join('|')).test(it[1])))
|
||||
);
|
||||
) || [";;;;;;;;;", chat || "!!!"];
|
||||
chat = copy_chat[1]
|
||||
.replace(
|
||||
new RegExp(copy_chat[0], 'g'),
|
||||
global_var.get("myUNAME") || '')
|
||||
|| "!!!"
|
||||
}
|
||||
|
||||
status = await retryfn(
|
||||
6,
|
||||
[4, 8, 9],
|
||||
[4],
|
||||
() => bili.sendChat(
|
||||
rid,
|
||||
is_repost_then_chat ? relay_chat.split('//')[0] : chat,
|
||||
|
||||
+25
-10
@@ -110,8 +110,12 @@ function parseDynamicCard(dynamic_detail_card) {
|
||||
obj.hasOfficialLottery = extension && extension.lott && true;
|
||||
/* 转发者的描述 纯文字内容 图片动态描述 后两个分别是视频动态的描述和视频本身的描述*/
|
||||
obj.description =
|
||||
(item && (item.content || '' + item.description || ''))
|
||||
|| (cardToJson.dynamic || '' + cardToJson.desc || '')
|
||||
(item && ((item.content || '') + (item.description || '')))
|
||||
|| (
|
||||
(cardToJson.dynamic || '')
|
||||
+ (cardToJson.desc || '')
|
||||
+ (cardToJson.vest && cardToJson.vest.content || '')
|
||||
)
|
||||
|| '';
|
||||
/* 转发 */
|
||||
if (obj.type === 1) {
|
||||
@@ -182,6 +186,12 @@ function modifyDynamicRes(res) {
|
||||
log.warn('处理动态数据', '未找到任何动态信息')
|
||||
}
|
||||
|
||||
if (typeof has_more === "undefined"
|
||||
&& typeof offset === "undefined") {
|
||||
log.error('处理动态数据', '该功能已失效');
|
||||
return null;
|
||||
}
|
||||
|
||||
const
|
||||
/**
|
||||
* 字符串offset防止损失精度
|
||||
@@ -349,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),
|
||||
@@ -356,7 +368,6 @@ class Searcher {
|
||||
|
||||
if (modDR === null) return null;
|
||||
|
||||
log.info('获取动态', `开始获取带话题#${tag_name}#的动态信息`);
|
||||
log.info('获取动态', '成功获取热门动态');
|
||||
|
||||
/**
|
||||
@@ -421,13 +432,16 @@ class Searcher {
|
||||
continue
|
||||
}
|
||||
const
|
||||
content = await bili.getOneArticleByCv(id),
|
||||
dyids = content.match(/(?<=t.bilibili.com\/)[0-9]+/g) || [],
|
||||
dyids_set = [...new Set(dyids)],
|
||||
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)),
|
||||
dyid_set = [...new Set([...dyids, ...short_ids_to_dyids])],
|
||||
/**判断此专栏是否查看过的权重 */
|
||||
weight = dyids_set.length / 2;
|
||||
weight = dyid_set.length / 2;
|
||||
|
||||
let { length } = dyids_set,
|
||||
let { length } = dyid_set,
|
||||
/**初始权重 */
|
||||
_weight = 0,
|
||||
/**单个专栏中的dyid */
|
||||
@@ -435,8 +449,9 @@ class Searcher {
|
||||
log.info('获取动态', `提取专栏(${id})中提及的dyid(${length})`)
|
||||
|
||||
/**遍历某专栏中的dyids */
|
||||
for (const dyid of dyids_set) {
|
||||
if (dyid.length === utils.dyid_length) {
|
||||
for (const dyid of dyid_set) {
|
||||
if (typeof dyid === "string"
|
||||
&& dyid.length === utils.dyid_length) {
|
||||
|
||||
log.info('获取动态', `查看专栏中所提及动态(${dyid}) (${length--})`)
|
||||
const card = await bili.getOneDynamicByDyid(dyid)
|
||||
|
||||
@@ -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 + "×tamp=" + timestamp]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { xiongmaodaili }
|
||||
+7
-1
@@ -5,7 +5,12 @@ module.exports = Object.freeze({
|
||||
DYNAMIC_REPOST_SHARE: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/share',
|
||||
DYNAMIC_SVR_CREATE_DRAW: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create_draw',
|
||||
DYNAMIC_SVR_CREATE: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V2: 'https://api.vc.bilibili.com/dynamic_svr/v2/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V3: 'https://api.vc.bilibili.com/dynamic_svr/v3/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V4: 'https://api.vc.bilibili.com/dynamic_svr/v4/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V5: 'https://api.vc.bilibili.com/dynamic_svr/v5/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V6: 'https://api.vc.bilibili.com/dynamic_svr/v6/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V7: 'https://api.vc.bilibili.com/dynamic_svr/v7/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_RM_DYNAMIC: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/rm_dynamic',
|
||||
DYNAMIC_SVR_SPACE_HISTORY: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history',
|
||||
FEED_GET_ATTENTION_LIST: 'https://api.vc.bilibili.com/feed/v1/feed/get_attention_list',
|
||||
@@ -27,6 +32,7 @@ module.exports = Object.freeze({
|
||||
SESSION_SVR_GET_SESSIONS: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/get_sessions',
|
||||
SESSION_SVR_SINGLE_UNREAD: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread',
|
||||
SESSION_SVR_UPDATE_ACK: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/update_ack',
|
||||
SHORTLINK: 'https://b23.tv/{{short_id}}',
|
||||
SPACE_MYINFO: 'https://api.bilibili.com/x/space/myinfo',
|
||||
TAG_INFO: 'https://api.bilibili.com/x/tag/info',
|
||||
TOP_FEED_RCMD: "https://api.bilibili.com/x/web-interface/index/top/feed/rcmd",
|
||||
|
||||
+116
-39
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -378,31 +387,90 @@ const bili_client = {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @param {string} short_id
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async shortDynamicIdToDyid(short_id) {
|
||||
return get({
|
||||
url: API.SHORTLINK.replace('{{short_id}}', short_id),
|
||||
config: {
|
||||
redirect: false,
|
||||
}
|
||||
}).then(a => {
|
||||
const dyid = (a.match(/[0-9]{18}/) || [])[0];
|
||||
log.info("短连接转换", `${short_id} -> ${dyid}`)
|
||||
return dyid
|
||||
})
|
||||
},
|
||||
_getOneDynamicByDyid: new Line('获取一个动态的细节', [
|
||||
(dynamic_id) => get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V2,
|
||||
config: { retry: false },
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}),
|
||||
(dynamic_id) => get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V3,
|
||||
config: { retry: false },
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}),
|
||||
(dynamic_id) => get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V4,
|
||||
config: { retry: false },
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}),
|
||||
(dynamic_id) => get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V5,
|
||||
config: { retry: false },
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}),
|
||||
(dynamic_id) => get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V6,
|
||||
config: { retry: false },
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}),
|
||||
(dynamic_id) => get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL_V7,
|
||||
config: { retry: false },
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}),
|
||||
], responseText => {
|
||||
const
|
||||
res = strToJson(responseText),
|
||||
{ code, data } = res,
|
||||
{ card } = data || {};
|
||||
switch (code) {
|
||||
case 0:
|
||||
if (card) {
|
||||
return [false, card, `ok`];
|
||||
} else {
|
||||
return [false, undefined, `动态不存在`];
|
||||
}
|
||||
case 500207:
|
||||
return [false, undefined, `该动态为包月充电专属可以给UP主充电后观看`];
|
||||
default:
|
||||
return [true, undefined, `获取动态数据出错:\n${responseText}`]
|
||||
}
|
||||
}),
|
||||
/**
|
||||
* 获取一个动态的细节
|
||||
* @param {string} dynamic_id
|
||||
* @return {Promise<JSON>} 失败返回undefined
|
||||
*/
|
||||
async getOneDynamicByDyid(dynamic_id) {
|
||||
const
|
||||
responseText = await get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL,
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}),
|
||||
{ code, data } = strToJson(responseText),
|
||||
{ card } = data || {};
|
||||
if (code !== 0) {
|
||||
log.error('获取一个动态的细节', `获取动态(${dynamic_id})数据出错:\n${responseText}`);
|
||||
return;
|
||||
}
|
||||
if (!card) {
|
||||
log.warn('获取一个动态的细节', `动态(${dynamic_id})不存在`);
|
||||
return;
|
||||
}
|
||||
log.info('获取一个动态的细节', `动态id(${dynamic_id})`);
|
||||
return card;
|
||||
return this._getOneDynamicByDyid.run(dynamic_id)
|
||||
},
|
||||
/**
|
||||
* 获取一组动态的信息
|
||||
@@ -572,7 +640,7 @@ const bili_client = {
|
||||
if (res.code === 0) {
|
||||
return [false, res.data.follower, 'ok'];
|
||||
} else {
|
||||
return [true, 1, `出错 可能是访问过频繁\n${responseText}`]
|
||||
return [true, -1, `出错 可能是访问过频繁\n${responseText}`]
|
||||
}
|
||||
}),
|
||||
/**
|
||||
@@ -588,7 +656,7 @@ const bili_client = {
|
||||
* @param {string} dyid
|
||||
* 动态id
|
||||
* @typedef LotteryNotice
|
||||
* @property {number | -1} ts
|
||||
* @property {number} ts
|
||||
* @returns {Promise<LotteryNotice>} 开奖时间
|
||||
*/
|
||||
async getLotteryNotice(dyid) {
|
||||
@@ -600,15 +668,21 @@ const bili_client = {
|
||||
}
|
||||
}),
|
||||
res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
return {
|
||||
ts: res.data.lottery_time
|
||||
};
|
||||
} else {
|
||||
log.error('获取开奖信息', `失败\n${responseText}`);
|
||||
return {
|
||||
ts: -1
|
||||
};
|
||||
switch (res.code) {
|
||||
case 0:
|
||||
return {
|
||||
ts: res.data.lottery_time
|
||||
};
|
||||
case -9999:
|
||||
log.warn('获取开奖信息', `${dyid}已撤销抽奖`);
|
||||
return {
|
||||
ts: -9999
|
||||
};
|
||||
default:
|
||||
log.error('获取开奖信息', `${dyid}失败\n${responseText}`);
|
||||
return {
|
||||
ts: -1
|
||||
};
|
||||
}
|
||||
},
|
||||
_autoAttention: new Line('自动关注', [
|
||||
@@ -1073,7 +1147,10 @@ const bili_client = {
|
||||
case 0:
|
||||
log.info('查询评论', `成功`);
|
||||
try {
|
||||
return res.data.replies.map(it => [it.member.uname, it.content.message]);
|
||||
const upmid = res.data.upper.mid;
|
||||
return res.data.replies
|
||||
.filter(it => it.mid !== upmid)
|
||||
.map(it => [it.member.uname, it.content.message]);
|
||||
} catch (_) {
|
||||
return []
|
||||
}
|
||||
@@ -1100,7 +1177,7 @@ const bili_client = {
|
||||
if (res.code === 0) {
|
||||
const data = res.data.filter((it) => it.name === name);
|
||||
if (data.length) {
|
||||
log.info('获取分区id', '成功');
|
||||
log.info('获取分区id', `成功 ${name}`);
|
||||
tagid = data[0].tagid;
|
||||
} else {
|
||||
log.warn('获取分区id', `失败 无指定分区名${name}`);
|
||||
@@ -1167,10 +1244,10 @@ const bili_client = {
|
||||
res.data.forEach(d => {
|
||||
uids.push(d.mid);
|
||||
});
|
||||
log.info(`获取分组${tagid}`, `成功获取取关分区列表${n}`);
|
||||
log.info(`获取分组id${tagid}`, `成功获取取关分区列表${n}`);
|
||||
return uids;
|
||||
} else {
|
||||
log.error(`获取分组${tagid}`, `获取取关分区列表失败\n${responseText}`);
|
||||
log.error(`获取分组id${tagid}`, `获取取关分区列表失败\n${responseText}`);
|
||||
return uids;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-5
@@ -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 = '';
|
||||
|
||||
@@ -403,6 +403,7 @@ module.exports = Object.freeze({
|
||||
/**
|
||||
* - 取关分区
|
||||
* - 默认为: 此处存放因抽奖临时关注的up
|
||||
* - 可用逗号分割以取关多分区
|
||||
*/
|
||||
clear_partition: '',
|
||||
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lottery-auto-script",
|
||||
"version": "2.7.4",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
const assert = require('assert');
|
||||
const bili_client = require("../lib/net/bili");
|
||||
const util = require('./util');
|
||||
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)
|
||||
@@ -13,7 +14,7 @@ const util = require('./util');
|
||||
// 1
|
||||
async () => {
|
||||
assert.equal(await bili_client.sendChat(
|
||||
(await bili_client.getOneDynamicByDyid("692193323569381399")).desc.rid,
|
||||
parseDynamicCard(await bili_client.getOneDynamicByDyid("692193323569381399")).rid_str,
|
||||
"test",
|
||||
11),
|
||||
7
|
||||
@@ -22,7 +23,7 @@ const util = require('./util');
|
||||
// 2
|
||||
async () => {
|
||||
assert.equal(await bili_client.sendChat(
|
||||
(await bili_client.getOneDynamicByDyid("11229466874154064")).desc.rid,
|
||||
parseDynamicCard(await bili_client.getOneDynamicByDyid("11229466874154064")).rid_str,
|
||||
"test",
|
||||
1),
|
||||
3
|
||||
@@ -43,7 +44,7 @@ const util = require('./util');
|
||||
// 6
|
||||
async () => {
|
||||
assert.equal(await bili_client.autolike("761391835139538967"), 4)
|
||||
}
|
||||
},
|
||||
])
|
||||
|
||||
console.log("api.test ... ok!");
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
const assert = require('assert');
|
||||
const bili_client = require("../lib/net/bili");
|
||||
const util = require('./util');
|
||||
|
||||
(async () => {
|
||||
await util.par_run([0], [
|
||||
// 0
|
||||
async () => {
|
||||
let info = await bili_client.getOneArticleByCv(22112353);
|
||||
let short_ids = [...new Set(info.match(/(?<=b23.tv\/)[a-zA-Z0-9]{7}/g) || [])];
|
||||
assert.equal((await Promise.all(short_ids.map(bili_client.shortDynamicIdToDyid)))[0], "767357823884460033");
|
||||
},
|
||||
])
|
||||
console.log("article.test ... ok!");
|
||||
})()
|
||||
@@ -4,7 +4,7 @@ const searcher = require("../lib/core/searcher");
|
||||
const util = require('./util');
|
||||
|
||||
(async () => {
|
||||
await util.par_run([0, 1, 2, 3], [
|
||||
await util.par_run([0, 1, 2, 3, 4, 5, 6], [
|
||||
// 0
|
||||
async () => {
|
||||
let info = await bili_client.getOneDynamicByDyid("728424890210713624");
|
||||
@@ -29,10 +29,28 @@ const util = require('./util');
|
||||
assert(card.chat_type == 17)
|
||||
assert(card.origin_chat_type == 11)
|
||||
},
|
||||
// 4
|
||||
async () => {
|
||||
assert.equal(await bili_client.getOneDynamicByDyid("111111111111111111"), undefined);
|
||||
assert.notEqual(await bili_client.getOneDynamicByDyid("746824225190314008"), undefined);
|
||||
assert.equal(await bili_client.getOneDynamicByDyid("761475750233636886"), undefined);
|
||||
},
|
||||
// 5
|
||||
async () => {
|
||||
let card = searcher.parseDynamicCard(await bili_client.getOneDynamicByDyid("762591475338838053"));
|
||||
let chats = await bili_client.getChat(card.rid_str, card.chat_type)
|
||||
assert.equal(chats.length, 19)
|
||||
card = searcher.parseDynamicCard(await bili_client.getOneDynamicByDyid("762502724122050647"));
|
||||
chats = await bili_client.getChat(card.rid_str, card.chat_type)
|
||||
assert.equal(chats.filter(it => it[0] === '六的月').length, 0)
|
||||
},
|
||||
// 6
|
||||
async () => {
|
||||
const dy = await bili_client.getOneDynamicByDyid("774973685666676768");
|
||||
const card = searcher.parseDynamicCard(dy)
|
||||
assert.notEqual(card.description + "", undefined + "");
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
|
||||
|
||||
console.log("dynamic_card.test ... ok!");
|
||||
})()
|
||||
+2
-1
@@ -3,10 +3,11 @@ const global_var = require("../lib/data/global_var");
|
||||
const { log } = require('../lib/utils');
|
||||
const fs = require('fs');
|
||||
|
||||
log._level = 1
|
||||
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}`))
|
||||
@@ -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 + "×tamp=" + timestamp]
|
||||
]
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
success: (res) => { resolve(JSON.parse(res.body)) },
|
||||
failure: resolve
|
||||
})
|
||||
}));
|
||||
console.log("proxy.test ... ok!");
|
||||
}
|
||||
},
|
||||
])
|
||||
})()
|
||||
Reference in New Issue
Block a user