mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
update: 如何新增添加更多账号的说明; feat: 每过15天自动清理动态关注
This commit is contained in:
parent
609b412d42
commit
fcd8456152
BIN
.github/behind.png
vendored
Normal file
BIN
.github/behind.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
24
.github/workflows/clear.yml
vendored
Normal file
24
.github/workflows/clear.yml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
name: 'Automatic clear dynamic&follow'
|
||||
on:
|
||||
workflow_dispatch:
|
||||
branches:
|
||||
- main
|
||||
schedule:
|
||||
- cron: '0 0 */15 * *'
|
||||
jobs:
|
||||
clear:
|
||||
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:
|
||||
COOKIE_1: ${{ secrets.COOKIE }}
|
||||
SCKEY: ${{ secrets.SCKEY }}
|
||||
run:
|
||||
npm run clear
|
||||
10
.github/workflows/node.js.yml
vendored
10
.github/workflows/node.js.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
||||
COOKIE_1: ${{ secrets.COOKIE }}
|
||||
SCKEY: ${{ secrets.SCKEY }}
|
||||
run:
|
||||
node main.js
|
||||
npm start
|
||||
lottery_2:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -40,7 +40,7 @@ jobs:
|
||||
COOKIE_2: ${{ secrets.COOKIE2 }}
|
||||
SCKEY: ${{ secrets.SCKEY }}
|
||||
run:
|
||||
node main.js
|
||||
npm start
|
||||
lottery_3:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -56,7 +56,7 @@ jobs:
|
||||
COOKIE_3: ${{ secrets.COOKIE3 }}
|
||||
SCKEY: ${{ secrets.SCKEY }}
|
||||
run:
|
||||
node main.js
|
||||
npm start
|
||||
lottery_4:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -72,7 +72,7 @@ jobs:
|
||||
COOKIE_4: ${{ secrets.COOKIE4 }}
|
||||
SCKEY: ${{ secrets.SCKEY }}
|
||||
run:
|
||||
node main.js
|
||||
npm start
|
||||
lottery_5:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -88,4 +88,4 @@ jobs:
|
||||
COOKIE_5: ${{ secrets.COOKIE5 }}
|
||||
SCKEY: ${{ secrets.SCKEY }}
|
||||
run:
|
||||
node main.js
|
||||
npm start
|
||||
|
||||
35
README.md
35
README.md
@ -15,7 +15,10 @@
|
||||
|
||||
## 动态抽奖
|
||||
通过Github Actions挂载Nodejs脚本
|
||||
> [Actions官方文档](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions)
|
||||
|
||||
> [Actions官方文档](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions)
|
||||
|
||||
此脚本将在B站专栏草稿中储存信息
|
||||
|
||||
---
|
||||
|
||||
@ -90,8 +93,11 @@ Chrome浏览器:
|
||||
|
||||
## 其他细节
|
||||
- 更新
|
||||
> [如何同步更新Github上Fork的项目](https://www.cnblogs.com/idyllcheung/p/13555934.html)
|
||||
- 支持最多5个账号
|
||||
如果出现
|
||||

|
||||
说明此脚本有更新
|
||||
自行搜索`如何同步更新Github上Fork的项目`
|
||||
- 默认支持5个账号
|
||||
| cookies | value |
|
||||
| --------- | ----- |
|
||||
| `COOKIE` | 值 |
|
||||
@ -99,15 +105,36 @@ Chrome浏览器:
|
||||
| `COOKIE3` | 值 |
|
||||
| `COOKIE4` | 值 |
|
||||
| `COOKIE5` | 值 |
|
||||
|
||||
也可在`.github/workflows/node.js.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:
|
||||
COOKIE_*: ${{ secrets.COOKIE* }}
|
||||
SCKEY: ${{ secrets.SCKEY }}
|
||||
run:
|
||||
npm start
|
||||
```
|
||||
将以上星号处改为数字并依次复制粘贴(简单的找规律问题)
|
||||
- 部分设置说明
|
||||
- 定时运行(`UTC`时间)
|
||||
`.github/workflows/node.js.yml`
|
||||
```yaml
|
||||
schedule:
|
||||
- cron: '0 */2 * * *'
|
||||
```
|
||||
[填写格式](https://crontab.guru/)
|
||||
- 模式选择
|
||||
`lib/config.js`
|
||||
```javascript
|
||||
/**
|
||||
* 默认设置
|
||||
|
||||
@ -555,6 +555,40 @@ const BiliAPI = {
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取一个分区中50个的id
|
||||
* @param {number} tagid
|
||||
* @param {number} n 1->
|
||||
* @returns {Promise<number[]>}
|
||||
*/
|
||||
getPartitionUID: (tagid, n) => {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/relation/tag',
|
||||
queryStringsObj: {
|
||||
mid: GlobalVar.myUID,
|
||||
tagid: tagid,
|
||||
pn: n,
|
||||
ps: 50
|
||||
},
|
||||
hasCookies: true,
|
||||
success: responseText => {
|
||||
const res = Base.strToJson(responseText);
|
||||
let uids = [];
|
||||
if (res.code === 0) {
|
||||
res.data.forEach(d => {
|
||||
uids.push(d.mid);
|
||||
})
|
||||
console.log(`[获取分组${tagid}]成功获取取关分区列表${n}`);
|
||||
resolve(uids)
|
||||
} else {
|
||||
console.warn(`[获取分组]获取取关分区列表失败\n${responseText}`);
|
||||
resolve(uids)
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取草稿列表
|
||||
* @typedef Page
|
||||
|
||||
@ -49,13 +49,25 @@ async function updateDyid(dyid) {
|
||||
if (typeof aid === 'number' && aid !== -1) {
|
||||
if (_dyid === '' && dyid === '') return;
|
||||
console.log(`[更新专栏草稿]id:${aid}`);
|
||||
await BiliAPI.addDraft(_dyid + dyid,aid);
|
||||
await BiliAPI.addDraft(_dyid + dyid, aid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空dyid
|
||||
* @param {string} dyid
|
||||
* @returns
|
||||
*/
|
||||
async function clearDyid() {
|
||||
const draftId = await getDraftid();
|
||||
console.log(`[清空专栏草稿]id:${draftId}`);
|
||||
await BiliAPI.addDraft('', draftId);
|
||||
}
|
||||
|
||||
const MyStorage = {
|
||||
getDyid,
|
||||
updateDyid
|
||||
updateDyid,
|
||||
clearDyid
|
||||
};
|
||||
|
||||
module.exports = MyStorage;
|
||||
56
lib/clear.js
Normal file
56
lib/clear.js
Normal file
@ -0,0 +1,56 @@
|
||||
const Base = require("./Base");
|
||||
const { checkMyPartition } = require("./BiliAPI");
|
||||
const BiliAPI = require("./BiliAPI");
|
||||
const Public = require("./Public");
|
||||
const GlobalVar = require('./GlobalVar.json');
|
||||
const { clearDyid } = require("./MyStorage");
|
||||
|
||||
let offset = '0';
|
||||
async function delDynamic() {
|
||||
for (let index = 0; index < 1000; index++) {
|
||||
const { allModifyDynamicResArray, offset: _offset } = await Public.prototype.checkAllDynamic(GlobalVar.myUID, 1, 5 * 1000, offset);
|
||||
offset = _offset;
|
||||
if (index < 2) {
|
||||
console.log(`跳过第${index + 1}页(12条)`);
|
||||
} else {
|
||||
console.log(`开始读取第${index + 1}页(12条)`);
|
||||
for (let index = 0; index < allModifyDynamicResArray.length; index++) {
|
||||
const res = allModifyDynamicResArray[index];
|
||||
const { type, dynamic_id } = res;
|
||||
if (type === 1) BiliAPI.rmDynamic(dynamic_id);
|
||||
await Base.delay(8 * 1000);
|
||||
}
|
||||
console.log(`第${index}页中的转发动态全部删除成功`)
|
||||
}
|
||||
if (offset === '0') break;
|
||||
}
|
||||
}
|
||||
async function unFollow() {
|
||||
const tagid = await checkMyPartition();
|
||||
if (tagid === 0) { console.log('未能成功获取关注分区id'); return }
|
||||
let rmup = [];
|
||||
for (let index = 1; index < 42; index++) {
|
||||
const uids = await BiliAPI.getPartitionUID(tagid, index);
|
||||
await Base.delay(5 * 1000);
|
||||
rmup.push(...uids);
|
||||
if (uids.length === 0) break;
|
||||
}
|
||||
for (let index = 0; index < rmup.length; index++) {
|
||||
const uid = rmup[index];
|
||||
BiliAPI.cancelAttention(uid);
|
||||
await Base.delay(8 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清理动态和关注
|
||||
*/
|
||||
async function clear() {
|
||||
await delDynamic();
|
||||
await unFollow();
|
||||
await clearDyid();
|
||||
return;
|
||||
}
|
||||
|
||||
module.exports = { clear }
|
||||
11
main.js
11
main.js
@ -16,9 +16,18 @@ COOKIE_ARR.forEach(async (cookie, num) => {
|
||||
if (typeof cookie === 'string' && cookie.length > 10) {
|
||||
await setGlobalVar(cookie, SCKEY);
|
||||
const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs");
|
||||
const { clear } = require("./lib/clear");
|
||||
const isRight = await checkCookie(num + 1);
|
||||
if (!isRight) return;
|
||||
await isMe();
|
||||
await start();
|
||||
if (process.argv.slice(2)[0] === 'clear') {
|
||||
console.log('开始清理动态');
|
||||
await clear();
|
||||
console.log('清理动态完毕');
|
||||
} else {
|
||||
console.log('开始参与抽奖');
|
||||
await start();
|
||||
console.log('参与抽奖结束');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -5,7 +5,9 @@
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "node main.js",
|
||||
"test": "env.bat && node main.js"
|
||||
"clear": "node main.js clear",
|
||||
"test_start": "env.bat && node main.js",
|
||||
"test_clear": "env.bat && node main.js clear"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user