diff --git a/.github/check.png b/.github/check.png
deleted file mode 100644
index be031c3..0000000
Binary files a/.github/check.png and /dev/null differ
diff --git a/.github/check_me.png b/.github/check_me.png
new file mode 100644
index 0000000..d44bb4e
Binary files /dev/null and b/.github/check_me.png differ
diff --git a/.github/menu.png b/.github/menu.png
deleted file mode 100644
index ad425a8..0000000
Binary files a/.github/menu.png and /dev/null differ
diff --git a/.gitignore b/.gitignore
index 732bbd0..40b24ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,5 +2,5 @@ node_modules/
lib/GlobalVar.json
lib/dyid.txt
dyid.zip
-env.bat
+env.js
my_config.json
\ No newline at end of file
diff --git a/README.md b/README.md
index 3b3eba3..fe74b6e 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@
## 操作步骤
-★ Star
+右上角★ Star
↓↓
@@ -108,7 +108,7 @@ Chrome浏览器:
也可以采用**其他方式获取**所需的Cookie
只需含有 `DedeUserID=...;SESSDATA=...;bili_jct=...` 三项即可
-(分号分割,顺序随意)
+(分号分割, 不要换行, 顺序随意)
↓↓
@@ -141,7 +141,7 @@ Chrome浏览器:
#### 手动检查
手动触发`Automatic check`工作流后可在日志中查看
-
+
#### 中奖推送(可选)
> 例如在 `Repository secrets` 中新建一个 `SCKEY` 并填入对应的值
> 
@@ -194,6 +194,8 @@ Chrome浏览器:

