mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-07-22 21:13:47 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
003508e1f3 | ||
|
|
847e6806c6 | ||
|
|
8bf5070459 | ||
|
|
727883a269 | ||
|
|
fd33478af1 | ||
|
|
b2d9e192aa | ||
|
|
db7ba49ca1 | ||
|
|
b51882819a | ||
|
|
e0a8ce5b20 | ||
|
|
2b2613386d | ||
|
|
92f700384e | ||
|
|
8e77afadc3 | ||
|
|
bfc8fb6a14 |
@@ -1,20 +1,24 @@
|
||||
name: Mirror and run GitLab CI
|
||||
|
||||
on: [push]
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Mirror + trigger CI
|
||||
uses: SvanBoxel/gitlab-mirror-and-ci-action@master
|
||||
with:
|
||||
args: "https://gitlab.com/shanmiteko/LotteryAutoScript"
|
||||
env:
|
||||
FORCE_PUSH: "true"
|
||||
GITLAB_HOSTNAME: "gitlab.com"
|
||||
GITLAB_USERNAME: "shanmiteko"
|
||||
GITLAB_PASSWORD: ${{ secrets.GITLAB_PASSWORD }}
|
||||
GITLAB_PROJECT_ID: "36365601"
|
||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
- uses: actions/checkout@v1
|
||||
- name: Mirror + trigger CI
|
||||
uses: SvanBoxel/gitlab-mirror-and-ci-action@master
|
||||
with:
|
||||
args: "https://gitlab.com/shanmiteko/LotteryAutoScript"
|
||||
env:
|
||||
FORCE_PUSH: "true"
|
||||
GITLAB_HOSTNAME: "gitlab.com"
|
||||
GITLAB_USERNAME: "shanmiteko"
|
||||
GITLAB_PASSWORD: ${{ secrets.GITLAB_PASSWORD }}
|
||||
GITLAB_PROJECT_ID: "36365601"
|
||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
<!-- markdownlint-disable MD036 MD024-->
|
||||
# CHANGELOG
|
||||
## 主要变化(2.6.8)
|
||||
* 847e680 feat: 丰富推送内容(#135)(#194)(#211)
|
||||
* 8bf5070 fix: `flatMap` is not a function (#218)
|
||||
* 727883a feat: 推送`NOTE` (#221)
|
||||
* fd33478 fix: 微信企业应用推送未配置出错 (#220)
|
||||
|
||||
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
|
||||
|
||||
## 主要变化(2.6.7)
|
||||
* db7ba49 style: 修改通知格式
|
||||
* b518828 feat: 新增企业微信应用推送 (#217)
|
||||
* e0a8ce5 doc: update image
|
||||
|
||||
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
|
||||
|
||||
## 主要变化(2.6.6)
|
||||
* 92f7003 perf: monochrome
|
||||
* 8e77afa fix: `fs.uninkSync` returns before remove finish
|
||||
* bfc8fb6 ci: gitlab mirror `workflow_dispatch`
|
||||
|
||||
_如果之前版本小于上一版本,请查看[CHANGELOG](https://github.com/shanmiteko/LotteryAutoScript/blob/main/CHANGELOG.md)变更说明_
|
||||
|
||||
## 主要变化(2.6.5)
|
||||
* 47e09a1 ci: arm64 added, and optimized
|
||||
* b91a4f9 fix: `fs.rm` node12
|
||||
|
||||
@@ -186,7 +186,8 @@ Chrome浏览器:
|
||||
| `IGOT_PUSH_KEY` | iGot推送 | iGot聚合推送,支持多方式推送,确保消息可达。 [参考文档](https://wahao.github.io/Bark-MP-helper ) |
|
||||
| `QQ_SKEY` | 酷推(Cool Push)推送 | 推送所需的Skey,登录后获取Skey [参考文档](https://cp.xuthus.cc/) |
|
||||
| `QQ_MODE` | 酷推(Cool Push)推送 | 推送方式(send或group或者wx,默认send) [参考文档](https://cp.xuthus.cc/) |
|
||||
| `QYWX_KEY` | 企业微信推送 | 密钥,企业微信推送 webhook 后面的 key [详见官方说明文档](https://work.weixin.qq.com/api/doc/90000/90136/91770) |
|
||||
| `QYWX_AM` | 企业微信应用 | 第一个值是企业id,第二个值是secret,第三个值@all(或者成员id),第四个值是AgentID (逗号分割) 可查看此[教程](http://note.youdao.com/s/HMiudGkb) [官方文档](https://developer.work.weixin.qq.com/document/path/90236) |
|
||||
| `QYWX_KEY` | 企业微信Bot推送 | 密钥,企业微信推送 webhook 后面的 key [详见官方说明文档](https://work.weixin.qq.com/api/doc/90000/90136/91770) |
|
||||
| `PUSH_PLUS_TOKEN` | pushplus推送 | 微信扫码登录后一对一推送或一对多推送下面的token(您的Token) [官方网站](http://pushplus.hxtrip.com/) |
|
||||
| `PUSH_PLUS_USER` | pushplus推送 | 一对多推送的“群组编码”(一对多推送下面->您的群组(如无则新建)->群组编码)注:(1、需订阅者扫描二维码 2、如果您是创建群组所属人,也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送),只填`PUSH_PLUS_TOKEN`默认为一对一推送 |
|
||||
| `QMSG_KEY` | [Qmsg酱](https://qmsg.zendee.cn)私聊推送 | [Qmsg注册](https://qmsg.zendee.cn/login.html) |
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 274 KiB After Width: | Height: | Size: 221 KiB |
@@ -75,6 +75,7 @@ module.exports = Object.freeze({
|
||||
TG_PROXY_PORT: "",
|
||||
DD_BOT_TOKEN: "",
|
||||
DD_BOT_SECRET: "",
|
||||
QYWX_AM: "",
|
||||
QYWX_KEY: "",
|
||||
IGOT_PUSH_KEY: "",
|
||||
PUSH_PLUS_TOKEN: "",
|
||||
|
||||
+7
-10
@@ -7,9 +7,8 @@ const bili = require('./net/bili')
|
||||
/**
|
||||
* 是否中奖
|
||||
* @param {number} num
|
||||
* @param {string} [note]
|
||||
*/
|
||||
async function isMe(num, note = "无") {
|
||||
async function isMe(num) {
|
||||
let desp = '';
|
||||
const
|
||||
{ notice_key_words, update_session_wait, get_session_wait, check_session_pages } = config,
|
||||
@@ -23,13 +22,13 @@ async function isMe(num, note = "无") {
|
||||
.slice(0, unread_at_num)
|
||||
.forEach(({ at_time, up_uname, business, source_content, url }) => {
|
||||
desp += '## [at]检测结果\n\n'
|
||||
desp += '----------------------------------------------------------------\n\n'
|
||||
desp += '- - - -\n\n'
|
||||
desp += `发生时间: ${new Date(at_time * 1000).toLocaleString()}\n\n`
|
||||
desp += `用户: ${up_uname}\n\n`
|
||||
desp += `在${business}中@了你(https://space.bilibili.com/${global_var.get("myUID")})\n\n`
|
||||
desp += `原内容为: ${source_content}\n\n`
|
||||
desp += `[直达链接](${url})\n\n`
|
||||
desp += '----------------------------------------------------------------\n\n'
|
||||
desp += '- - - -\n\n'
|
||||
});
|
||||
log.info('中奖检测', '--> OK');
|
||||
}
|
||||
@@ -41,12 +40,12 @@ async function isMe(num, note = "无") {
|
||||
.forEach(({ nickname, uri, source, timestamp }) => {
|
||||
if (judge(source, notice_key_words)) {
|
||||
desp += '## 回复检测结果\n\n'
|
||||
desp += '----------------------------------------------------------------\n\n'
|
||||
desp += '- - - -\n\n'
|
||||
desp += `发生时间: ${new Date(timestamp * 1000).toLocaleString()}\n\n`
|
||||
desp += `用户: ${nickname}\n\n`
|
||||
desp += `回复你(https://space.bilibili.com/${global_var.get("myUID")})说:\n${source}\n\n`
|
||||
desp += `[直达链接](${uri})\n\n`
|
||||
desp += '----------------------------------------------------------------\n\n'
|
||||
desp += '- - - -\n\n'
|
||||
}
|
||||
})
|
||||
log.info('中奖检测', '--> OK');
|
||||
@@ -64,12 +63,12 @@ async function isMe(num, note = "无") {
|
||||
const content = await bili.fetch_session_msgs(talker_id, unread_count);
|
||||
if (judge(content, notice_key_words)) {
|
||||
desp += '## 私信检测结果\n\n'
|
||||
desp += '----------------------------------------------------------------\n\n'
|
||||
desp += '- - - -\n\n'
|
||||
desp += `发生时间: ${new Date(timestamp * 1000).toLocaleString()}\n\n`
|
||||
desp += `用户: ${sender_uid}\n\n`
|
||||
desp += `私信你(https://space.bilibili.com/${global_var.get("myUID")})说:\n${content}\n\n`
|
||||
desp += `[直达链接](https://message.bilibili.com/#/whisper/mid${sender_uid})\n\n`
|
||||
desp += '----------------------------------------------------------------\n\n'
|
||||
desp += '- - - -\n\n'
|
||||
}
|
||||
await bili.updateSessionStatus(talker_id, type, msg_seqno);
|
||||
await delay(update_session_wait);
|
||||
@@ -94,8 +93,6 @@ async function isMe(num, note = "无") {
|
||||
log.info('中奖检测', '--> OK');
|
||||
}
|
||||
if (desp) {
|
||||
desp += `帐号备注: ${note}\n\n`;
|
||||
desp += '中奖了别忘给脚本(https://github.com/shanmiteko/LotteryAutoScript)点一个Star哦, 赞助一两块也不是不可以_(:з」∠)_\n\n'
|
||||
log.info('可能中奖了', desp);
|
||||
await sendNotify(`帐号${num}可能中奖了`, desp);
|
||||
} else {
|
||||
|
||||
+4
-4
@@ -66,7 +66,7 @@ class Monitor extends Searcher {
|
||||
case 2004:
|
||||
log.warn('账号异常', `UID(${global_var.get('myUID')})异常号只会对部分UP出现关注异常`)
|
||||
if (!config.is_exception) {
|
||||
await sendNotify('[动态抽奖]账号异常通知', `UID: ${global_var.get('myUID')}\n\n异常号只会对部分UP出现关注异常\n\n可在设置中令is_exception为true关闭此推送`)
|
||||
await sendNotify('[动态抽奖]账号异常通知', `UID: ${global_var.get('myUID')}\n异常号只会对部分UP出现关注异常\n可在设置中令is_exception为true关闭此推送\n${log._cache.filter(it => /Error|\[抽奖信息\]/.test(it)).join('\n')}`)
|
||||
}
|
||||
config.is_exception = true;
|
||||
event_bus.emit('Turn_on_the_Monitor')
|
||||
@@ -74,7 +74,7 @@ class Monitor extends Searcher {
|
||||
case 2005:
|
||||
log.warn('关注已达上限', `UID(${global_var.get('myUID')})关注已达上限,已临时进入只转已关注模式`)
|
||||
if (!config.is_outof_maxfollow) {
|
||||
await sendNotify('[动态抽奖]关注已达上限', `UID: ${global_var.get('myUID')}\n\n关注已达上限,已临时进入只转已关注模式\n\n可在设置中令is_outof_maxfollow为true关闭此推送`)
|
||||
await sendNotify('[动态抽奖]关注已达上限', `UID: ${global_var.get('myUID')}\n关注已达上限,已临时进入只转已关注模式\n可在设置中令is_outof_maxfollow为true关闭此推送\n${log._cache.filter(it => /Error|\[抽奖信息\]/.test(it)).join('\n')}`)
|
||||
}
|
||||
config.is_outof_maxfollow = true;
|
||||
config.only_followed = true;
|
||||
@@ -289,12 +289,12 @@ class Monitor extends Searcher {
|
||||
|
||||
if (lottery_param[0] !== "APIs" && save_lottery_info_to_file && protoLotteryInfo.length) {
|
||||
log.info("保存抽奖信息", "保存开始")
|
||||
appendLotteryInfoFile(lottery_param[1].toString(), protoLotteryInfo)
|
||||
await appendLotteryInfoFile(lottery_param[1].toString(), protoLotteryInfo)
|
||||
}
|
||||
|
||||
if (lottery_param[0] !== "APIs" && set_lottery_info_url && protoLotteryInfo.length) {
|
||||
log.info("上传抽奖信息", "上传开始")
|
||||
new Promise((resolve) => {
|
||||
await new Promise((resolve) => {
|
||||
send({
|
||||
url: set_lottery_info_url,
|
||||
method: "POST",
|
||||
|
||||
@@ -42,8 +42,9 @@ let global_var = {
|
||||
LotteryOrder
|
||||
.map(it => LotteryOrderMap.get(it))
|
||||
.filter(it => typeof it === "string")
|
||||
.flatMap(lottery_option => config[lottery_option]
|
||||
.map(it => [lottery_option, it])));
|
||||
.map(lottery_option => config[lottery_option].map(it => [lottery_option, it]))
|
||||
.flat()
|
||||
);
|
||||
this.set('remoteconfig', await getRemoteConfig());
|
||||
}
|
||||
await createDir('dyids');
|
||||
|
||||
+94
-3
@@ -43,6 +43,12 @@ let DD_BOT_TOKEN = '';
|
||||
//密钥,机器人安全设置页面,加签一栏下面显示的SEC开头的字符串
|
||||
let DD_BOT_SECRET = '';
|
||||
|
||||
// ================================企业微信应用通知设置区域====================================
|
||||
// 此处填你企业微信应用消息的值(详见文档 https://work.weixin.qq.com/api/doc/90000/90135/90236)
|
||||
// 环境变量名 QYWX_AM 依次填入 corpid,corpsecret,touser(注:多个成员ID使用|隔开),agentid,消息类型(选填,不填默认文本消息类型)
|
||||
// 注意用,号隔开(英文输入法的逗号),例如:wwcff56746d9adwers,B-791548lnzXBE6_BWfxdf3kSTMJr9vFEPKAbh6WERQ,mingcheng,1000001,2COXgjH2UIfERF2zxrtUOKgQ9XklUqMdGSWLBoW_lSDAdafat
|
||||
let QYWX_AM = '';
|
||||
|
||||
// =======================================企业微信机器人通知设置区域===========================================
|
||||
//此处填你企业微信机器人的 webhook(详见文档 https://work.weixin.qq.com/api/doc/90000/90136/91770),例如:693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa
|
||||
//注:此处设置github action用户填写到Settings-Secrets里面(Name输入QYWX_KEY)
|
||||
@@ -125,6 +131,10 @@ if (process.env.DD_BOT_TOKEN) {
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.QYWX_AM) {
|
||||
QYWX_AM = process.env.QYWX_AM;
|
||||
}
|
||||
|
||||
if (process.env.QYWX_KEY) {
|
||||
QYWX_KEY = process.env.QYWX_KEY;
|
||||
}
|
||||
@@ -164,12 +174,13 @@ if (process.env.SMTP_TO_USER) {
|
||||
SMTP_TO_USER = process.env.SMTP_TO_USER;
|
||||
}
|
||||
|
||||
|
||||
//==========================云端环境变量的判断与接收=========================
|
||||
|
||||
|
||||
async function sendNotify(text, desp, params = {}) {
|
||||
//提供10种通知方式
|
||||
if (process.env.NOTE) {
|
||||
desp += `\n帐号备注: ${process.env.NOTE}`
|
||||
}
|
||||
//提供多种通知方式
|
||||
await Promise.all([
|
||||
//微信server酱
|
||||
serverNotify(text, desp),
|
||||
@@ -183,6 +194,8 @@ async function sendNotify(text, desp, params = {}) {
|
||||
tgBotNotify(text, desp),
|
||||
//钉钉机器人
|
||||
ddBotNotify(text, desp),
|
||||
//企业微信应用
|
||||
qywxAmNotify(text, desp),
|
||||
//企业微信机器人
|
||||
qywxBotNotify(text, desp),
|
||||
//iGot
|
||||
@@ -529,6 +542,84 @@ function ddBotNotify(text, desp) {
|
||||
})
|
||||
}
|
||||
|
||||
function qywxAmNotify(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (QYWX_AM) {
|
||||
const QYWX_AM_AY = QYWX_AM.split(',');
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://qyapi.weixin.qq.com/cgi-bin/gettoken`,
|
||||
contents: {
|
||||
corpid: `${QYWX_AM_AY[0]}`,
|
||||
corpsecret: `${QYWX_AM_AY[1]}`,
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/json, text/plain, */*',
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
success: res => {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
let accesstoken = data.access_token;
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`,
|
||||
contents: {
|
||||
touser: `${QYWX_AM_AY[2]}`,
|
||||
agentid: `${QYWX_AM_AY[3]}`,
|
||||
safe: '0',
|
||||
msgtype: 'text',
|
||||
text: {
|
||||
content: `${text}\n\n${desp}`,
|
||||
},
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/json, text/plain, */*',
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
success: res => {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.errcode === 0) {
|
||||
log.info('发送通知', '企业微信应用发送通知消息完成。');
|
||||
} else {
|
||||
log.error('发送通知', `${data.errmsg}`);
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
log.error('发送通知', '企业微信应用发送通知消息失败!!' + err);
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
log.error('发送通知', '企业微信应用发送通知消息失败!!' + err);
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
} else {
|
||||
log.debug('发送通知', '您未提供企业微信应用所需的QYWX_AM,取消企业微信应用推送消息通知');
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function qywxBotNotify(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (QYWX_KEY) {
|
||||
|
||||
+5
-7
@@ -34,9 +34,6 @@ async function createRandomDynamic(num) {
|
||||
function start(num) {
|
||||
return new Promise(resolve => {
|
||||
let times = utils.counter();
|
||||
if (config.notice_running_state) {
|
||||
sendNotify(`动态抽奖-帐号${num}开始抽奖`, "运行正常")
|
||||
}
|
||||
/* 注册事件 */
|
||||
event_bus.on('Turn_on_the_Monitor', async () => {
|
||||
const lotterys = global_var.get("Lottery");
|
||||
@@ -56,11 +53,12 @@ function start(num) {
|
||||
await (new Monitor(lottery)).init();
|
||||
});
|
||||
event_bus.on('Turn_off_the_Monitor', async (msg) => {
|
||||
if (config.notice_running_state) {
|
||||
sendNotify(`动态抽奖-帐号${num}结束抽奖`, msg)
|
||||
}
|
||||
await createRandomDynamic(config.create_dy_num);
|
||||
log.info('结束抽奖', '原因: ' + msg);
|
||||
if (config.notice_running_state) {
|
||||
sendNotify(`动态抽奖-帐号${num}结束抽奖`, `${log._cache.filter(it => /抽奖\]|Error|\[抽奖信息\]/.test(it)).join('\n')}`);
|
||||
}
|
||||
log._cache.length = 0;
|
||||
await createRandomDynamic(config.create_dy_num);
|
||||
event_bus.flush();
|
||||
resolve();
|
||||
})
|
||||
|
||||
+52
-46
@@ -189,8 +189,8 @@ const utils = {
|
||||
chalk.hex('#64B3FF'), chalk.grey, chalk.hex('#FFA500'),
|
||||
chalk.hex('#0070BB'), chalk.hex('#48BB31'), chalk.hex('#BBBB23'), chalk.hex('#FF0006')
|
||||
],
|
||||
_iso_time: () => new Date(Date.now() + 288e5).toISOString().slice(0, -1) + '+08'
|
||||
,
|
||||
_iso_time: () => new Date(Date.now() + 288e5).toISOString().slice(0, -1) + '+08',
|
||||
_cache: [],
|
||||
/**
|
||||
* 初始化默认level为3
|
||||
*/
|
||||
@@ -213,10 +213,7 @@ const utils = {
|
||||
* @returns
|
||||
*/
|
||||
rainbow(msg) {
|
||||
const
|
||||
colors = ['red', 'yellow', 'green', 'cyan', 'blue', 'magenta'],
|
||||
colorsCount = colors.length;
|
||||
this.proPrint(msg.map(it => it.split('').map((l, i) => chalk[colors[i % colorsCount]](l)).join('')), '\n')
|
||||
this.proPrint(msg.map(it => it.split('').map(l => chalk.hex("#89cff0")(l)).join('')), '\n')
|
||||
},
|
||||
/**
|
||||
* @param {number} done
|
||||
@@ -232,20 +229,50 @@ const utils = {
|
||||
debug(context, msg) {
|
||||
if (this._level > 3) {
|
||||
if (msg instanceof Object) msg = JSON.stringify(msg, null, 4);
|
||||
this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Debug]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[3](`[\n${msg}\n]`)])
|
||||
let color_text_pair = [
|
||||
[this._colors[0], `[${this._iso_time()}]`],
|
||||
[this._colors[1], "[Debug]"],
|
||||
[this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`],
|
||||
[this._colors[3], `[\n${msg}\n]`],
|
||||
];
|
||||
this.proPrint(color_text_pair.map(([color, text]) => color(text)))
|
||||
}
|
||||
},
|
||||
info(context, msg) {
|
||||
if (this._level > 2)
|
||||
this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Info]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[4](`[${msg}]`)])
|
||||
if (this._level > 2) {
|
||||
let color_text_pair = [
|
||||
[this._colors[0], `[${this._iso_time()}]`],
|
||||
[this._colors[1], "[Info]"],
|
||||
[this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`],
|
||||
[this._colors[4], `[${msg}]`],
|
||||
];
|
||||
this._cache.push(color_text_pair.map(it => it[1]).join(' '));
|
||||
this.proPrint(color_text_pair.map(([color, text]) => color(text)))
|
||||
}
|
||||
},
|
||||
warn(context, msg) {
|
||||
if (this._level > 1)
|
||||
this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Warn]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[5](`[\n${msg}\n]`)])
|
||||
if (this._level > 1) {
|
||||
let color_text_pair = [
|
||||
[this._colors[0], `[${this._iso_time()}]`],
|
||||
[this._colors[1], "[Warn]"],
|
||||
[this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`],
|
||||
[this._colors[5], `[\n${msg}\n]`],
|
||||
];
|
||||
this._cache.push(color_text_pair.map(it => it[1]).join(' '));
|
||||
this.proPrint(color_text_pair.map(([color, text]) => color(text)))
|
||||
}
|
||||
},
|
||||
error(context, msg) {
|
||||
if (this._level > 0)
|
||||
this.proPrint([this._colors[0](`[${this._iso_time()}]`), this._colors[1]("[Error]"), this._colors[2](`[帐号${process.env["NUMBER"]} ${context}]`), this._colors[6](`[\n${msg}\n]`)])
|
||||
if (this._level > 0) {
|
||||
let color_text_pair = [
|
||||
[this._colors[0], `[${this._iso_time()}]`],
|
||||
[this._colors[1], "[Error]"],
|
||||
[this._colors[2], `[帐号${process.env["NUMBER"]} ${context}]`],
|
||||
[this._colors[6], `[\n${msg}\n]`],
|
||||
];
|
||||
this._cache.push(color_text_pair.map(it => it[1]).join(' '));
|
||||
this.proPrint(color_text_pair.map(([color, text]) => color(text)))
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -370,25 +397,6 @@ const utils = {
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* deleteFolderRecursive
|
||||
* @param {*} url
|
||||
*/
|
||||
deleteFolderRecursive(url) {
|
||||
var files = [];
|
||||
if (fs.existsSync(url)) {
|
||||
files = fs.readdirSync(url);
|
||||
files.forEach(function (file) {
|
||||
var curPath = path.join(url, file);
|
||||
if (fs.statSync(curPath).isDirectory()) {
|
||||
utils.deleteFolderRecursive(curPath);
|
||||
} else {
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(url);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 读取dyid文件
|
||||
* @param {number} num
|
||||
@@ -413,23 +421,20 @@ const utils = {
|
||||
* @param {import("./core/searcher").LotteryInfo[]} lottery_info
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
appendLotteryInfoFile(from, lottery_info) {
|
||||
async appendLotteryInfoFile(from, lottery_info) {
|
||||
let all_lottery_info = {};
|
||||
try {
|
||||
all_lottery_info = utils.strToJson(fs.readFileSync(path.join(utils.lottery_info_dir, `lottery_info_${Number(process.env.NUMBER)}.json`)).toString())
|
||||
} catch (_) {
|
||||
all_lottery_info = {}
|
||||
}
|
||||
utils
|
||||
.createDir(utils.lottery_info_dir)
|
||||
.then(() => {
|
||||
if (all_lottery_info[from] instanceof Array) {
|
||||
all_lottery_info[from].push(...lottery_info)
|
||||
} else {
|
||||
all_lottery_info[from] = lottery_info
|
||||
}
|
||||
utils.createFile(utils.lottery_info_dir, `lottery_info_${Number(process.env.NUMBER)}.json`, JSON.stringify(all_lottery_info), "w")
|
||||
})
|
||||
await utils.createDir(utils.lottery_info_dir);
|
||||
if (all_lottery_info[from] instanceof Array) {
|
||||
all_lottery_info[from].push(...lottery_info)
|
||||
} else {
|
||||
all_lottery_info[from] = lottery_info
|
||||
}
|
||||
await utils.createFile(utils.lottery_info_dir, `lottery_info_${Number(process.env.NUMBER)}.json`, JSON.stringify(all_lottery_info), "w")
|
||||
},
|
||||
/**
|
||||
* 读取lottery_info
|
||||
@@ -449,10 +454,11 @@ const utils = {
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 清空lottery_info
|
||||
* 清空lottery_info file
|
||||
*/
|
||||
clearLotteryInfo() {
|
||||
utils.deleteFolderRecursive(utils.lottery_info_dir)
|
||||
async clearLotteryInfo() {
|
||||
await utils.createDir(utils.lottery_info_dir);
|
||||
await utils.createFile(utils.lottery_info_dir, `lottery_info_${Number(process.env.NUMBER)}.json`, "{}", "w")
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ let loop_wait = 0;
|
||||
* @returns {Promise<string>} 错误信息
|
||||
*/
|
||||
async function main() {
|
||||
const { COOKIE, NOTE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env;
|
||||
const { COOKIE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env;
|
||||
if (ENABLE_MULTIPLE_ACCOUNT) {
|
||||
let muti_acco = multiple_account.length
|
||||
? multiple_account
|
||||
@@ -56,17 +56,20 @@ async function main() {
|
||||
if (await checkCookie(NUMBER)) {
|
||||
const mode = process.env.lottery_mode;
|
||||
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 } = require("./lib/data/config");
|
||||
const { lottery_loop_wait, check_loop_wait, clear_loop_wait, save_lottery_info_to_file } = require("./lib/data/config");
|
||||
switch (mode) {
|
||||
case 'start':
|
||||
log.info('抽奖', '开始运行');
|
||||
loop_wait = lottery_loop_wait;
|
||||
if (save_lottery_info_to_file) {
|
||||
await clearLotteryInfo()
|
||||
}
|
||||
await start(NUMBER);
|
||||
break;
|
||||
case 'check':
|
||||
log.info('中奖检测', '检查是否中奖');
|
||||
loop_wait = check_loop_wait;
|
||||
await isMe(NUMBER, NOTE);
|
||||
await isMe(NUMBER);
|
||||
break;
|
||||
case 'clear':
|
||||
if (CLEAR) {
|
||||
@@ -158,13 +161,11 @@ function initConfig() {
|
||||
log.warn('结束运行', '5秒后自动退出');
|
||||
await delay(5 * 1000);
|
||||
} else {
|
||||
clearLotteryInfo();
|
||||
while (loop_wait) {
|
||||
log.info('程序休眠', `${loop_wait / 1000}秒后再次启动`)
|
||||
await delay(loop_wait)
|
||||
if (initEnv() || initConfig()) return;
|
||||
await main()
|
||||
clearLotteryInfo();
|
||||
}
|
||||
log.info('结束运行', '未在config.js中设置休眠时间')
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lottery-auto-script",
|
||||
"version": "2.6.5",
|
||||
"version": "2.6.8",
|
||||
"description": "自动参与B站动态抽奖",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user