perf: 中奖检测单独运行; docs: 新增检测中奖的相关说明

This commit is contained in:
shanmite 2021-02-01 13:10:13 +08:00
parent 65e636de7c
commit 342d5d628f
8 changed files with 183 additions and 74 deletions

93
.github/workflows/check.yml vendored Normal file
View File

@ -0,0 +1,93 @@
name: 'Automatic check'
on:
workflow_dispatch:
branches:
- main
schedule:
- cron: '0 0 */2 * *'
jobs:
lottery_1:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v2
- name: 'Use Node.js'
uses: actions/setup-node@v1
with:
node-version: '12.18.3'
- name: 'Run in Nodejs'
shell: bash
env:
NUMBER: 1
COOKIE: ${{ secrets.COOKIE }}
SCKEY: ${{ secrets.SCKEY }}
run:
npm run check
lottery_2:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v2
- name: 'Use Node.js'
uses: actions/setup-node@v1
with:
node-version: '12.18.3'
- name: 'Run in Nodejs'
shell: bash
env:
NUMBER: 2
COOKIE: ${{ secrets.COOKIE2 }}
SCKEY: ${{ secrets.SCKEY }}
run:
npm run check
lottery_3:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v2
- name: 'Use Node.js'
uses: actions/setup-node@v1
with:
node-version: '12.18.3'
- name: 'Run in Nodejs'
shell: bash
env:
NUMBER: 3
COOKIE: ${{ secrets.COOKIE3 }}
SCKEY: ${{ secrets.SCKEY }}
run:
npm run check
lottery_4:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v2
- name: 'Use Node.js'
uses: actions/setup-node@v1
with:
node-version: '12.18.3'
- name: 'Run in Nodejs'
shell: bash
env:
NUMBER: 4
COOKIE: ${{ secrets.COOKIE4 }}
SCKEY: ${{ secrets.SCKEY }}
run:
npm run check
lottery_5:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v2
- name: 'Use Node.js'
uses: actions/setup-node@v1
with:
node-version: '12.18.3'
- name: 'Run in Nodejs'
shell: bash
env:
NUMBER: 5
COOKIE: ${{ secrets.COOKIE5 }}
SCKEY: ${{ secrets.SCKEY }}
run:
npm run check

View File

