Compare commits

...
8 Commits
Author SHA1 Message Date
shanmite a426eb48f5 fix: 账号异常处理 2021-08-14 20:14:35 +08:00
shanmite c06f69457a pref: 时区+8(#13) 2021-08-14 13:24:54 +08:00
shanmite 155332751f fix: 解构赋初值异常 2021-08-14 13:02:46 +08:00
shanmite a28ec20b12 feat: 检查更新
fix: tag在中间的情况
2021-08-13 12:32:54 +08:00
shanmite 35cb1c24c2 fix: lib/main[48:9] 2021-08-09 14:52:41 +08:00
shanmite 4f961250be feat: 不参与主站黑名单用户抽奖 2021-08-09 13:48:44 +08:00
shanmite dce1ff61fd fix: 可从环境变量中读取COOKIE 2021-08-09 11:32:45 +08:00
shanmite ab6bc97f50 chore: 部分修改 2021-08-09 10:49:33 +08:00
16 changed files with 232 additions and 213 deletions
-123
View File
@@ -1,123 +0,0 @@
{
"HttpRequest-get": {
"scope": "javascript,typescript",
"prefix": "hrget",
"body": [
"HttpRequest({",
" method: 'GET',",
" url: '$1',",
" query: {",
" $2",
" },",
" headers: {",
" accept: 'application/json, text/plain, */*',",
" cookie: '$3',",
" },",
" success: res => {",
" $4",
" },",
" failure: err => {",
" $5",
" }",
"})$6"
],
"description": "简化http-get请求"
},
"HttpRequest-post": {
"scope": "javascript,typescript",
"prefix": "hrpost",
"body": [
"HttpRequest({",
" method: 'POST',",
" url: '$1',",
" contents: {",
" $2",
" },",
" headers: {",
" accept: 'application/json, text/plain, */*',",
" 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',",
" cookie: '$3',",
" },",
" success: res => {",
" $4",
" },",
" failure: err => {",
" $5",
" }",
"})$6"
],
"description": "简化http-post请求"
},
"CORSajax-get": {
"scope": "javascript,typescript",
"prefix": "corsget",
"body": [
"CORSajax.get({",
" proxy_link: '$1',",
" proxy_querystring: {",
" $2",
" },",
" proxy_headers: {",
" Cookie: '$3'",
" },",
"},chunk => {",
" $4",
"})$5"
],
"description": "简化跨域Ajax本地nodejsのget代理"
},
"CORSajax-post": {
"scope": "javascript,typescript",
"prefix": "corspost",
"body": [
"CORSajax.post({",
" proxy_link: '$1',",
" proxy_headers: {",
" 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',",
" cookie: '$2'",
" },",
" proxy_body: {",
" $3",
" },",
"},chunk => {",
" $4",
"})$5"
],
"description": "简化跨域Ajax本地nodejsのpost代理"
},
"Ajax-get": {
"scope": "javascript,typescript",
"prefix": "myget",
"body": [
"Ajax.get({",
" url: '$1',",
" queryStringsObj: {",
" $2",
" },",
" hasCookies: true,",
" success: responseText => {",
" $3",
" }",
"})",
],
"description": "简化AjaxのGet请求"
},
"Ajax-post": {
"scope": "javascript,typescript",
"prefix": "mypost",
"body": [
"Ajax.post({",
" url: '$1',",
" hasCookies: true,",
" dataType: 'application/x-www-form-urlencoded',",
" data: {",
" $2",
" },",
" success: responseText => {",
" $3",
" }",
"})",
],
"description": "简化Ajaxのpost请求"
},
}
-14
View File
@@ -1,14 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "启动程序",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
+13 -5
View File
@@ -24,10 +24,12 @@
- 自动点赞、评论、乱序转发、@好友、带话题、可选随机动态
- 检测是否中奖
- 清理动态关注
- 检查更新
- 更多功能设置请参考配置文件
**声明**: 此脚本仅用于学习和测试,作者本人并不对其负责,请于运行测试完成后自行删除,请勿滥用!
----------------------------------------
---------------------------------
## 操作步骤
@@ -75,11 +77,17 @@ Chrome浏览器:
### 本地运行
#### 可执行文件
1. [[下载](https://github.com/shanmiteko/LotteryAutoScript/releases)|[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript/releases)|[Fastgit镜像下载](https://hub.fastgit.org/shanmiteko/LotteryAutoScript/releases)]压缩包并解压后有三个文件
1. [[下载](https://github.com/shanmiteko/LotteryAutoScript/releases)|[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript/releases)|[Fastgit镜像下载](https://hub.fastgit.org/shanmiteko/LotteryAutoScript/releases)]压缩包并解压后
```
env.js 便捷设置环境变量和多账号参数
lottery.exe 可执行文件
my_config.js 自定义设置文件
~/nlts-linux-x64
=> tree
.
├── dyids (自动生成的dyid存储)
│   └── dyid.txt
├── env.js (便捷设置环境变量和多账号参数)
├── lottery (可执行文件)
├── my_config.js (自定义设置文件) (!使用前必读)
└── README.md (说明文件)
```
2. 用记事本或其他编辑器修改`env.js`和`my_config.js`文件(右键选择用记事本打开)
3. 在`env.js`中填入`COOKIE`和推送参数
+7 -7
View File
@@ -2,19 +2,19 @@ const { log, delay, infiniteNumber, judge } = require('./utils')
const { sendNotify } = require('./helper/notify')
const config = require('./data/config')
const global_var = require('./data/global_var')
const bili_client = require('./net/bili')
const bili = require('./net/bili')
/**
* 是否中奖
*/
async function isMe() {
let desp = '';
const UnreadAtNum = await bili_client.getUnreadAtNum();
const UnreadSessionNum = await bili_client.getUnreadSessionNum();
const UnreadAtNum = await bili.getUnreadAtNum();
const UnreadSessionNum = await bili.getUnreadSessionNum();
const { follow_unread, unfollow_unread } = UnreadSessionNum || { unfollow_unread: 0, follow_unread: 0 };
if (UnreadAtNum > 0) {
log.info('中奖检测', '<-- 正在检查at');
const MyAtInfo = await bili_client.getMyAtInfo();
const MyAtInfo = await bili.getMyAtInfo();
MyAtInfo.forEach(async AtInfo => {
const { at_time, up_uname, business, source_content, url } = AtInfo
desp += `发生时间: ${new Date(at_time * 1000).toLocaleString()} \n\n`
@@ -29,13 +29,13 @@ async function isMe() {
if (follow_unread + unfollow_unread > 0) {
const check = async (type) => {
let session_t = '';
let MySession = await bili_client.getSessionInfo(type)
let MySession = await bili.getSessionInfo(type)
for (const index of infiniteNumber()) {
for (const Session of MySession.data) {
const { content, sender_uid, session_ts, timestamp, unread_count, talker_id, msg_seqno } = Session;
session_t = session_ts;
if (unread_count) {
bili_client.updateSessionStatus(talker_id, type, msg_seqno);
bili.updateSessionStatus(talker_id, type, msg_seqno);
await delay(1000);
if (judge(content, config.notice_key_words)) {
desp += `发生时间: ${new Date(timestamp * 1000).toLocaleString()} \n\n`
@@ -48,7 +48,7 @@ async function isMe() {
}
if (MySession.has_more && index < 16) {
await delay(3e3);
MySession = await bili_client.getSessionInfo(type, session_t)
MySession = await bili.getSessionInfo(type, session_t)
} else {
break
}
+20 -16
View File
@@ -55,9 +55,10 @@ class Monitor extends Searcher {
event_bus.emit('Turn_on_the_Monitor')
break
case 22:
config.only_followed = true;
log.warn('账号异常', `UID(${global_var.get('myUID')})临时进入只转已关注模式(异常号只会对部分UP出现关注异常)`)
if (!config.is_exception) {
config.is_exception = true;
await sendNotify('[动态抽奖]账号异常通知', `UID: ${global_var.get('myUID')}\n\n已自动跳过异常关注(异常号只会对部分UP出现关注异常)\n\n可在设置中令is_exception为true关闭此推送`)
await sendNotify('[动态抽奖]账号异常通知', `UID: ${global_var.get('myUID')}\n\n临时进入只转已关注模式(异常号只会对部分UP出现关注异常)\n\n可在设置中令is_exception为true关闭此推送`)
}
event_bus.emit('Turn_on_the_Monitor')
break
@@ -116,10 +117,10 @@ class Monitor extends Searcher {
}
}
status = await this.go(Lottery)
if (status % 2 !== 0) {
if (status) {
return status
}
d_storage.updateDyid(Lottery.dyid);
d_storage.updateDyid(Lottery.dyid)
await utils.delay(config.wait * (Math.random() + 0.5));
}
log.info('抽奖', '开始转发下一组动态');
@@ -191,20 +192,20 @@ class Monitor extends Searcher {
const
/**判断是转发源动态还是现动态 */
uid = lottery_info_type === 'uid' ? uids[1] : uids[0]
, isFollowed = (new RegExp(uid)).test(attentionList)
, description = typeof des === 'string' ? des : ''
, needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description)
, needTopic = [...(new Set(description.match(/(?<=[带加上](?:话题|tag).*)#.+?#/ig) || []))].join(' ')
, isRelayDynamic = type === 1
, isTwoLevelDynamic = /\/\/@/.test(description)
, has_key_words = key_words.every(it => new RegExp(it).test(description))
, isBlock = new RegExp(blockword.join('|')).test(description)
, isLottery =
uid = lottery_info_type === 'uid' ? uids[1] : uids[0],
isFollowed = (new RegExp(uid)).test(attentionList),
description = typeof des === 'string' ? des : '',
needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description),
needTopic = [...new Set(description.match(/(?<=[带加上](?:话题|tag).*)#.+?#|(?<=[带加上])#.+?#(?=话题|tag)/ig) || [])].join(' '),
isRelayDynamic = type === 1,
isTwoLevelDynamic = /\/\/@/.test(description),
has_key_words = key_words.every(it => new RegExp(it).test(description)),
isBlock = new RegExp(blockword.join('|')).test(description),
isLottery =
(is_imitator && lottery_info_type === 'uid' && model !== '00')
|| (hasOfficialLottery && model[0] === '1')
|| (!hasOfficialLottery && model[1] === '1' && !isTwoLevelDynamic && has_key_words)
, isSendChat =
|| (!hasOfficialLottery && model[1] === '1' && !isTwoLevelDynamic && has_key_words),
isSendChat =
(is_imitator && lottery_info_type === 'uid' && chatmodel !== '00')
|| (hasOfficialLottery && chatmodel[0] === '1')
|| (!hasOfficialLottery && chatmodel[1] === '1');
@@ -326,6 +327,9 @@ class Monitor extends Searcher {
const max_retry_times = 5;
for (let times = 0; times < max_retry_times; times++) {
status = await bili.sendChat(rid, utils.getRandomOne(config.chat), chat_type)
if (status === -1) {
return 0
}
if (!status) {
break
}
+4 -4
View File
@@ -86,8 +86,8 @@ function parseDynamicCard(dynamic_detail_card) {
*/
function modifyDynamicRes(res) {
const
{ data = {}, code } = utils.strToJson(res),
{ cards = [], has_more, offset } = data;
{ data, code } = utils.strToJson(res),
{ cards = [], has_more, offset } = data || {};
if (code !== 0) {
log.error('处理动态数据', '获取动态数据出错,可能是访问太频繁 \n' + res);
@@ -320,8 +320,8 @@ class Searcher {
if (!isRelayed) {
log.info('获取动态', `查看动态(${dyid})的细节 (${length--})`)
const res = await bili.getOneDynamicByDyid(dyid)
, { code, data = {} } = utils.strToJson(res)
, { card } = data;
, { code, data } = utils.strToJson(res)
, { card } = data || {};
if (code !== 0) {
log.error('获取动态', '获取动态数据出错,可能是访问太频繁 \n' + res)
+10 -10
View File
@@ -221,7 +221,7 @@ function serverNotify(text, desp) {
}
})
} else {
log.warn('发送通知', '您未提供server酱的SCKEY,取消微信推送消息通知\n');
log.debug('发送通知', '您未提供server酱的SCKEY,取消微信推送消息通知\n');
resolve()
}
})
@@ -263,7 +263,7 @@ function serverNotifyTurbo(text, desp) {
}
})
} else {
log.warn('发送通知', '您未提供server酱(Turbo版)的SCKEY,取消微信推送消息通知\n');
log.debug('发送通知', '您未提供server酱(Turbo版)的SCKEY,取消微信推送消息通知\n');
resolve()
}
})
@@ -319,7 +319,7 @@ function coolPush(text, desp) {
}
})
} else {
log.warn('发送通知', '您未提供酷推的SKEY,取消QQ推送消息通知\n');
log.debug('发送通知', '您未提供酷推的SKEY,取消QQ推送消息通知\n');
resolve()
}
})
@@ -362,7 +362,7 @@ function barkNotify(text, desp, params = {}) {
}
})
} else {
log.warn('发送通知', '您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知\n');
log.debug('发送通知', '您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知\n');
resolve()
}
})
@@ -417,7 +417,7 @@ function tgBotNotify(text, desp) {
}
send(options)
} else {
log.warn('发送通知', '您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知\n');
log.debug('发送通知', '您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知\n');
resolve()
}
})
@@ -512,7 +512,7 @@ function ddBotNotify(text, desp) {
}
})
} else {
log.warn('发送通知', '您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知\n');
log.debug('发送通知', '您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知\n');
resolve()
}
})
@@ -558,7 +558,7 @@ function qywxBotNotify(text, desp) {
}
})
} else {
log.warn('发送通知', '您未提供企业微信机器人推送所需的QYWX_KEY,取消企业微信推送消息通知\n');
log.debug('发送通知', '您未提供企业微信机器人推送所需的QYWX_KEY,取消企业微信推送消息通知\n');
resolve();
}
});
@@ -610,7 +610,7 @@ function iGotNotify(text, desp, params = {}) {
}
})
} else {
log.warn('发送通知', '您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知\n');
log.debug('发送通知', '您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知\n');
resolve()
}
})
@@ -656,7 +656,7 @@ function pushPlusNotify(text, desp) {
}
})
} else {
log.warn('发送通知', '您未提供push+推送所需的PUSH_PLUS_TOKEN,取消push+推送消息通知\n');
log.debug('发送通知', '您未提供push+推送所需的PUSH_PLUS_TOKEN,取消push+推送消息通知\n');
resolve()
}
})
@@ -684,7 +684,7 @@ async function email(text, desp) {
}
log.info('发送通知', 'email发送成功');
} else {
log.warn('发送通知', '您未提供email推送所需的所有参数故取消email推送消息通知\n');
log.debug('发送通知', '您未提供email推送所需的所有参数故取消email推送消息通知\n');
}
}
+3 -2
View File
@@ -1,10 +1,11 @@
const { isMe } = require('./check');
const { clear } = require('./clear');
const { start } = require('./lottery');
const { update } = require('./update');
const global_var = require('./data/global_var')
const bili = require('./net/bili')
const { log } = require('./utils')
const { sendNotify } = require('./helper/notify')
const { sendNotify } = require('./helper/notify');
/**
* 检查cookie是否有效
@@ -23,4 +24,4 @@ async function checkCookie(num) {
}
module.exports = { start, isMe, clear, checkCookie }
module.exports = { start, isMe, clear, update, checkCookie }
+2 -2
View File
@@ -1,4 +1,4 @@
module.exports = {
module.exports = Object.freeze({
DYNAMIC_LIKE_THUMB: 'https://api.vc.bilibili.com/dynamic_like/v1/dynamic_like/thumb',
DYNAMIC_REPOST_REPOST: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/repost',
DYNAMIC_SVR_CREATE_DRAW: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create_draw',
@@ -29,4 +29,4 @@ module.exports = {
TOPIC_SVR_TOPIC_NEW: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new',
WEB_INTERFACE_CARD: 'https://api.bilibili.com/x/web-interface/card',
WEB_INTERFACE_SEARCH_TYPE: 'https://api.bilibili.com/x/web-interface/search/type',
}
})
+9 -5
View File
@@ -161,8 +161,8 @@ const bili_client = {
const sessions = res.data.session_list || [];
const has_more = res.data.has_more;
const data = sessions.map(session => {
const { session_ts, last_msg = {}, unread_count, talker_id } = session;
const { content = '', timestamp = 0, sender_uid = 0, msg_seqno } = last_msg;
const { session_ts, last_msg, unread_count, talker_id } = session;
const { content = '', timestamp = 0, sender_uid = 0, msg_seqno } = last_msg || {};
return { session_ts, content, timestamp, sender_uid, unread_count, talker_id, msg_seqno }
})
return { has_more, data }
@@ -218,7 +218,7 @@ const bili_client = {
if (res.code === 0) {
log.info('私信已读', `成功 -> talker_id: ${talker_id}`);
} else {
log.error('私信已读', `失败 -> talker_id: ${talker_id}`);
log.error('私信已读', `失败 -> talker_id: ${talker_id}\n${responseText}`);
}
})
},
@@ -724,8 +724,9 @@ const bili_client = {
* 11(有图)
* 17(无图)
* @returns {Promise<number>}
* 0 - 成功
* 1 - 失败
* - 成功 0
* - 失败 1
* - 黑名单 -1
*/
sendChat(rid, msg, type, show = true) {
return post({
@@ -750,6 +751,9 @@ const bili_client = {
} else if (res.code === 12015) {
show && log.error('自动评论', '需要输入验证码');
return 1
} else if (res.code === 12053) {
show && log.error('自动评论', '黑名单用户无法互动');
return -1
} else {
show && log.error('自动评论', `评论失败\n${responseText}`);
return 1
+75
View File
@@ -0,0 +1,75 @@
const { send } = require('./net/http')
const { strToJson, download } = require('./utils')
const { version, checkVersion, log } = require('./utils')
/**
* 获取下载链接
* @param {string} owner
* @param {string} repo
* @returns {Promise<{ download_url: string, text: string }>}
*/
function getLatestReleaseDownloadUrl(owner, repo) {
return new Promise((resolve, reject) => {
send({
url: `https://api.github.com/repos/${owner}/${repo}/releases/latest`,
headers: {
"accept": 'application/vnd.github.v3+json'
},
config: {
retry: false
},
success: ({ body }) => {
const { tag_name, assets, body: text } = strToJson(body)
if (tag_name) {
if (checkVersion(version) < checkVersion(tag_name)) {
const platform = new Map([
['win32', 'win'],
['linux', 'linux'],
['darwin', 'macos']
]).get(process.platform)
if (platform) {
try {
const download_url = assets
.filter(({ name }) => name.includes(platform))
.map(({ browser_download_url }) => browser_download_url)[0]
resolve({ download_url, text })
} catch (err) {
reject(err)
}
} else {
reject(`未找到能在此平台(${process.platform})上运行的版本`)
}
} else {
reject('当前已是最新版本')
}
} else {
reject(body)
}
},
failure: error => {
reject(error)
}
})
});
}
/**
* 半自动更新
*/
async function update() {
try {
const { download_url, text } = await getLatestReleaseDownloadUrl('shanmiteko', 'LotteryAutoScript')
let proxy_url = new URL(download_url)
proxy_url.host = 'download.fastgit.org'
await download(proxy_url.href, 'latest_version.zip')
log.info('更新说明', '\n' + text + '\n')
} catch (error) {
log.error('更新脚本', error)
}
}
module.exports = { update }
+54 -5
View File
@@ -2,11 +2,13 @@ const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const { send } = require("./net/http");
const { version } = require('../package.json');
/**
* 基础工具
*/
const utils = {
version,
/**环境变量设置文件 */
env_file: path.join(process.cwd(), "env.js"),
/**配置文件 */
@@ -15,6 +17,16 @@ const utils = {
dyids_dir: path.join(process.cwd(), "dyids"),
/**dyid长度 */
dyid_length: 18,
/**
* 将版本号转为数字
* @example
* 1.2.3 => 1.0203
* @param {string} version
* @returns {Number}
*/
checkVersion(version) {
return (version.match(/\d.*/)[0]).split('.').reduce((a, v, i) => a + (0.01 ** i) * Number(v), 0)
},
/**
* 安全的将JSON字符串转为对象
* 超出精度的数转为字符串
@@ -154,7 +166,7 @@ const utils = {
},
/**日志 */
log: {
level: 0,
level: 3,
/**
* 初始化默认level为3
*/
@@ -172,22 +184,59 @@ const utils = {
debug(context, msg) {
if (this.level > 3) {
if (msg instanceof Object) msg = JSON.stringify(msg, null, 4);
this.proPrint([chalk.hex('#64B3FF')(`[${Date()}]`), chalk.grey("[Debug]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#0070BB')(`[\n${msg}\n]`)])
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Debug]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#0070BB')(`[\n${msg}\n]`)])
}
},
info(context, msg) {
if (this.level > 2)
this.proPrint([chalk.hex('#64B3FF')(`[${Date()}]`), chalk.grey("[Info]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#48BB31')(`[${msg}]`)])
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Info]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#48BB31')(`[${msg}]`)])
},
warn(context, msg) {
if (this.level > 1)
this.proPrint([chalk.hex('#64B3FF')(`[${Date()}]`), 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')(`[${msg}]`)])
},
error(context, msg) {
if (this.level > 0)
this.proPrint([chalk.hex('#64B3FF')(`[${Date()}]`), 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')(`[${msg}]`)])
}
},
/**
* 下载文件
* @param {string} url
* @param {string} file_name
* @returns {Promise<void | string>}
*/
download(url, file_name) {
return new Promise((resolve, reject) => {
send({
url,
stream: true,
config: {
redirect: true,
retry: false
},
success: ({ resStream }) => {
let recv_length = 0;
const wtbs = fs.createWriteStream(file_name);
resStream.on('data', chuck => {
recv_length += chuck.length
utils.log.proPrint(`已收到:${recv_length} Bytes`)
})
resStream.pipe(wtbs)
wtbs.on('finish', () => {
utils.log.proPrint('下载完成')
resolve()
}).on('error', error => {
wtbs.destroy()
resolve(error)
})
},
failure: error => {
reject(error)
}
})
});
},
/**
* 获取远程设置
* @returns {Promise<JSON>}
+22 -12
View File
@@ -1,4 +1,4 @@
const { env_file, config_file, log, delay, hasFileOrDir } = require("./lib/utils");
const { version: ve, env_file, config_file, log, hasEnv, delay, hasFileOrDir } = require("./lib/utils");
const metainfo = [
` _ _ _ _____ _ _ `,
@@ -10,8 +10,8 @@ const metainfo = [
` __/ | | | `,
` |___/ |_| `,
` `,
` Verison: v2.0.4`,
` Written by shanmite`,
` Verison: v${ve}`,
` Written By shanmite`,
]
/**多账号存储 */
let multiple_account = [];
@@ -44,21 +44,19 @@ async function main() {
/**多账号状态还原 */
process.env.ENABLE_MULTIPLE_ACCOUNT = ENABLE_MULTIPLE_ACCOUNT;
} else {
if (!COOKIE) {
return '请查看README文件, 在env.js指定位置填入cookie'
}
} else if (COOKIE) {
const global_var = require("./lib/data/global_var");
await global_var.init(COOKIE, Number(NUMBER));
const { start, isMe, clear, checkCookie } = require("./lib/index");
/**引入基础功能 */
const { start, isMe, clear, update, checkCookie } = require("./lib/index");
log.info('main', '当前为第' + NUMBER + '个账号');
if (await checkCookie(NUMBER)) {
const mode = process.env.lottery_mode;
const help_msg = "用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tclear 清理动态和关注\n\thelp 帮助信息";
const { lottery_loop_wait, check_loop_wait, clear_loop_wait } = require("./lib/data/config");
const help_msg = "用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tclear 清理动态和关注\n\tupdate 检查更新\n\thelp 帮助信息";
const { lottery_loop_wait, check_loop_wait, clear_loop_wait, update_loop_wait } = require("./lib/data/config");
switch (mode) {
case 'start':
log.info('抽奖', '开始运行');
@@ -77,6 +75,11 @@ async function main() {
await clear();
}
break;
case 'update':
log.info('检查更新', '开始')
loop_wait = update_loop_wait;
await update()
break;
case 'help':
return help_msg
case undefined:
@@ -84,7 +87,11 @@ async function main() {
default:
return `提供了错误的[OPTIONS] -> ${mode}\n\n` + help_msg
}
} else {
return 'Cookie已失效, 切换账号时不要点击退出账号而应直接删除Cookie退出'
}
} else {
return '请查看README文件, 在env.js指定位置填入cookie'
}
}
@@ -99,9 +106,12 @@ async function main() {
initEnv();
log.init();
log.info('环境变量初始化', '成功加载env.js文件');
} else if (hasEnv('COOKIE') || hasEnv('MULTIPLE_ACCOUNT_PARM')) {
log.init();
log.info('环境变量初始化', '成功从环境变量中读取COOKIE设置');
} else {
log.init();
log.warn('环境变量初始化', '未在当前目录下找到env.js文件 也可在环境变量中设置所需参数');
log.error('环境变量初始化', '未在当前目录下找到env.js文件或者在环境变量中设置所需参数');
return
}
@@ -127,7 +137,7 @@ async function main() {
await delay(loop_wait)
await main()
}
log.info('结束运行', '未设置休眠时间')
log.info('结束运行', '未在config.js中设置休眠时间')
}
process.exit(0);
+2 -1
View File
@@ -87,6 +87,7 @@ module.exports = {
lottery_loop_wait: 0,
check_loop_wait: 0,
clear_loop_wait: 0,
update_loop_wait: 0,
/**
* - 转发间隔时间
@@ -140,7 +141,7 @@ module.exports = {
at_users: [['转发抽奖娘', 294887687], ['你的工具人老公', 100680137]],
/**
* - 同步 https://gitee.com/shanmite/lottery-notice/raw/master/notice.json
* - 自动同步 https://gitee.com/shanmite/lottery-notice/raw/master/notice.json
* - 英文逗号分隔 如: 1,2,3
*/
blacklist: '',
+5 -4
View File
@@ -1,13 +1,14 @@
{
"name": "lottery-in-bili",
"version": "3.0.0",
"description": "自动抽奖",
"name": "lottery-auto-script",
"version": "2.0.8",
"description": "自动参与B站动态抽奖",
"main": "main.js",
"scripts": {
"start": "node main.js start",
"clear": "node main.js clear",
"check": "node main.js check",
"pkg_x86": "npx pkg . && PowerShell .\\script\\pkg\\pkg.ps1",
"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_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"
+6 -3
View File
@@ -7,10 +7,12 @@ $ENV_FILE = "env.js"
$TARGET_DIR = ".\dist"
$NAME = 'lottery-auto-script'
$TRIARR = @(
@("lottery-in-bili-win.exe", "lottery.exe", "nlts-win-x64"),
@("lottery-in-bili-linux", "lottery", "nlts-linux-x64"),
@("lottery-in-bili-macos", "lottery", "nlts-macos-x64")
@("$NAME-win.exe", "lottery.exe", "nlts-win-x64"),
@("$NAME-linux", "lottery", "nlts-linux-x64"),
@("$NAME-macos", "lottery", "nlts-macos-x64")
)
Copy-Item -Path $TEMPLATE_ENV_FILE -Destination $TARGET_DIR -Force
@@ -38,6 +40,7 @@ foreach ($TRI in $TRIARR) {
New-Item -Path $DIR -Name "start.bat" -ItemType File -Value "@echo off && lottery start && pause" -Force
New-Item -Path $DIR -Name "check.bat" -ItemType File -Value "@echo off && lottery check && pause" -Force
New-Item -Path $DIR -Name "clear.bat" -ItemType File -Value "@echo off && lottery clear && pause" -Force
New-Item -Path $DIR -Name "update.bat" -ItemType File -Value "@echo off && lottery update && pause" -Force
}
Compress-Archive -Path $DIR -DestinationPath "$($DIR)-$(Get-Date -Format "yyyyMMd")" -Force