+其中每条`workflow`都可点开查看`Run in Nodejs`里的日志
+
---
## 清理动态
@@ -234,110 +236,57 @@ Chrome浏览器:
### 本地运行
由于Github服务器共用IP导致脚本易发生访问频繁, 且滥用行为可能会封禁Actions可选择在本地运行
-具体操作详见[env.example.bat](env.example.bat)文件
+具体操作详见[env.example.js](env.example.js)文件
-win系统环境配置及定时计划运行
-
-step1:环境配置
-
-下载代码到本地
+step1: 下载代码到本地
[点此下载](https://github.com/shanmite/LotteryAutoScript/archive/refs/heads/main.zip)或如图示下载↓

-下载的压缩包解压后修改env.example.bat文件,详见step3
+下载的压缩包解压后修改env.example.js文件,详见step3
-step2:下载并安装Node.js
+step2: 下载并安装Node.js
[点此进入nodejs下载页面](http://nodejs.cn/download)

-step3:修改env.example.bat文件及创建运行文件
+step3:修改env.example.js文件及创建运行文件
-1.step1下载的压缩包解压后将其中的`env.example.bat`文件重命名为`env.bat`
+1.step1下载的压缩包解压后将其中的`env.example.js`文件重命名为`env.js`
-2.右键`env.bat`文件选择编辑或用记事本打开
+2.右键`env.js`文件选择编辑或用记事本打开
-3.使用 -[填入COOKIE](#填入cookie) 操作获取cookie,将字段其中包含`%`的修改成`%%`,多输入一个`%`避免转义
+3.填入相关参数
-4.将cookie填入文件对应值中
+4.运行
+新建`start.bat`(windows)或`start.sh`(linux)文件写入以下内容
+即在当前目录下运行执行以下命令
+注: `npm i`意味安装依赖, 只需运行一次, 为防止依赖有变化遂每次都执行
-```
-set COOKIE= 你在浏览器获取后并修改了%的cookie
-…………
-(后面的按照文件中的提示填写)
-```
-
-5.在`env.bat`文件同一根目录下新建一个`start.bat`文件,用于运行程序
-
-
-
-6.右键`start.bat`文件选择编辑或用记事本打开,填入以下内容(内容具体含义详见`env.bat`文件,可根据个人需求选择其中一条)
-
-```
-npm run test_start
-```
-或
-```
-npm run test_check
-```
-或
-```
-npm run test_clear
+启动抽奖
+```bash
+npm i
+npm run start
```
-8.确入修改无误后,将`env.bat`文件中前面含有`::`的注释全部删除,只保留`chcp 65001`语句和含有前缀`set`的语句
-
-9.上一步操作仍可能无法修改默认编码,此时可以去搜索引擎搜索永久修改cmd默认编码为`65001`的方法,这里不赘述了
-
-10.以上修改都保存成功后,点击`start.bat`文件即可启动
-
-11.注意事项
-
-```
-运行成功后在lib文件夹下会生成一个GlobalVar.json文件和dyid.txt文件
-==换env.bat的参数时须先将GlobalVar.json文件删除==
-==注意运行时请去掉注释==
-==注意 bat文件中% 要转义写为 %%==
-如果要运行多账号只能复制本项目并依次独立运行
-在lib/Public.js文件getLotteryInfoByTag方法和getLotteryInfoByUID方法中可适当增大扫描范围 默认3页
+检查中奖
+```bash
+npm i
+npm run check
```
-step4:本地定时运行(在Windows系统的操作)
+清理动态
+```
+npm i
+npm run clear
+```
-1.右键我的电脑打开控制面板,或在win10搜索框里搜索控制面板打开
+4.以上修改都保存成功后,点击`start.bat`文件即可启动
-2.在`控制面板`右上角的搜索框里搜索`计划任务`点击打开
-
-3.在`任务计划程序`中选择`任务计划程序库`
-
-4.在右边的操作框中选择`创建任务`
-
-5.在`常规`页面中的名称框中写入计划名称后,在`安全选项`里选择`不管用户是否登陆都要运行`,`使用最高权限运行`
-
-6.在`触发器`页面中规划时间,点击`新建`,选择设置`每天`和具体开始时间以及间隔时间,高级设置直接看情况选择
-
-7.在`操作`页面中点击`新建`,选择操作为`启动程序`,在设置里点击浏览找到`start.bat`文件并选择,在`起始于(可选)(T):`中的空白框里输入`start.bat`文件的目录地址,也就是`程序或脚本(P):`里`start.bat`的前面那一串目录地址,最后是以`\`结尾的 ,填好东西后按下面`确认`
-
-
-
-8.在`条件`页面中选择`网络`,设定启动条件为任何连接
-
-9.在`设置`页面中选择如图示选项,或者不修改默认设置
-
-
-
-10.最后按`确定`
-
-11.此时它会弹框要求输入用户密码,一般是你的开机密码确认身份,这个对于服务器来说就是远程桌面开启的那个密码
-
-最后你可以在任务列表中选择已有的任务,右边的操作框中选择`运行`点击,启动计划的任务,如下图所示
-
-
-
-具体看任务是否正常执行,你可以看看自己的账号动态的最新转发,运行成功每几分钟自动转发抽奖动态
+> [windows系统定时运行](./doc/win_schedule.md)
+> [linux系统定时运行](https://zhuanlan.zhihu.com/p/58719487)
### 多账号支持
默认支持5个账号
diff --git a/doc/win_schedule.md b/doc/win_schedule.md
new file mode 100644
index 0000000..4300e39
--- /dev/null
+++ b/doc/win_schedule.md
@@ -0,0 +1,35 @@
+## win系统定时计划运行
+
+本地定时运行(在Windows系统的操作)
+
+1.右键我的电脑打开控制面板,或在win10搜索框里搜索控制面板打开
+
+2.在`控制面板`右上角的搜索框里搜索`计划任务`点击打开
+
+3.在`任务计划程序`中选择`任务计划程序库`
+
+4.在右边的操作框中选择`创建任务`
+
+5.在`常规`页面中的名称框中写入计划名称后,在`安全选项`里选择`不管用户是否登陆都要运行`,`使用最高权限运行`
+
+6.在`触发器`页面中规划时间,点击`新建`,选择设置`每天`和具体开始时间以及间隔时间,高级设置直接看情况选择
+
+7.在`操作`页面中点击`新建`,选择操作为`启动程序`,在设置里点击浏览找到`start.bat`文件并选择,在`起始于(可选)(T):`中的空白框里输入`start.bat`文件的目录地址,也就是`程序或脚本(P):`里`start.bat`的前面那一串目录地址,最后是以`\`结尾的 ,填好东西后按下面`确认`
+
+
+
+8.在`条件`页面中选择`网络`,设定启动条件为任何连接
+
+9.在`设置`页面中选择如图示选项,或者不修改默认设置
+
+
+
+10.最后按`确定`
+
+11.此时它会弹框要求输入用户密码,一般是你的开机密码确认身份,这个对于服务器来说就是远程桌面开启的那个密码
+
+最后你可以在任务列表中选择已有的任务,右边的操作框中选择`运行`点击,启动计划的任务,如下图所示
+
+
+
+具体看任务是否正常执行,你可以看看自己的账号动态的最新转发,运行成功每几分钟自动转发抽奖动态
diff --git a/env.example.bat b/env.example.bat
deleted file mode 100644
index f7421ed..0000000
--- a/env.example.bat
+++ /dev/null
@@ -1,51 +0,0 @@
-chcp 65001
-:: 1.运行环境配置
-:: 下载代码到本地 https://github.com/shanmite/LotteryAutoScript/archive/refs/heads/main.zip
-:: 安装Node.js http://nodejs.cn/download
-
-:: 2.环境变量配置
-:: 此批处理脚本为本地运行代码前设置环境变量时所需
-:: 使用时先将本文件名改成env.bat
-:: 填入相应的值
-set COOKIE=
-set NUMBER=1
-set CLEAR=
-set LOCALLAUNCH=true
-set CLEAR=true
-:: 以下是推送所需环境变量(可不填)
-set SCKEY=
-set SENDKEY=
-set QQ_SKEY=
-set QQ_MODE=
-set BARK_PUSH=
-set BARK_SOUND=
-set TG_BOT_TOKEN=
-set TG_USER_ID=
-set TG_PROXY_HOST=
-set TG_PROXY_PORT=
-set DD_BOT_TOKEN=
-set DD_BOT_SECRET=
-set QYWX_KEY=
-set IGOT_PUSH_KEY=
-set PUSH_PLUS_TOKEN=
-set PUSH_PLUS_USER=
-set SMTP_HOST=
-set SMTP_PORT=
-set SMTP_USER=
-set SMTP_PASS=
-set SMTP_TO_USER=
-
-:: 2.运行
-:: 在当前目录下新建一个start.bat
-:: 填入 npm run test_start 启动脚本
-:: 填入 npm run test_check 检查是否中奖
-:: 填入 npm run test_clear 清空动态和关注
-:: 点击start.bat即可启动
-
-:: 3.注意事项
-:: 运行成功后在lib文件夹下会生成一个GlobalVar.json文件和dyid.txt文件
-:: ==换参数时须先将GlobalVar.json文件删除==
-:: ==注意运行时请去掉注释==
-:: ==注意 % 要转义为 %%==
-:: 如果要运行多账号只能复制本项目并依次独立运行
-:: 在lib/Public.js文件getLotteryInfoByTag方法和getLotteryInfoByUID方法中可适当增大扫描范围 默认3页
\ No newline at end of file
diff --git a/env.example.js b/env.example.js
new file mode 100644
index 0000000..a018f98
--- /dev/null
+++ b/env.example.js
@@ -0,0 +1,51 @@
+/**
+ * 使用时请将此文件命名为env.js
+ */
+
+/**
+ * 账号相关参数
+ * `COOKIE` 是必填项
+ * `NUMBER` 表示是第几个账号
+ * `PAT` 与 `GITHUB_REPOSITORY` 两项是为了从构件中下载已转发信息
+ */
+const account_parm = {
+ "COOKIE": "",
+ "NUMBER": 1,
+ "CLEAR": true,
+ "LOCALLAUNCH": true,
+ "PAT": "",
+ "GITHUB_REPOSITORY": "用户名/仓库名"
+}
+
+/**
+ * 推送相关参数
+ */
+const push_parm = {
+ "SCKEY=": "",
+ "SENDKEY": "",
+ "QQ_SKEY": "",
+ "QQ_MODE": "",
+ "BARK_PUSH": "",
+ "BARK_SOUND": "",
+ "TG_BOT_TOKEN": "",
+ "TG_USER_ID": "",
+ "TG_PROXY_HOST": "",
+ "TG_PROXY_PORT": "",
+ "DD_BOT_TOKEN": "",
+ "DD_BOT_SECRET": "",
+ "QYWX_KEY": "",
+ "IGOT_PUSH_KEY": "",
+ "PUSH_PLUS_TOKEN": "",
+ "PUSH_PLUS_USER": "",
+ "SMTP_HOST": "",
+ "SMTP_PORT": "",
+ "SMTP_USER": "",
+ "SMTP_PASS": "",
+ "SMTP_TO_USER": ""
+}
+
+process.env = {
+ ...process.env,
+ ...account_parm,
+ ...push_parm
+}
\ No newline at end of file
diff --git a/lib/Base.js b/lib/Base.js
index ccd3bee..2cc5932 100644
--- a/lib/Base.js
+++ b/lib/Base.js
@@ -173,18 +173,19 @@ const Base = {
*/
transformTimeZone: (ts, zoneOffset) => new Date(new Date(ts).getTime() + zoneOffset * 60 * 60 * 1000).toLocaleString(),
/**
- * ifNotExistCreateFile
+ * CreateFile
* @param {string} filepath 相对于lib的文件路径
* @param {string} [defaultValue] 写入默认值
+ * @param {string} flag
* @returns {Promise}
*/
- ifNotExistCreateFile: (filepath, defaultValue = '') => {
+ createFile: (filepath, defaultValue, flag) => {
const fpath = path.join('./lib', filepath);
const buffer = Buffer.from(defaultValue);
return new Promise((resolve, rejects) => {
- fs.open(fpath, 'wx', (err, fd) => {
+ fs.open(fpath, flag, (err, fd) => {
if (err) {
- resolve();
+ rejects(err)
} else {
fs.write(fd, buffer, 0, buffer.length, 0, err => {
if (err) {
diff --git a/lib/BiliAPI.js b/lib/BiliAPI.js
index d4108fa..1536cf8 100644
--- a/lib/BiliAPI.js
+++ b/lib/BiliAPI.js
@@ -154,7 +154,7 @@ const BiliAPI = {
if (res.code === 0) {
const { unfollow_unread, follow_unread } = res.data;
resolve({ unfollow_unread, follow_unread });
- tooltip.log(`[获取未读私信]成功 follow_unread: ${follow_unread}, unfollow_unread: ${unfollow_unread}`);
+ tooltip.log(`[获取未读私信]成功 已关注未读数: ${follow_unread}, 未关注未读数 ${unfollow_unread}`);
} else {
resolve(null);
tooltip.log(`[获取未读私信]失败\n${responseText}`);
diff --git a/lib/MyStorage.js b/lib/MyStorage.js
index df92ac4..ef2b8b9 100644
--- a/lib/MyStorage.js
+++ b/lib/MyStorage.js
@@ -1,5 +1,4 @@
const Base = require("./Base");
-const { ifNotExistCreateFile } = require("./Base");
const GihubAPI = require("./GithubAPI");
const MyStorage = {
@@ -16,12 +15,12 @@ const MyStorage = {
Base.tooltip.log('存储初始化成功');
} else {
Base.tooltip.log('存储初始化失败');
- await ifNotExistCreateFile('dyid.txt')
+ await Base.createFile('dyid.txt', '', 'a')
}
resolve()
})
} else {
- await ifNotExistCreateFile('dyid.txt')
+ await Base.createFile('dyid.txt', '', 'a')
resolve()
}
})
diff --git a/lib/setVariable.js b/lib/setVariable.js
index 842d5bd..6b1f732 100644
--- a/lib/setVariable.js
+++ b/lib/setVariable.js
@@ -1,6 +1,6 @@
-const Script = require("./Script");
-const MyStorage = require("./MyStorage");
const Base = require("./Base");
+const MyStorage = require("./MyStorage");
+const Script = require("./Script");
let GlobalVar = {
cookie: '',
@@ -30,12 +30,12 @@ async function setVariable(cookie) {
GlobalVar.csrf = GlobalVar.bili_jct;
GlobalVar.myUID = GlobalVar.DedeUserID;
GlobalVar.remoteconfig = await Base.getRemoteConfig();
- await Base.ifNotExistCreateFile('GlobalVar.json', JSON.stringify(GlobalVar));
+ await Base.createFile('GlobalVar.json', JSON.stringify(GlobalVar), 'w');
}
if (process.env.PAT) {
await MyStorage.init()
} else {
- await Base.ifNotExistCreateFile('dyid.txt')
+ await Base.createFile('dyid.txt', '', 'a')
}
return
}
diff --git a/main.js b/main.js
index 039b784..23eb5c1 100644
--- a/main.js
+++ b/main.js
@@ -1,11 +1,16 @@
const { tooltip } = require("./lib/Base");
-const { setVariable } = require("./lib/setVariable");
-const { NUMBER, CLEAR, COOKIE, PAT, LOCALLAUNCH } = process.env;
+try {
+ require("./env");
+} catch (error) {
+ tooltip.log("无env.js文件");
+}
((async () => {
- if (typeof COOKIE === 'string' && COOKIE.length > 10) {
+ const { NUMBER, CLEAR, COOKIE, PAT, LOCALLAUNCH } = process.env;
+ if (COOKIE) {
if (!LOCALLAUNCH && !PAT) { tooltip.log('请查看README文件, 填入相应的PAT'); return; }
+ const { setVariable } = require("./lib/setVariable");
await setVariable(COOKIE);
const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs");
const { clear } = require("./lib/clear");
diff --git a/package.json b/package.json
index e4c87f3..b4a85e9 100644
--- a/package.json
+++ b/package.json
@@ -6,10 +6,7 @@
"scripts": {
"start": "node main.js start",
"clear": "node main.js clear",
- "check": "node main.js check",
- "test_start": "npm install && env.bat && node main.js start",
- "test_clear": "npm install && env.bat && node main.js clear",
- "test_check": "npm install && env.bat && node main.js check"
+ "check": "node main.js check"
},
"repository": {
"type": "git",