@ -4,6 +4,10 @@
![Automatic check](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20check/badge.svg)
![Automatic clear dynamic&follow](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20clear%20dynamic&follow/badge.svg)
@ -19,7 +23,9 @@
- [操作步骤](#操作步骤)
- [Fork本仓库](#fork本仓库)
- [填入COOKIE](#填入cookie)
- [微信推送中奖信息(可选)](#微信推送中奖信息可选)
- [检测中奖](#检测中奖)
- [手动检查](#手动检查)
- [微信推送(可选)](#微信推送可选)
- [运行](#运行)
- [完成!](#完成)
- [清理动态](#清理动态)
@ -99,15 +105,22 @@ Chrome浏览器:
↓↓
### 微信推送中奖信息(可选)
### 检测中奖
每两个小时检测一次
通过`@`信息判断
#### 手动检查
手动触发`Automatic check`工作流后可在日志中查看
#### 微信推送(可选)
如果想使用Server酱提供的**微信推送**服务
> [Server酱是什么?](http://sc.ftqq.com/3.version)
可在 `Repository secrets` 中新建一个 `SCKEY` 并填入相应的值
![new secret SCKEY](.github/secret2.png)
![new secret SCKEY](.github/secret2.png)
**注意**Server酱有时会出错
↓↓
@ -182,6 +195,7 @@ Chrome浏览器:
*添加更多的账号*
可在文件`.github/workflows/node.js.yml`中
将以下代码中星号处改为数字并依次复制粘贴
```yaml
lottery_*:
runs-on: ubuntu-latest
@ -202,9 +216,31 @@ steps:
run:
npm start
```
将以上星号处改为数字并依次复制粘贴
此时`Secrets`里就可以添加更多的`COOKIE*`(简单的找规律问题)
若使用自动清理功能,还需再`.github/workflows/clear.yml`中
同理须在文件`.github/workflows/check.yml`中
将以下代码中星号处改为数字并依次复制粘贴(启用对应的中奖检测)
```yaml
lottery_*:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v2
- name: 'Use Node.js'
uses: actions/setup-node@v1
with:
node-version: '12.18.3'
- name: 'Run in Nodejs'
shell: bash
env:
NUMBER: *
COOKIE: ${{ secrets.COOKIE* }}
SCKEY: ${{ secrets.SCKEY }}
run:
npm run check
```
若使用**自动清理**功能,还需再`.github/workflows/clear.yml`中
```yaml
lottery_*:
runs-on: ubuntu-latest

View File

@ -152,5 +152,5 @@ module.exports = {
* @param {string} ts 13位时间戳
* @param {number} zoneOffset 东时区记做正数
*/
transformTimeZone: (ts, zoneOffset) => new Date(new Date(ts).getTime() + zoneOffset * 60 * 60 * 1000)
transformTimeZone: (ts, zoneOffset) => new Date(new Date(ts).getTime() + zoneOffset * 60 * 60 * 1000).toLocaleString()
};

View File

@ -28,16 +28,13 @@ const BiliAPI = {
},
/**
* 获取被at的信息
* @returns {
Promise<{
at_time: number;
id: number;
nickname: string;
business: string;
source_content: string;
url: string
}[] | []>
}
* @typedef AtInfo
* @property {number} at_time
* @property {string} up_uname
* @property {string} business
* @property {string} source_content
* @property {string} url
* @returns {Promise<AtInfo[]>}
*/
getMyAtInfo: async () => {
return new Promise((resolve) => {
@ -51,13 +48,12 @@ const BiliAPI = {
const items = res.data.items;
if (items.length !== 0) {
items.forEach(i => {
const { at_time, id, item, user } = i,
{ nickname } = user,
{ business, uri: url, source_content } = item;
const { at_time, item, user } = i
, { nickname: up_uname } = user
, { business, uri: url, source_content } = item;
atInfo.push({
at_time,
id,
nickname,
up_uname,
business,
source_content,
url
@ -72,35 +68,6 @@ const BiliAPI = {
});
});
},
/**
* 删除at信息
* @param {number} id
* @returns {Promise<void>}
*/
delAtinfo: async (id) => {
return new Promise((resolve) => {
Ajax.post({
url: 'https://api.bilibili.com/x/msgfeed/del',
hasCookies: true,
dataType: 'application/x-www-form-urlencoded',
data: {
tp: 2,
id,
csrf: GlobalVar.csrf
},
success: responseText => {
let res = Base.strToJson(responseText);
if (res.code === 0) {
console.log('删除at信息成功');
resolve();
} else {
console.log(`删除at信息失败`);
resolve();
}
}
})
});
},
/**
* 获取关注列表
* @param {number} uid

View File

@ -182,6 +182,9 @@ class Monitor extends Public {
async go(option) {
const { uid, dyid, type, rid, relay_chat, ctrl } = option;
if (typeof dyid === 'string') {
if (typeof rid === 'string' && type !== 0) {
if (await BiliAPI.sendChat(rid, Base.getRandomStr(config.chat), type) === 0) return 0;
}
if (!this.isAttentionErr) {
uid.forEach(async (one_uid) => {
if (typeof one_uid === 'number') {
@ -198,9 +201,6 @@ class Monitor extends Public {
})
}
if (this.isAttentionErr && uid.length !== 0) return 0;
if (typeof rid === 'string' && type !== 0) {
if (await BiliAPI.sendChat(rid, Base.getRandomStr(config.chat), type) === 0) return 0;
}
if (await BiliAPI.autoRelay(GlobalVar.myUID, dyid, relay_chat, ctrl) === 0) return 0;
if (await MyStorage.updateDyid((Array.from(new Set([dyid, ...this.AllMyLotteryInfo.split(',')]))).toString()) === -1) return 0;
if (await BiliAPI.autolike(dyid) === 0) return 0;

View File

@ -25,6 +25,7 @@ const ServerChan = (text, desp) => {
},
success: responseText => {
console.log(responseText);
if (JSON.parse(responseText).errno !== 0) throw new Error("ServerChan通知失败")
}
})
}
@ -56,26 +57,28 @@ function start() {
* 是否中奖
*/
async function isMe() {
const { SCKEY } = GlobalVar;
if (SCKEY === '') return;
const arr = await BiliAPI.getMyAtInfo();
let desp = '';
if (arr.length !== 0) {
arr.forEach(async e => {
const { at_time, id, nickname, business, source_content, url } = e
const { at_time, up_uname, business, source_content, url } = e
if ((Date.now() / 1000 - at_time) / 3600 >= 2) {
await BiliAPI.delAtinfo(id);
return;
}
desp += `发生时间: ${transformTimeZone(at_time * 1000, 8)} \n\n`
desp += `用户: ${nickname} \n\n`
desp += `${business}中@了你 \n\n`
desp += `用户: ${up_uname} \n\n`
desp += `${business}中@了你(${GlobalVar.myUID}) \n\n`
desp += `原内容为: ${source_content} \n\n`
desp += `[直达链接](${url}) \n\n`
desp += `---\n\n`
});
}
if (desp !== '') ServerChan('可能中奖了!', desp);
if (desp !== '') {
console.log(desp);
ServerChan('可能中奖了!', desp)
} else {
console.log("未中奖");
}
return;
}
@ -89,7 +92,7 @@ async function checkCookie(num) {
return true;
} else {
console.log('登录失败');
ServerChan('动态抽奖出错', `COOKIE${num} 已失效`);
ServerChan('动态抽奖出错', `COOKIE${num} 已失效 UID:${GlobalVar.myUID}`);
return false;
}
}

28
main.js
View File

@ -9,16 +9,24 @@ const { NUMBER, CLEAR, COOKIE, SCKEY } = process.env;
const { clear } = require("./lib/clear");
const isRight = await checkCookie(NUMBER);
if (!isRight) return;
await isMe();
if (process.argv.slice(2)[0] === 'clear') {
if (typeof CLEAR === 'string' && CLEAR === 'true') {
console.log('开始清理动态');
await clear();
console.log('清理动态完毕');
}
} else {
console.log('开始参与抽奖');
await start();
switch (process.argv.slice(2)[0]) {
case 'start':
console.log('开始参与抽奖');
await start();
break;
case 'check':
console.log('检查是否中奖');
await isMe();
break;
case 'clear':
if (typeof CLEAR === 'string' && CLEAR === 'true') {
console.log('开始清理动态');
await clear();
console.log('清理动态完毕');
}
break;
default:
break;
}
}
}))();

View File

@ -4,10 +4,12 @@
"description": "",
"main": "main.js",
"scripts": {
"start": "node main.js",
"start": "node main.js start",
"clear": "node main.js clear",
"test_start": "env.bat && node main.js",
"test_clear": "env.bat && node main.js clear"
"check": "node main.js check",
"test_start": "env.bat && node main.js start",
"test_clear": "env.bat && node main.js clear",
"test_check": "env.bat && node main.js check"
},
"repository": {
"type": "git",