Compare commits

..
1 Commits
Author SHA1 Message Date
shanmite a28ec20b12 feat: 检查更新
fix: tag在中间的情况
2021-08-13 12:32:54 +08:00
10 changed files with 158 additions and 22 deletions
+1
View File
@@ -24,6 +24,7 @@
- 自动点赞、评论、乱序转发、@好友、带话题、可选随机动态
- 检测是否中奖
- 清理动态关注
- 检查更新
- 更多功能设置请参考配置文件
**声明**: 此脚本仅用于学习和测试,作者本人并不对其负责,请于运行测试完成后自行删除,请勿滥用!
+1 -1
View File
@@ -195,7 +195,7 @@ class Monitor extends Searcher {
, isFollowed = (new RegExp(uid)).test(attentionList)
, description = typeof des === 'string' ? des : ''
, needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description)
, needTopic = [...(new Set(description.match(/(?<=[带加上](?:话题|tag).*)#.+?#/ig) || []))].join(' ')
, 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))
+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',
}
})
+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().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().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().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().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>}
+10 -5
View File
@@ -1,4 +1,4 @@
const { env_file, config_file, log, hasEnv, delay, hasFileOrDir } = require("./lib/utils");
const { version: ve, env_file, config_file, log, hasEnv, delay, hasFileOrDir } = require("./lib/utils");
const metainfo = [
` _ _ _ _____ _ _ `,
@@ -10,7 +10,7 @@ const metainfo = [
` __/ | | | `,
` |___/ |_| `,
` `,
` Verison: v2.0.5`,
` Verison: v${ve}`,
` Written By shanmite`,
]
/**多账号存储 */
@@ -49,14 +49,14 @@ async function main() {
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('抽奖', '开始运行');
@@ -75,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:
+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,
/**
* - 转发间隔时间
+5 -4
View File
@@ -1,13 +1,14 @@
{
"name": "lottery-in-bili",
"version": "3.0.0",
"description": "自动抽奖",
"name": "lottery-auto-script",
"version": "2.0.6",
"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