Compare commits

..
3 Commits
Author SHA1 Message Date
shanmite ef822df5bf fix: 两处潜在问题
- 存储专栏获取结果
- 专栏获取为null
2021-08-17 18:43:59 +08:00
shanmite 9842107f52 fix: (#14) 2021-08-16 13:00:12 +08:00
shanmite 89dea18ae3 feat: 账号异常时切换线路 2021-08-16 12:51:21 +08:00
9 changed files with 94 additions and 60 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ async function isMe() {
log.info('可能中奖了', desp);
await sendNotify('可能中奖了', desp);
} else {
log.info('中奖检测', "未中奖");
log.info('中奖检测', "未中奖");
}
return;
}
+1
View File
@@ -60,6 +60,7 @@ class Monitor extends Searcher {
if (!config.is_exception) {
await sendNotify('[动态抽奖]账号异常通知', `UID: ${global_var.get('myUID')}\n\n临时进入只转已关注模式(异常号只会对部分UP出现关注异常)\n\n可在设置中令is_exception为true关闭此推送`)
}
config.is_exception = true;
event_bus.emit('Turn_on_the_Monitor')
break
case 31:
+10 -3
View File
@@ -294,7 +294,9 @@ class Searcher {
log.info('获取动态', `开始获取含关键词${key_words}的专栏信息`);
const cvs = (await bili.searchArticlesByKeyword(key_words)).slice(0, config.article_scan_page);
/**存储所有专栏中的dyid */
let dyinfos = [];
/**遍历专栏s */
for (const cv of cvs) {
const
content = await bili.getOneArticleByCv(cv),
@@ -304,8 +306,12 @@ class Searcher {
weight = dyids_set.length / 2;
let { length } = dyids_set,
_weight = 0;
/**初始权重 */
_weight = 0,
/**单个专栏中的dyid */
_dyinfos = [];
log.info('获取动态', `提取专栏(${cv})中提及的dyid(${length})`)
/**遍历某专栏中的dyids */
for (const dyid of dyids_set) {
const isRelayed = await d_storage.searchDyid(dyid);
if (isRelayed) {
@@ -313,7 +319,7 @@ class Searcher {
}
if (_weight >= weight) {
log.warn('获取动态', `1/2动态曾经转过,该专栏或已查看,故中止`)
dyinfos = []
_dyinfos = []
break
}
if (dyid.length === utils.dyid_length) {
@@ -331,7 +337,7 @@ class Searcher {
await utils.delay(2000)
if (card) {
dyinfos.push(parseDynamicCard(card));
_dyinfos.push(parseDynamicCard(card));
}
} else {
log.info('获取动态', `动态(${dyid})已转发过 (${length--})`)
@@ -340,6 +346,7 @@ class Searcher {
log.warn('获取动态', `动态(${dyid})无效 (${length--})`)
}
}
dyinfos.push(..._dyinfos)
}
const fomatdata = dyinfos.map(o => {
return {
+41 -41
View File
@@ -202,10 +202,10 @@ function serverNotify(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.errno === 0) {
log.info('发送通知', 'server酱发送通知消息成功\n')
log.info('发送通知', 'server酱发送通知消息成功')
} else if (data.errno === 1024) {
// 一分钟内发送相同的内容会触发
log.error('发送通知', `server酱发送通知消息异常: ${data.errmsg}\n`)
log.error('发送通知', `server酱发送通知消息异常: ${data.errmsg}`)
} else {
log.error('发送通知', `server酱发送通知消息异常\n${JSON.stringify(data)}`)
}
@@ -216,12 +216,12 @@ function serverNotify(text, desp) {
}
},
failure: err => {
log.error('发送通知', 'server酱 发送通知调用API失败!!\n')
log.error('发送通知', 'server酱 发送通知调用API失败!!')
throw new Error(err);
}
})
} else {
log.debug('发送通知', '您未提供server酱的SCKEY,取消微信推送消息通知\n');
log.debug('发送通知', '您未提供server酱的SCKEY,取消微信推送消息通知');
resolve()
}
})
@@ -247,7 +247,7 @@ function serverNotifyTurbo(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.code === 0) {
log.info('发送通知', 'server酱(Turbo版)发送通知消息成功\n')
log.info('发送通知', 'server酱(Turbo版)发送通知消息成功')
} else {
log.error('发送通知', `server酱(Turbo版)发送通知消息异常\n${JSON.stringify(data)}`)
}
@@ -258,12 +258,12 @@ function serverNotifyTurbo(text, desp) {
}
},
failure: err => {
log.error('发送通知', 'server酱(Turbo版) 发送通知调用API失败!!\n')
log.error('发送通知', 'server酱(Turbo版) 发送通知调用API失败!!')
throw new Error(err);
}
})
} else {
log.debug('发送通知', '您未提供server酱(Turbo版)的SCKEY,取消微信推送消息通知\n');
log.debug('发送通知', '您未提供server酱(Turbo版)的SCKEY,取消微信推送消息通知');
resolve()
}
})
@@ -301,9 +301,9 @@ function coolPush(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.code === 200) {
log.info('发送通知', `酷推发送${pushMode(QQ_MODE)}通知消息成功\n`)
log.info('发送通知', `酷推发送${pushMode(QQ_MODE)}通知消息成功`)
} else if (data.code === 400) {
log.error('发送通知', `QQ酷推(Cool Push)发送${pushMode(QQ_MODE)}推送失败:${data}\n`)
log.error('发送通知', `QQ酷推(Cool Push)发送${pushMode(QQ_MODE)}推送失败:${data}`)
} else {
log.error('发送通知', `酷推推送异常: ${data.msg}`);
}
@@ -314,12 +314,12 @@ function coolPush(text, desp) {
}
},
failure: err => {
log.error('发送通知', `酷推 发送${pushMode(QQ_MODE)}通知调用API失败!!\n`)
log.error('发送通知', `酷推 发送${pushMode(QQ_MODE)}通知调用API失败!!`)
throw new Error(err);
}
})
} else {
log.debug('发送通知', '您未提供酷推的SKEY,取消QQ推送消息通知\n');
log.debug('发送通知', '您未提供酷推的SKEY,取消QQ推送消息通知');
resolve()
}
})
@@ -345,9 +345,9 @@ function barkNotify(text, desp, params = {}) {
try {
const data = JSON.parse(res.body);
if (data.code === 200) {
log.info('发送通知', 'Bark APP发送通知消息成功\n')
log.info('发送通知', 'Bark APP发送通知消息成功')
} else {
log.error('发送通知', `${data.message}\n`);
log.error('发送通知', `${data.message}`);
}
} catch (error) {
log.error('发送通知', error);
@@ -356,13 +356,13 @@ function barkNotify(text, desp, params = {}) {
}
},
failure: err => {
log.error('发送通知', 'Bark APP发送通知调用API失败!!\n');
log.error('发送通知', 'Bark APP发送通知调用API失败!!');
resolve();
throw new Error(err)
}
})
} else {
log.debug('发送通知', '您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知\n');
log.debug('发送通知', '您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知');
resolve()
}
})
@@ -391,11 +391,11 @@ function tgBotNotify(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.ok) {
log.info('发送通知', 'Telegram发送通知消息完成。\n')
log.info('发送通知', 'Telegram发送通知消息完成。')
} else if (data.error_code === 400) {
log.error('发送通知', '请主动给bot发送一条消息并检查接收用户ID是否正确。\n')
log.error('发送通知', '请主动给bot发送一条消息并检查接收用户ID是否正确。')
} else if (data.error_code === 401) {
log.error('发送通知', 'Telegram bot token 填写错误。\n')
log.error('发送通知', 'Telegram bot token 填写错误。')
}
} catch (error) {
log.error('发送通知', error);
@@ -404,7 +404,7 @@ function tgBotNotify(text, desp) {
}
},
failure: err => {
log.error('发送通知', 'telegram发送通知消息失败!!\n')
log.error('发送通知', 'telegram发送通知消息失败!!')
resolve()
throw new Error(err)
}
@@ -417,7 +417,7 @@ function tgBotNotify(text, desp) {
}
send(options)
} else {
log.debug('发送通知', '您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知\n');
log.debug('发送通知', '您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知');
resolve()
}
})
@@ -456,9 +456,9 @@ function ddBotNotify(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.errcode === 0) {
log.info('发送通知', '钉钉发送通知消息完成。\n')
log.info('发送通知', '钉钉发送通知消息完成。')
} else {
log.error('发送通知', `${data.errmsg}\n`)
log.error('发送通知', `${data.errmsg}`)
}
} catch (e) {
log.error('发送通知', e);
@@ -467,7 +467,7 @@ function ddBotNotify(text, desp) {
}
},
failure: err => {
log.error('发送通知', '钉钉发送通知消息失败!!\n')
log.error('发送通知', '钉钉发送通知消息失败!!')
throw new Error(err);
}
})
@@ -495,9 +495,9 @@ function ddBotNotify(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.errcode === 0) {
log.info('发送通知', '钉钉发送通知消息完成。\n')
log.info('发送通知', '钉钉发送通知消息完成。')
} else {
log.error('发送通知', `${data.errmsg}\n`)
log.error('发送通知', `${data.errmsg}`)
}
} catch (e) {
log.error('发送通知', e);
@@ -506,13 +506,13 @@ function ddBotNotify(text, desp) {
}
},
failure: err => {
log.error('发送通知', '钉钉发送通知消息失败!!\n');
log.error('发送通知', '钉钉发送通知消息失败!!');
resolve();
throw new Error(err)
}
})
} else {
log.debug('发送通知', '您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知\n');
log.debug('发送通知', '您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知');
resolve()
}
})
@@ -541,9 +541,9 @@ function qywxBotNotify(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.errcode === 0) {
log.info('发送通知', '企业微信发送通知消息完成。\n');
log.info('发送通知', '企业微信发送通知消息完成。');
} else {
log.error('发送通知', `${data.errmsg}\n`);
log.error('发送通知', `${data.errmsg}`);
}
} catch (e) {
log.error('发送通知', e);
@@ -552,13 +552,13 @@ function qywxBotNotify(text, desp) {
}
},
failure: err => {
log.error('发送通知', '企业微信发送通知消息失败!!\n');
log.error('发送通知', '企业微信发送通知消息失败!!');
resolve();
throw new Error(err)
}
})
} else {
log.debug('发送通知', '您未提供企业微信机器人推送所需的QYWX_KEY,取消企业微信推送消息通知\n');
log.debug('发送通知', '您未提供企业微信机器人推送所需的QYWX_KEY,取消企业微信推送消息通知');
resolve();
}
});
@@ -570,7 +570,7 @@ function iGotNotify(text, desp, params = {}) {
// 校验传入的IGOT_PUSH_KEY是否有效
const IGOT_PUSH_KEY_REGX = new RegExp("^[a-zA-Z0-9]{24}$")
if (!IGOT_PUSH_KEY_REGX.test(IGOT_PUSH_KEY)) {
log.error('发送通知', '您所提供的IGOT_PUSH_KEY无效\n')
log.error('发送通知', '您所提供的IGOT_PUSH_KEY无效')
resolve()
return
}
@@ -593,9 +593,9 @@ function iGotNotify(text, desp, params = {}) {
try {
const data = JSON.parse(res.body);
if (data.ret === 0) {
log.info('发送通知', 'iGot发送通知消息成功\n')
log.info('发送通知', 'iGot发送通知消息成功')
} else {
log.error('发送通知', `iGot发送通知消息失败:${data.errMsg}\n`)
log.error('发送通知', `iGot发送通知消息失败:${data.errMsg}`)
}
} catch (e) {
log.error('发送通知', e);
@@ -604,13 +604,13 @@ function iGotNotify(text, desp, params = {}) {
}
},
failure: err => {
log.error('发送通知', 'iGot 发送通知调用API失败!!\n')
log.error('发送通知', 'iGot 发送通知调用API失败!!')
resolve();
throw new Error(err)
}
})
} else {
log.debug('发送通知', '您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知\n');
log.debug('发送通知', '您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知');
resolve()
}
})
@@ -639,9 +639,9 @@ function pushPlusNotify(text, desp) {
try {
const data = JSON.parse(res.body);
if (data.code === 200) {
log.info('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息完成。\n`)
log.info('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息完成。`)
} else {
log.error('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败:${data.msg}\n`)
log.error('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败:${data.msg}`)
}
} catch (e) {
log.error('发送通知', e);
@@ -650,13 +650,13 @@ function pushPlusNotify(text, desp) {
}
},
failure: err => {
log.error('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败!!\n`)
log.error('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败!!`)
resolve();
throw new Error(err)
}
})
} else {
log.debug('发送通知', '您未提供push+推送所需的PUSH_PLUS_TOKEN,取消push+推送消息通知\n');
log.debug('发送通知', '您未提供push+推送所需的PUSH_PLUS_TOKEN,取消push+推送消息通知');
resolve()
}
})
@@ -684,7 +684,7 @@ async function email(text, desp) {
}
log.info('发送通知', 'email发送成功');
} else {
log.debug('发送通知', '您未提供email推送所需的所有参数故取消email推送消息通知\n');
log.debug('发送通知', '您未提供email推送所需的所有参数故取消email推送消息通知');
}
}
+20 -8
View File
@@ -349,8 +349,15 @@ const bili_client = {
}).then(responseText => {
const res = JSON.parse(responseText);
if (res.code === 0) {
log.info('搜索专栏', '成功 关键词: ' + keyword)
return res.data.result.map(it => it.id)
let cv_arr = []
try {
log.info('搜索专栏', '成功 关键词: ' + keyword)
cv_arr = res.data.result.map(it => it.id)
} catch (error) {
log.error('搜索专栏', '失败 原因:\n' + responseText)
cv_arr = []
}
return cv_arr
} else {
log.error('搜索专栏', '失败 原因:\n' + responseText)
return []
@@ -476,23 +483,23 @@ const bili_client = {
contents: {
fid: uid,
act: 1,
re_src: 11,
re_src: 0,
csrf: GlobalVar.get("csrf")
}
}).then(responseText => {
let _responseText = ''
/* 重复关注code also equal 0 */
const res = strToJson(responseText)
_responseText += responseText
if (res.code === 0) {
log.info('自动关注', '关注+1');
return 0
} else if (res.code === 22002) {
log.error('自动关注', '您已被对方拉入黑名单');
return 1
} else if (res.code === 22015) {
log.error('自动关注', '您的账号异常无法关注');
return 2
} else {
log.warn('自动关注', `失败 尝试切换线路\n${responseText}`);
_responseText += responseText
return post({
url: API.FEED_SETUSERFOLLOW,
contents: {
@@ -506,12 +513,13 @@ const bili_client = {
return 0
} else {
log.warn('自动关注', `失败 尝试切换另一条线路\n${responseText}`);
_responseText += responseText
return post({
url: API.RELATION_BATCH_MODIFY,
contents: {
fid: uid,
act: 1,
re_src: 11,
re_src: 0,
csrf: GlobalVar.get("csrf")
}
}).then(responseText => {
@@ -520,6 +528,10 @@ const bili_client = {
return 0
} else {
log.error('自动关注', `失败\n${responseText}`);
_responseText += responseText
if (_responseText.includes(22015)) {
return 2
}
return 1
}
})
@@ -569,7 +581,7 @@ const bili_client = {
contents: {
fid: uid,
act: 2,
re_src: 11,
re_src: 0,
csrf: GlobalVar.get("csrf")
}
}).then(responseText => {
+2 -2
View File
@@ -193,11 +193,11 @@ const utils = {
},
warn(context, msg) {
if (this.level > 1)
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Warn]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#BBBB23')(`[${msg}]`)])
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Warn]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#BBBB23')(`[\n${msg}\n]`)])
},
error(context, msg) {
if (this.level > 0)
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Error]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#FF0006')(`[${msg}]`)])
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Error]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#FF0006')(`[\n${msg}\n]`)])
}
},
/**
+1 -1
View File
@@ -128,7 +128,7 @@ async function main() {
const err_msg = await main();
if (err_msg) {
log.error('错误', '\n' + err_msg + '\n');
log.error('错误', err_msg);
log.warn('结束运行', '5秒后自动退出');
await delay(5 * 1000);
} else {
+12 -4
View File
@@ -1,6 +1,6 @@
{
"name": "lottery-auto-script",
"version": "2.0.8",
"version": "2.1.0",
"description": "自动参与B站动态抽奖",
"main": "main.js",
"scripts": {
@@ -8,11 +8,19 @@
"clear": "node main.js clear",
"check": "node main.js check",
"update": "node main.js update",
"pkg_x64": "npx pkg . && PowerShell .\\script\\pkg\\pkg.ps1",
"pkg_clean_dist": "PowerShell -Command \"& {Remove-Item -Path .\\dist\\ -Recurse}\"",
"pkg_x64": "PowerShell .\\script\\pkg\\pkg.ps1",
"pkg_arm64": "npx pkg -t linux-arm64 -o dist/lottery main.js && cp my_config.example.js my_config.js && cp env.example.js dist/env.js",
"pkg_armv7": "npx pkg -t linux-armv7 -o dist/lottery main.js && cp my_config.example.js my_config.js && cp env.example.js dist/env.js"
},
"files": [
"lib",
"main.js",
"package.js",
"my_config.example.js",
"env.example.js",
"LICENSE",
"README.md"
],
"bin": "main.js",
"pkg": {
"targets": [
@@ -44,4 +52,4 @@
"chalk": "^4.1.1",
"nodemailer": "^6.5.0"
}
}
}
+6
View File
@@ -15,6 +15,12 @@ $TRIARR = @(
@("$NAME-macos", "lottery", "nlts-macos-x64")
)
if((Test-Path $TARGET_DIR) -eq "True") {
Remove-Item -Path $TARGET_DIR -Recurse
}
npx pkg .
Copy-Item -Path $TEMPLATE_ENV_FILE -Destination $TARGET_DIR -Force
Copy-Item -Path $TEMPLATE_CONFIG_FILE -Destination $TARGET_DIR -Force
Copy-Item -Path $README -Destination $TARGET_DIR -Force