feat: my_config设置

This commit is contained in:
shanmite 2021-07-10 15:02:08 +08:00
parent 0b3fbaae41
commit 645e458548
10 changed files with 235 additions and 231 deletions

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ dist/
lib/dyid*.txt
dyid.zip
env.js
my_config.json
my_config.js

163
README.md
View File

@ -1,11 +1,4 @@
# AutoScript
![Automatic sweepstakes](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20sweepstakes/badge.svg)
![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)
![Automatic sync](https://github.com/shanmite/LotteryAutoScript/workflows/Automatic%20sync/badge.svg)
- [AutoScript](#autoscript)
- [操作步骤](#操作步骤)
@ -20,7 +13,6 @@
- [检测未读信息, 已读未读信息](#检测未读信息-已读未读信息)
- [中奖推送(可选)](#中奖推送可选)
- [设置说明](#设置说明)
- [模式选择](#模式选择)
- [自定义设置](#自定义设置)
已实现功能:
@ -77,18 +69,21 @@ Chrome浏览器:
具体操作详见[env.example.js](env.example.js)文件内注释
#### 可执行文件
[打开终端](https://cn.bing.com/search?q=%E5%A6%82%E4%BD%95%E5%9C%A8%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E6%89%93%E5%BC%80%E7%BB%88%E7%AB%AF)运行内部的可执行文件
[打开终端](https://cn.bing.com/search?q=%E5%A6%82%E4%BD%95%E5%9C%A8%E5%BD%93%E5%89%8D%E7%9B%AE%E5%BD%95%E6%89%93%E5%BC%80%E7%BB%88%E7%AB%AF)运行内部的可执行文件即可
[下载](https://github.com/shanmite/LotteryAutoScript/releases)
[下载](https://github.com/shanmiteko/LotteryAutoScript/releases)
[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmite/LotteryAutoScript/releases)
[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript/releases)
[Fastgit镜像下载](https://hub.fastgit.org/shanmite/LotteryAutoScript/releases)
[Fastgit镜像下载](https://hub.fastgit.org/shanmiteko/LotteryAutoScript/releases)
#### Windows
如何搭建运行环境
step1: 下载代码到本地
[点此下载](https://github.com/shanmite/LotteryAutoScript/archive/refs/heads/main.zip)或如图示下载↓
[点此下载](https://github.com/shanmiteko/LotteryAutoScript/archive/refs/heads/main.zip)或如图示下载↓
![点我加载下载操作图示](doc/pic/download.png)
@ -108,7 +103,9 @@ step3修改env.example.js文件及创建运行文件(打开扩展名显示)
3.填入相关参数
4.运行
4.`my_config.example.js`同样操作
5.运行
注: `npm i`意味安装依赖, 只需运行一次, 为防止依赖有变化遂每次都执行
@ -143,7 +140,7 @@ npm i && npm run clear
1.初始化
```bash
curl -fsSL https://cdn.staticaly.com/gh/shanmite/LotteryAutoScript/main/script/docker/init.sh | sh
curl -fsSL https://cdn.staticaly.com/gh/shanmiteko/LotteryAutoScript/main/script/docker/init.sh | sh
```
进入`lottery`文件夹
@ -151,9 +148,9 @@ curl -fsSL https://cdn.staticaly.com/gh/shanmite/LotteryAutoScript/main/script/d
cd lottery
```
编辑`env.js`与`my_config.json`文件
编辑`env.js`与`my_config.js`文件
- env.js 设置必要环境变量
- my_config.json 写入要覆盖[默认设置](#设置说明)
- my_config.js 你的设置
执行相应的脚本
> start,check,clear
@ -229,135 +226,10 @@ rm -rf lottery/
----------------------------------------
## 设置说明
### 模式选择
`lib/config.js`
<details>
<summary>点击显示所有设置的详细说明</summary>
- `model`
- `'00'`关闭自动抽奖
- `'10'`只转发官方抽奖
- `'01'`只转发非官方抽奖
- `'11'`都转
- `chatmodel`
- `'00'`关闭自动评论
- `'10'`只评论官抽
- `'01'`只评论非官抽
- `'11'`都评论
- `scan_page_num`
- 在uid或tag里检索的页数
- `number`
- `maxday`
- 开奖时间距离现在的最大天数
- 默认为`-1`表示不限制
- `string`
- `wait`
- 转发间隔时间
- 单位毫秒
- 上下浮动50%
- `string`
- `minfollower`
- up主粉丝数限制
- 仅限制没有官方认证的up
- `string`
- `only_followed`
- 只转发已关注的
- `'1'`开启
- `'0'`关闭
- `create_dy`
- 是否发送随机动态(防止被开奖机过滤)
- `'1'`开启
- `'0'`关闭
- `create_dy_num`
- 发送随机动态的数量
- `number`
- `dy_contents`
- 随机动态内容
- 类型 `content[]`
```js
/**
* @typedef Picture
* @property {string} img_src
* @property {number} img_width
* @property {number} img_height
* @param { string | Picture[] } content
*/
```
- `at_users`
- 转发时[at]的用户
- `AtInfo[]`
```js
/**
* @typedef {string} NickName
* @typedef {number} UID
* @typedef {(NickName | UID)[]} AtInfo
*/
```
- `blacklist`
- 防钓鱼uid黑名单
- 逗号分割字符串
- `blockword`
- 屏蔽词
- `string[]`
- `followWhiteList`
- 取关白名单
- 逗号分割字符串
- `relay`
- 转发评语
- `string[]`
- `chat`
- 评论内容
- `string[]`
- 若此项不为长度大于0的数组, 则使用转发评语
- `UIDs`
- 监听的UID列表
- `number[]`
- `TAGs`
- 监听的抽奖话题
- `string[]`
- `partition_id`
- 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid)
- `number`
- `is_exception`
- 是否关注异常
- `boolean`
- `clear_partition`
- 取关分区
- `string`
- `clear_max_day`
- 清理多少天内的动态或关注
- `number`
- `clear_remove_dynamic`
- 是否移除动态
- `boolean`
- `clear_remove_attention`
- 是否移除关注
- `boolean`
- `clear_remove_delay`
- 清除动态延时(毫秒)
- `number`
- `clear_dynamic_type`
- 清除动态类型
| 动态类型 | type值 |
| ---------- | ------ |
| 无 | `0` |
| 转发 | `1` |
| 含图片 | `2` |
| 无图纯文字 | `4` |
| 视频 | `8` |
| 专栏 | `64` |
| 活动 | `2048` |
- `number`
</details>
### 自定义设置
- **默认设置**存放于[config.js](lib/config.js)和[script.js](lib/Script.js)中
- 修改默认设置(非必要)
- 本地运行 => 在项目根目录下新建my_config.json文件将设置填在其中
- 填入符合[JSON语法](https://www.w3school.com.cn/json/json_syntax.asp)的内容
- 字段的名称和对应的值按照[字段解释](#模式选择)要求填写
- 本地运行 => 在项目根目录下新建my_config.js文件将设置填在其中
- 多账号的设置
分别存储于键`"config_1"``"config_2"`...`"config_n"`中, 例如
```json
@ -369,7 +241,4 @@ rm -rf lottery/
"model": "11"
}
}
```
- [自定义设置模板](https://github.com/shanmite/LotteryAutoScript/issues/62#issuecomment-808882833)
<!-- 关于如何在GitHub Actions中运行 请查看历史提交记录 -->
```

View File

@ -9,7 +9,7 @@ const Base = {
/**环境变量设置文件 */
env_file: path.join(process.cwd(), "env.js"),
/**配置文件 */
config_file: path.join(process.cwd(), "my_config.json"),
config_file: path.join(process.cwd(), "my_config.js"),
/**dyid存储文件 */
dyids_dir: path.join(process.cwd(), "dyids"),
/**

View File

@ -113,11 +113,8 @@ class Monitor extends Public {
/** 所有抽奖信息 */
let alllotteryinfo = [];
const { model, chatmodel, maxday: _maxday, minfollower, only_followed, at_users, blockword, blacklist } = config;
const maxday = (_maxday === '-1' || _maxday === '')
? Infinity
: (Number(_maxday) * 86400);
const { model, chatmodel, is_imitator, maxday: _maxday, minfollower, skip_official_verify, only_followed, at_users, blockword, blacklist } = config;
const maxday = _maxday * 86400
let dyids_set = new Set();
for (const info of protoLotteryInfo) {
const { lottery_info_type, uids, uname, dyid, official_verify, ctrl, befilter, rid, des, type, hasOfficialLottery } = info;
@ -148,27 +145,29 @@ class Monitor extends Public {
const isTwoLevelRelay = /\/\/@/.test(description);
const haslottery = /[抽奖]/.test(description);
const hasGuanZhuan = /[转关].*[转关]/.test(description);
if (hasOfficialLottery && model[0] === '1') {
if (lottery_info_type === 'uid' && is_imitator) {
isLottery = true;
} else if (hasOfficialLottery && model[0] === '1') {
({ ts } = await BiliAPI.getLotteryNotice(dyid));
if (ts < 0) { alllotteryinfo = null; break }
isLottery = ts > now_ts_10 && ts < now_ts_10 + maxday;
isSendChat = chatmodel[0] === '1';
} else if (!hasOfficialLottery && model[1] === '1' && haslottery && hasGuanZhuan && !isTwoLevelRelay) {
({ ts } = Base.getLotteryNotice(description));
if (!official_verify) {
if (official_verify && skip_official_verify) {
isLottery = ts === 0 || (ts > now_ts_10 && ts < now_ts_10 + maxday);
} else {
const followerNum = await BiliAPI.getUserInfo(uid);
if (followerNum < 0) { alllotteryinfo = null; break }
if (followerNum < Number(minfollower)) continue;
if (followerNum < minfollower) continue;
isLottery = !befilter && (ts === 0 || (ts > now_ts_10 && ts < now_ts_10 + maxday));
} else {
isLottery = ts === 0 || (ts > now_ts_10 && ts < now_ts_10 + maxday);
}
isSendChat = chatmodel[1] === '1';
}
if (isLottery) {
/* 判断是否关注过 */
const isFollowed = (new RegExp(uid)).test(self.attentionList);
if (only_followed === '1' && !isFollowed) continue;
if (only_followed && !isFollowed) continue;
/* 判断是否转发过 */
const isRelay = await MyStorage.searchDyid(dyid);
/* 获取黑名单并去重合并 */

View File

@ -194,7 +194,7 @@ class Public {
if (_modify === null) return null;
mDRdata.push.apply(mDRdata, _modify.modifyDynamicResArray);
next_offset = _modify.nextinfo.next_offset;
await Base.delay(1000);
await Base.delay(config.search_wait);
}
const fomatdata = mDRdata.map(o => {
const hasOrigin = o.type === 1;
@ -223,7 +223,7 @@ class Public {
*/
async getLotteryInfoByUID(UID) {
Base.tooltip.log(`开始获取用户${UID}的动态信息`);
const { allModifyDynamicResArray: aMDRA } = await this.checkAllDynamic(UID, config.scan_page_num, 1000);
const { allModifyDynamicResArray: aMDRA } = await this.checkAllDynamic(UID, config.scan_page_num, config.search_wait);
if (!aMDRA.length) return null;
const fomatdata = aMDRA.map(o => {
return {

View File

@ -1,75 +1,22 @@
const { config_file, tooltip } = require('./Base');
/**
* 默认设置 具体含义参见README
* 如需修改请按照README文件要求填写在指定位置
* 直接修改文件自动更新时会被重置
*/
const default_config = {
model: '11',
chatmodel: '01',
scan_page_num: 3,
maxday: '-1',
wait: '100000',
minfollower: '1000',
only_followed: '0',
create_dy: '1',
create_dy_num: 1,
dy_contents: ['[doge]'],
at_users: [['转发抽奖娘', 294887687], ['你的工具人老公', 100680137]],
/* 与最新黑名单同步 */
blacklist: '28008897,28272016,140389827,24598781,28008860,28008880,28008743,28008948,28009292,319696958,90138218,28272000,28272047,28271978,8831288,175979009,3177443,486780865,403048135,474325039,455274996,477519424,292671666,448873224,22498938,1770865,444796995,306112375,320193786,606637517,305276429,204487541,404761800,186914127,99439379,457697569,270886929,477519424,401575,201296348,206804212,333584926,34679178,699923691,392689522,178700744,272882445,350977368,487168411,22682842,444949061,523974463,192231907,503908324,383189098,252909207,336467750,264875137,90721742,452299642,677739290,441522918,8766623,698327474,5439672,483247863,237055308,95404163,202052696,1309889741,627942060,455030741,406353670,18036870,470220612',
blockword: ["脚本抽奖", "恭喜", "结果", "抽奖号"],
followWhiteList: '',
relay: ['转发动态'],
chat: [
'[OK]', '[星星眼]', '[歪嘴]', '[喜欢]', '[偷笑]', '[笑]', '[喜极而泣]', '[辣眼睛]', '[吃瓜]', '[奋斗]',
'永不缺席 永不中奖 永不放弃!', '万一呢', '在', '冲吖~', '来了', '万一', '[保佑][保佑]', '从未中,从未停', '[吃瓜]', '[抠鼻][抠鼻]',
'来力', '秋梨膏', '[呲牙]', '从不缺席', '分子', '可以', '恰', '不会吧', '1', '好',
'rush', '来来来', 'ok', '冲', '凑热闹', '我要我要[打call]', '我还能中!让我中!!!', '大家都散了吧,已经抽完了,是我的', '我是天选之子', '给我中一次吧!',
'坚持不懈,迎难而上,开拓创新!', '[OK][OK]', '我来抽个奖', '中中中中中中', '[doge][doge][doge]', '我我我',
],
partition_id: 0,
is_exception: false,
clear_partition: '',
clear_max_day: 30,
clear_remove_dynamic: true,
clear_remove_attention: true,
clear_remove_delay: 8000,
clear_dynamic_type: 1
};
/**
* 自己修改过的设置
*/
const my_config = (() => {
let _my_config = {}
if (process.env.LOCALLAUNCH) {
try {
_my_config = require(config_file)
} catch (e) {
tooltip.log("[config]无自定义设置\n" + e);
}
} else {
try {
const { MY_CONFIG } = process.env;
if (MY_CONFIG) {
_my_config = JSON.parse(MY_CONFIG);
}
} catch (_) {
tooltip.log("[config]MY_CONFIG语法错误");
}
try {
_my_config = require(config_file)
} catch (e) {
tooltip.log("[config]自定义设置异常 原因如下:\n" + e);
}
return _my_config;
})();
const config = {
...default_config,
...my_config["default_config"],
/**
* @param {string} n
*/
updata(n) {
const new_config = my_config[`config_${n}`] || my_config;
const new_config = my_config[`config_${n}`] || {};
Object.entries(new_config)
.forEach(([k, v]) => this[k] = v)
}

View File

@ -13,7 +13,7 @@ const MAX_TIME = 6 * 60 * 60 * 1000 - 6 * 60 * 1000;
async function createRandomDynamic(num) {
Base.tooltip.log(`准备创建${num}条随机动态`);
if (config.create_dy === '1') {
if (config.create_dy) {
const Dynamic = await Public.prototype.checkAllDynamic(GlobalVar.get("myUID"), 1);
if ((Dynamic.allModifyDynamicResArray[0] || { type: 0 }).type === 1) {
for (let index = 0; index < num; index++) {

View File

@ -61,7 +61,7 @@ async function main() {
}
}
} else {
tooltip.log('请查看README文件, 在指定位置填入cookie')
tooltip.log('请查看README文件, 在env.js指定位置填入cookie')
}
}
} else {

183
my_config.example.js Normal file
View File

@ -0,0 +1,183 @@
module.exports = {
/**
* 默认设置(公用)
*/
default_config: {
/**
* - '00' 关闭自动抽奖
* - '10' 只转发官方抽奖
* - '01' 只转发非官方抽奖
* - '11' 都转
*/
model: '11',
/**
* - '00'关闭自动评论
* - '10'只评论官抽
* - '01'只评论非官抽
* - '11'都评论
*/
chatmodel: '01',
/**
* 不加判断的转发所监视的uid转发的动态
*/
is_imitator: false,
/**
* - 在uid或tag里检索的页数
*/
scan_page_num: 3,
/**
* - 开奖时间距离现在的最大天数
* - 默认不限制
*/
maxday: Infinity,
/**
* - 转发间隔时间
* - 单位毫秒
* - 上下浮动50%
*/
wait: 100000,
/**
* - 检索动态间隔
* - 单位毫秒
*/
search_wait: 1000,
/**
* - up主粉丝数限制
*/
minfollower: 1000,
/**
* 粉丝数限制是否跳过有官方认证的up
*/
skip_official_verify: true,
/**
* - 只转发已关注的
*/
only_followed: false,
/**
* - 是否发送随机动态(防止被开奖机过滤)
*/
create_dy: false,
/**
* - 发送随机动态的数量
*/
create_dy_num: 1,
/**
* - 随机动态内容
* - 类型 `content[]`
*/
/**
* @typedef Picture
* @property {string} img_src 站内源
* @property {number} img_width
* @property {number} img_height
* @param { string | Picture[] } content
*/
dy_contents: ['[doge]', '[doge][doge]'],
/**
* 转发时[at]的用户
*/
at_users: [['转发抽奖娘', 294887687], ['你的工具人老公', 100680137]],
/**
* 同步 https://gitee.com/shanmite/lottery-notice/raw/master/notice.json
*/
blacklist: '1,2',
/**
* 屏蔽词
*/
blockword: ["脚本抽奖", "恭喜", "结果", "抽奖号"],
/**
* 取关白名单
*/
followWhiteList: '1,2',
/**
* 转发评语
*/
relay: ['转发动态'],
/**
* 评论内容
*/
chat: [
'[OK]', '[星星眼]', '[歪嘴]', '[喜欢]', '[偷笑]', '[笑]', '[喜极而泣]', '[辣眼睛]', '[吃瓜]', '[奋斗]',
'永不缺席 永不中奖 永不放弃!', '万一呢', '在', '冲吖~', '来了', '万一', '[保佑][保佑]', '从未中,从未停', '[吃瓜]', '[抠鼻][抠鼻]',
'来力', '秋梨膏', '[呲牙]', '从不缺席', '分子', '可以', '恰', '不会吧', '1', '好',
'rush', '来来来', 'ok', '冲', '凑热闹', '我要我要[打call]', '我还能中!让我中!!!', '大家都散了吧,已经抽完了,是我的', '我是天选之子', '给我中一次吧!',
'坚持不懈,迎难而上,开拓创新!', '[OK][OK]', '我来抽个奖', '中中中中中中', '[doge][doge][doge]', '我我我',
],
/**
* 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid)
*/
partition_id: 0,
/**
* 是否关注异常
*/
is_exception: false,
/**
* 取关分区
*/
clear_partition: '',
/**
* 清理多少天内的动态或关注
*/
clear_max_day: 30,
/**
* 是否移除动态
*/
clear_remove_dynamic: true,
/**
* 是否移除关注
*/
clear_remove_attention: true,
/**
* 清除动态延时(毫秒)
*/
clear_remove_delay: 8000,
/**
* 清除动态类型
| 动态类型 | type值 |
| ---------- | ------ |
| | `0` |
| 转发 | `1` |
| 含图片 | `2` |
| 无图纯文字 | `4` |
| 视频 | `8` |
| 专栏 | `64` |
| 活动 | `2048` |
*/
clear_dynamic_type: 1
},
/**
* 针对某一账号的特别设置
* config_[数字] 依次类推
*/
config_1: {},
config_2: {},
config_3: {}
}

View File

@ -1,6 +1,11 @@
$CONFIG_FILE = "my_config.json"
$TEMPLATE_CONFIG_FILE = "my_config.example.js"
$TEMPLATE_ENV_FILE = "env.example.js"
$CONFIG_FILE = "my_config.js"
$ENV_FILE = "env.js"
$TARGET_DIR = ".\dist"
$WIN_BIN = "lottery-in-bili-win.exe"
$LINUX_BIN = "lottery-in-bili-linux"
$MACOS_BIN = "lottery-in-bili-macos"
@ -11,11 +16,13 @@ $MACOS_X64 = "nlts-macos-x64"
$MAP = @{ $WIN_X64 = $WIN_BIN; $LINUX_X64 = $LINUX_BIN; $MACOS_X64 = $MACOS_BIN}
Copy-Item -Path "env.example.js" -Destination .\dist -Force
Copy-Item -Path $TEMPLATE_ENV_FILE -Destination $TARGET_DIR -Force
Copy-Item -Path $TEMPLATE_CONFIG_FILE -Destination $TARGET_DIR -Force
cd .\dist
Set-Location -Path $TARGET_DIR
Move-Item -Path "env.example.js" -Destination $ENV_FILE -Force
Move-Item -Path $TEMPLATE_ENV_FILE -Destination $ENV_FILE -Force
Move-Item -Path $TEMPLATE_CONFIG_FILE -Destination $CONFIG_FILE -Force
foreach($X64 in $MAP.Keys) {
$BIN = $MAP[$X64]
@ -24,10 +31,9 @@ foreach($X64 in $MAP.Keys) {
}
Move-Item -Path $BIN -Destination $X64 -Force
Copy-Item -Path $ENV_FILE -Destination $X64 -Force
cd $X64
Set-Content -Path $CONFIG_FILE -Value "{`n`t`"config_1`":{}`n}" -Force
cd ..
Copy-Item -Path $CONFIG_FILE -Destination $X64 -Force
Compress-Archive -Path $X64 -DestinationPath $X64 -Force
}
Remove-Item -Path $ENV_FILE
Remove-Item -Path $ENV_FILE
Remove-Item -Path $CONFIG_FILE