feat: 移除远程设置启用自动更新

This commit is contained in:
shanmite 2023-08-26 08:36:12 +08:00
parent 04c25a88fc
commit 0024b19cbf
5 changed files with 29 additions and 68 deletions

View File

@ -281,7 +281,6 @@ class Monitor extends Searcher {
model, chatmodel, chat: chats, relay: relays,
block_dynamic_type, max_create_time, is_imitator,
only_followed, at_users, blockword, blacklist,
use_public_blacklist
} = config,
now_ts = Date.now() / 1000;
@ -399,25 +398,12 @@ class Monitor extends Searcher {
isSendChat =
(hasOfficialLottery && chatmodel[0] === '1')
|| (!hasOfficialLottery && chatmodel[1] === '1'),
{ blacklist: remote_blacklist } = use_public_blacklist === false
? { blacklist: "" }
: global_var.get("remoteconfig"),
/**
* 获取黑名单并去重合并
* @type {string[]}
*/
new_blacklist = remote_blacklist
? [
...new Set([...blacklist.split(','),
...remote_blacklist.split(',')])
]
: blacklist.split(','),
keys = [dyid, m_uid, ori_uid];
log.debug("筛选动态", { real_uid, mIsFollowed, oriIsFollowed, realIsFollowed, needAt, needTopic, type, isRelayDynamic, key_words, has_key_words, blockword, isBlock, isLottery, isSendChat })
if (
new_blacklist.some(id => keys.some(key => {
blacklist.split(',').some(id => keys.some(key => {
if (key + '' === id) {
log.info("筛选动态", `黑名单匹配(${id})(https://t.bilibili.com/${dyid})`)
return true
@ -472,7 +458,6 @@ class Monitor extends Searcher {
}
if (isLottery) {
const { uname_map = {} } = global_var.get("remoteconfig")
let onelotteryinfo = {};
onelotteryinfo.isOfficialLottery = hasOfficialLottery;
@ -489,7 +474,7 @@ class Monitor extends Searcher {
let
/**转发评语 */
RandomStr = (getRandomOne(relays) || "!!!")
.replace(/\$\{uname\}/g, uname_map[real_uid] || uname),
.replace(/\$\{uname\}/g, uname),
/**控制字段 */
new_ctrl = [];
@ -542,7 +527,7 @@ class Monitor extends Searcher {
if (isSendChat) {
onelotteryinfo.rid = rid
onelotteryinfo.chat = (getRandomOne(chats) || "!!!")
.replace(/\$\{uname\}/g, uname_map[real_uid] || uname)
.replace(/\$\{uname\}/g, uname)
}
alllotteryinfo.push(onelotteryinfo);

View File

@ -1,4 +1,4 @@
const { getRemoteConfig, getRandomOne, createDir, createFile, dyids_dir } = require("../utils");
const { getRandomOne, createDir, createFile, dyids_dir } = require("../utils");
const config = require("../data/config");
let global_var = {
@ -62,7 +62,6 @@ let global_var = {
.map(lottery_option => config[lottery_option].map(it => [lottery_option, it]))
.flat()
);
this.set('remoteconfig', await getRemoteConfig());
}
await createDir('dyids');
await createFile(dyids_dir, num < 2 ? 'dyid.txt' : `dyid${num}.txt`, '', 'a')

View File

@ -56,8 +56,9 @@ function checkPlatform(releases) {
/**
* 半自动更新
* @param {boolean} isDdownload
*/
async function update() {
async function update(isDdownload) {
try {
const { tag_name, assets, body: text } = await getLatestRelease('shanmiteko', 'LotteryAutoScript')
if (checkVersion(version) < checkVersion(tag_name)) {
@ -65,6 +66,7 @@ async function update() {
.filter(({ name }) => checkPlatform(name))
.map(({ browser_download_url }) => browser_download_url)
if (download_url.length) {
if (isDdownload) {
await try_for_each(download_url.entries(), async ([i, url]) => {
let proxy_url = "https://ghproxy.com/";
proxy_url += url
@ -79,6 +81,8 @@ async function update() {
return false
})
log.info('自动下载', '成功下载到当前目录')
log.info('检查更新', '请手动解压替换可执行文件');
}
log.info('更新说明', '\n' + text + '\n')
} else {
throw `未找到能在此平台(${process.platform})-(${process.arch})上运行的版本,建议以源码运行`
@ -87,7 +91,7 @@ async function update() {
throw '当前已是最新版本'
}
} catch (error) {
log.error('更新脚本', error)
log.warn('更新脚本', error)
}
}

View File

@ -338,35 +338,6 @@ const utils = {
})
});
},
/**
* 获取远程设置
* @returns {Promise<JSON>}
*/
getRemoteConfig() {
return new Promise((resolve) => {
send({
method: 'GET',
url: 'https://gitee.com/shanmite/lottery-notice/raw/master/notice.json',
headers: {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
},
success: res => {
try {
const body = JSON.parse(Buffer.from(res.body, "base64").toString());
if (body.node_msg) utils.log.info('公告', '\n' + body.node_msg + '\n');
resolve(body.config)
} catch (error) {
utils.log.error('获取远程设置', '获取远程设置错误: ' + error);
resolve({})
}
},
failure: err => {
utils.log.error('获取远程设置', '获取远程设置错误: ' + err);
resolve({})
}
})
})
},
/**
* 是否存在文件或目录
* @param {string} path

View File

@ -153,11 +153,13 @@ function initConfig() {
/**OPTIONS */
process.env.lottery_mode = process.argv[2]
if (process.env.lottery_mode === "update") {
log.info('检查更新', '开始')
await require("./lib/update").update()
log.info('检查更新', '请手动解压替换可执行文件')
if (process.env.lottery_mode === "update") {
await require("./lib/update").update(true)
return
} else {
await require("./lib/update").update(false)
}
const err_msg = await main();