mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-07-22 21:13:47 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c269b2f96 | ||
|
|
3851f51621 | ||
|
|
d676a10e56 | ||
|
|
88d3e97595 | ||
|
|
88ad8ecfcc | ||
|
|
478d10d27e | ||
|
|
6fbcf6e0b7 | ||
|
|
8bf47698ad | ||
|
|
c0bc4878e3 | ||
|
|
e9b7965a76 | ||
|
|
0a54cd20db | ||
|
|
a2591f260a | ||
|
|
e6dc9d7abb | ||
|
|
179f4d0d41 | ||
|
|
5a625dbd12 | ||
|
|
65fd4b3112 | ||
|
|
14067ca923 | ||
|
|
33e55721f6 | ||
|
|
aa1aad7ddd | ||
|
|
0c0d112aaf | ||
|
|
b4ec45a48d | ||
|
|
1ce8e966e8 | ||
|
|
f252365809 | ||
|
|
30fee87485 | ||
|
|
214abd449f | ||
|
|
79b348d37e | ||
|
|
965734c2f2 | ||
|
|
3cc42c0fc5 | ||
|
|
b24c32a877 | ||
|
|
ef822df5bf | ||
|
|
9842107f52 | ||
|
|
89dea18ae3 | ||
|
|
a426eb48f5 | ||
|
|
c06f69457a | ||
|
|
155332751f | ||
|
|
a28ec20b12 | ||
|
|
35cb1c24c2 | ||
|
|
4f961250be | ||
|
|
dce1ff61fd | ||
|
|
ab6bc97f50 | ||
|
|
da8903944a | ||
|
|
08f4375c21 | ||
|
|
ec0c5da092 | ||
|
|
7d3273611f | ||
|
|
673b3883a8 | ||
|
|
f157761f5c | ||
|
|
c57d21d4cd | ||
|
|
26ae391eee | ||
|
|
a1b055b9de | ||
|
|
d2d9d31ebf | ||
|
|
fdee933ca4 | ||
|
|
53ae976caf | ||
|
|
de88467c03 | ||
|
|
6bbbfbb521 | ||
|
|
e7ab5790cd | ||
|
|
6c08cee944 | ||
|
|
236fcb6284 | ||
|
|
8bc053b352 | ||
|
|
f5a8ad75d2 | ||
|
|
cbce4b113d | ||
|
|
a63456bd29 | ||
|
|
329e6931dd | ||
|
|
309371fbd7 | ||
|
|
6f81360d2a | ||
|
|
4e377f1c41 | ||
|
|
79c550db14 | ||
|
|
28c2af93cf | ||
|
|
11aec87eed | ||
|
|
2442d5c46d | ||
|
|
a21b0dd33e | ||
|
|
ce3274c258 | ||
|
|
455c81ee55 | ||
|
|
18760ebaac | ||
|
|
266a657a8f | ||
|
|
ebf7440ef2 | ||
|
|
a0e668bcb5 | ||
|
|
a47472a3e4 | ||
|
|
3698c81384 | ||
|
|
ad7df1aa74 |
@@ -1,11 +0,0 @@
|
||||
---
|
||||
name: 新功能请求
|
||||
about: 提出你想要的功能或你的建议
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### 清晰而简明地描述
|
||||
在此写下你的描述
|
||||
@@ -1,33 +0,0 @@
|
||||
---
|
||||
name: Bug 反馈
|
||||
about: 提出你遇到的问题, 提问之前请检索问题是否重复
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### 在反馈bug之前,请确保你已经认真阅读了本项目的README和脚本的内置说明
|
||||
**描述bug**
|
||||
简要描述所遇到的bug
|
||||
|
||||
**重现bug**
|
||||
说明您在进行了怎样的操作后出现了bug
|
||||
1. xxx
|
||||
2. xxx
|
||||
|
||||
**预期行为**
|
||||
简要描述进行以上操作后预期的脚本行为
|
||||
|
||||
**截图**
|
||||
如果可以,请提供有关截图
|
||||
|
||||
**运行日志**
|
||||
控制台日志。
|
||||
|
||||
**使用环境:**
|
||||
- Github Actions中
|
||||
- 本地运行
|
||||
|
||||
**其他**
|
||||
若您有其他想要补充的内容,请在此说明
|
||||
@@ -0,0 +1,107 @@
|
||||
name: Bug反馈
|
||||
description: 提出你遇到的问题
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
**为避免无效问题和冗余问题,提问前请确认**
|
||||
- 你确定搜索引擎不能解决你的问题
|
||||
- 你确定提供的Readme文档和Release说明不能解决你的问题
|
||||
- 你确定已有的issue不能解决你的问题
|
||||
- 你确定issue的title能简明的描述你的问题
|
||||
<br />
|
||||
|
||||
- id: describe
|
||||
type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: "描述Bug"
|
||||
description: |
|
||||
简要而清晰的描述你所遇到的bug。
|
||||
|
||||
- id: reproduction
|
||||
type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: "重现Bug"
|
||||
description: |
|
||||
说明您在进行了怎样的操作后出现了Bug.
|
||||
placeholder: |
|
||||
1. xxx
|
||||
2. xxx
|
||||
|
||||
- id: expection
|
||||
type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: "预期行为"
|
||||
description: |
|
||||
简要描述进行以上操作后预期的脚本行为。
|
||||
|
||||
- id: picture
|
||||
type: textarea
|
||||
validations:
|
||||
required: false
|
||||
attributes:
|
||||
label: "截图"
|
||||
description: |
|
||||
如果可以,请提供尽可能多的相关截图。
|
||||
placeholder: |
|
||||
可使用 QQ / Snipaste 等工具截图后在此处 ctrl + v 黏贴。
|
||||
|
||||
- id: log
|
||||
type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: "运行日志"
|
||||
description: |
|
||||
控制台日志。
|
||||
placeholder: |
|
||||
请在此黏贴运行日志。
|
||||
|
||||
- id: system
|
||||
type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: "操作系统"
|
||||
description: |
|
||||
请给出操作系统名称和版本号。
|
||||
placeholder: |
|
||||
eg: Windows 10
|
||||
|
||||
- id: nodejs_version
|
||||
type: input
|
||||
validations:
|
||||
required: false
|
||||
attributes:
|
||||
label: "NodeJs版本"
|
||||
description: |
|
||||
若使用源码运行请在控制台输入`node -v`查看版本号。
|
||||
placeholder: |
|
||||
eg: v16.5.0
|
||||
|
||||
- id: lotteryAutoScript_version
|
||||
type: input
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: "脚本版本"
|
||||
description: |
|
||||
脚本版本。脚本开始运行后会显示版本号。
|
||||
placeholder: |
|
||||
eg: v2.0.2
|
||||
|
||||
- id: extra
|
||||
type: textarea
|
||||
validations:
|
||||
required: false
|
||||
attributes:
|
||||
label: "其他"
|
||||
description: |
|
||||
若您有其他想要补充的内容,请在此说明
|
||||
@@ -0,0 +1 @@
|
||||
blank_issues_enabled: false
|
||||
@@ -0,0 +1,19 @@
|
||||
name: 新功能请求
|
||||
description: 提出你想要的功能或你的建议
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## 欢迎
|
||||
请确保你所提出的功能脚本的确没有。
|
||||
<br />
|
||||
|
||||
- id: describe
|
||||
type: textarea
|
||||
validations:
|
||||
required: true
|
||||
attributes:
|
||||
label: "描述"
|
||||
description: |
|
||||
请清晰而简明地描述你想要的功能或你的建议。
|
||||
@@ -0,0 +1,40 @@
|
||||
name: "Build and push Docker images"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "lib/**"
|
||||
- "main.js"
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "lib/**"
|
||||
- "main.js"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
path-context:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: shanmite/lottery_auto_docker:latest
|
||||
@@ -0,0 +1,25 @@
|
||||
name: "Publishing to NPM"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "lib/**"
|
||||
- "main.js"
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "lib/**"
|
||||
- "main.js"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: JS-DevTools/npm-publish@v1
|
||||
with:
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
@@ -0,0 +1,82 @@
|
||||
name: "Package Node.js project into an executable"
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "lib/**"
|
||||
- "main.js"
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "lib/**"
|
||||
- "main.js"
|
||||
workflow_dispatch:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
pkg_x64:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: "Checkout codes"
|
||||
uses: actions/checkout@v2
|
||||
- name: "Use Node.js"
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: "16"
|
||||
- name: "Pkg this"
|
||||
run: |
|
||||
npm install
|
||||
npm run pkg_x64
|
||||
- name: "Upload to artifact(win)"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-win-x64
|
||||
path: dist/nlts-win-x64.zip
|
||||
- name: "Upload to artifact(linux)"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-linux-x64
|
||||
path: dist/nlts-linux-x64.zip
|
||||
- name: "Upload to artifact(macos)"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-macos-x64
|
||||
path: dist/nlts-macos-x64.zip
|
||||
pkg_arm64:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout codes"
|
||||
uses: actions/checkout@v2
|
||||
- name: "Use Node.js"
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: "16"
|
||||
- name: "Pkg this"
|
||||
run: |
|
||||
npm install
|
||||
npm run pkg_arm64
|
||||
- name: "Upload to artifact"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-linux-arm64
|
||||
path: dist/
|
||||
pkg_armv7:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout codes"
|
||||
uses: actions/checkout@v2
|
||||
- name: "Use Node.js"
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: "16"
|
||||
- name: "Pkg this"
|
||||
run: |
|
||||
npm install
|
||||
npm run pkg_armv7
|
||||
- name: "Upload to artifact"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: nlts-linux-armv7
|
||||
path: dist/
|
||||
@@ -1,27 +0,0 @@
|
||||
name: 'Automatic sync'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
watch:
|
||||
types: started
|
||||
repository_dispatch:
|
||||
types: repo-sync
|
||||
jobs:
|
||||
repo-sync:
|
||||
env:
|
||||
PAT: ${{ github.event.client_payload.PAT || secrets.PAT }}
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.repository.owner.id == github.event.sender.id
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: 开始自动同步
|
||||
uses: repo-sync/github-sync@v2
|
||||
if: env.PAT
|
||||
with:
|
||||
source_repo: "https://github.com/shanmite/LotteryAutoScript.git"
|
||||
source_branch: "main"
|
||||
destination_branch: "main"
|
||||
github_token: ${{ github.event.client_payload.PAT || secrets.PAT }}
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
node_modules/
|
||||
dyids/
|
||||
dist/
|
||||
lib/dyid*.txt
|
||||
dyid.zip
|
||||
package-lock.json
|
||||
env.js
|
||||
my_config.js
|
||||
Vendored
-123
@@ -1,123 +0,0 @@
|
||||
{
|
||||
"HttpRequest-get": {
|
||||
"scope": "javascript,typescript",
|
||||
"prefix": "hrget",
|
||||
"body": [
|
||||
"HttpRequest({",
|
||||
" method: 'GET',",
|
||||
" url: '$1',",
|
||||
" query: {",
|
||||
" $2",
|
||||
" },",
|
||||
" headers: {",
|
||||
" accept: 'application/json, text/plain, */*',",
|
||||
" cookie: '$3',",
|
||||
" },",
|
||||
" success: res => {",
|
||||
" $4",
|
||||
" },",
|
||||
" failure: err => {",
|
||||
" $5",
|
||||
" }",
|
||||
"})$6"
|
||||
],
|
||||
"description": "简化http-get请求"
|
||||
},
|
||||
"HttpRequest-post": {
|
||||
"scope": "javascript,typescript",
|
||||
"prefix": "hrpost",
|
||||
"body": [
|
||||
"HttpRequest({",
|
||||
" method: 'POST',",
|
||||
" url: '$1',",
|
||||
" contents: {",
|
||||
" $2",
|
||||
" },",
|
||||
" headers: {",
|
||||
" accept: 'application/json, text/plain, */*',",
|
||||
" 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',",
|
||||
" cookie: '$3',",
|
||||
" },",
|
||||
" success: res => {",
|
||||
" $4",
|
||||
" },",
|
||||
" failure: err => {",
|
||||
" $5",
|
||||
" }",
|
||||
"})$6"
|
||||
],
|
||||
"description": "简化http-post请求"
|
||||
},
|
||||
"CORSajax-get": {
|
||||
"scope": "javascript,typescript",
|
||||
"prefix": "corsget",
|
||||
"body": [
|
||||
"CORSajax.get({",
|
||||
" proxy_link: '$1',",
|
||||
" proxy_querystring: {",
|
||||
" $2",
|
||||
" },",
|
||||
" proxy_headers: {",
|
||||
" Cookie: '$3'",
|
||||
" },",
|
||||
"},chunk => {",
|
||||
" $4",
|
||||
"})$5"
|
||||
],
|
||||
"description": "简化跨域Ajax本地nodejsのget代理"
|
||||
},
|
||||
"CORSajax-post": {
|
||||
"scope": "javascript,typescript",
|
||||
"prefix": "corspost",
|
||||
"body": [
|
||||
"CORSajax.post({",
|
||||
" proxy_link: '$1',",
|
||||
" proxy_headers: {",
|
||||
" 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',",
|
||||
" cookie: '$2'",
|
||||
" },",
|
||||
" proxy_body: {",
|
||||
" $3",
|
||||
" },",
|
||||
"},chunk => {",
|
||||
" $4",
|
||||
"})$5"
|
||||
],
|
||||
"description": "简化跨域Ajax本地nodejsのpost代理"
|
||||
},
|
||||
"Ajax-get": {
|
||||
"scope": "javascript,typescript",
|
||||
"prefix": "myget",
|
||||
"body": [
|
||||
"Ajax.get({",
|
||||
" url: '$1',",
|
||||
" queryStringsObj: {",
|
||||
" $2",
|
||||
" },",
|
||||
" hasCookies: true,",
|
||||
" success: responseText => {",
|
||||
" $3",
|
||||
" }",
|
||||
"})",
|
||||
],
|
||||
"description": "简化AjaxのGet请求"
|
||||
},
|
||||
"Ajax-post": {
|
||||
"scope": "javascript,typescript",
|
||||
"prefix": "mypost",
|
||||
"body": [
|
||||
"Ajax.post({",
|
||||
" url: '$1',",
|
||||
" hasCookies: true,",
|
||||
" dataType: 'application/x-www-form-urlencoded',",
|
||||
" data: {",
|
||||
" $2",
|
||||
" },",
|
||||
" success: responseText => {",
|
||||
" $3",
|
||||
" }",
|
||||
"})",
|
||||
],
|
||||
"description": "简化Ajaxのpost请求"
|
||||
},
|
||||
}
|
||||
Vendored
-14
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "启动程序",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${file}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
# AutoScript
|
||||
|
||||
- [AutoScript](#autoscript)
|
||||
- [操作步骤](#操作步骤)
|
||||
- [获取COOKIE](#获取cookie)
|
||||
- [本地运行](#本地运行)
|
||||
- [可执行文件](#可执行文件)
|
||||
- [搭建运行环境](#搭建运行环境)
|
||||
- [以源码方式运行](#以源码方式运行)
|
||||
- [Windows](#windows)
|
||||
- [Linux](#linux)
|
||||
- [Docker](#docker)
|
||||
@@ -15,15 +14,30 @@
|
||||
- [中奖推送(可选)](#中奖推送可选)
|
||||
- [设置说明](#设置说明)
|
||||
|
||||
已实现功能:
|
||||
> 点赞 评论 转发 @好友 带话题 随机动态 检测开奖 清理
|
||||
[Github仓库链接](https://github.com/shanmiteko/LotteryAutoScript)
|
||||
|
||||
声明: 此脚本仅用于学习和测试,作者本人并不对其负责,请于运行测试完成后自行删除,请勿滥用!
|
||||
[](https://github.com/shanmiteko/LotteryAutoScript/actions/workflows/pkg.yml)<br>
|
||||
[](https://github.com/shanmiteko/LotteryAutoScript/actions/workflows/docker.yml)<br>
|
||||
[](https://github.com/shanmiteko/LotteryAutoScript/actions/workflows/npmp.yml)
|
||||
|
||||
----------------------------------------
|
||||
已实现功能:
|
||||
- 监控用户转发
|
||||
- 监控话题页面
|
||||
- 监控专栏合集
|
||||
- 自动点赞、评论、乱序转发、@好友、带话题、可选随机动态
|
||||
- 检测是否中奖
|
||||
- 清理动态关注
|
||||
- 检查更新
|
||||
- 更多功能设置请参考配置文件
|
||||
|
||||
**声明**: 此脚本仅用于学习和测试,作者本人并不对其负责,请于运行测试完成后自行删除,请勿滥用!
|
||||
|
||||
---------------------------------
|
||||
|
||||
## 操作步骤
|
||||
|
||||
**使用前务必阅读此教程和配置文件内注释**
|
||||
|
||||
右上角<kbd>★ Star</kbd>
|
||||
|
||||
↓↓
|
||||
@@ -38,9 +52,9 @@ Chrome浏览器:
|
||||
|
||||
2. 进入Application找到Cookies栏中的SESSDATA将HttpOnly选项**取消**勾选
|
||||
|
||||
(此步骤是为了方便后续采用JS获取Cookies)
|
||||
(此步骤是为了方便后续采用JS获取Cookies,获取完毕后应再次勾选)
|
||||
|
||||

|
||||

|
||||
|
||||
3. 在Console中复制以下代码回车
|
||||
|
||||
@@ -66,20 +80,31 @@ Chrome浏览器:
|
||||
↓↓
|
||||
|
||||
### 本地运行
|
||||
设置环境变量中的cookie和推送相关参数
|
||||
具体操作详见[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)运行内部的可执行文件即可
|
||||
1. [[下载](https://github.com/shanmiteko/LotteryAutoScript/releases)|[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript/releases)|[Fastgit镜像下载](https://hub.fastgit.org/shanmiteko/LotteryAutoScript/releases)]压缩包并解压后
|
||||
```
|
||||
~/nlts-linux-x64
|
||||
=> tree
|
||||
.
|
||||
├── env.js (便捷设置环境变量和多账号参数)
|
||||
├── lottery (可执行文件)
|
||||
├── my_config.js (自定义设置文件) (!使用前必读)
|
||||
└── README.md (说明文件)
|
||||
```
|
||||
2. 用记事本或其他编辑器修改`env.js`和`my_config.js`文件(右键选择用记事本打开)
|
||||
3. 在`env.js`中填入`COOKIE`和推送参数
|
||||
4. 在`my_config.js`中自定义设置
|
||||
5. 在当前目录下**打开终端**运行可执行文件`lottery`(勿直接点击`lottery`)
|
||||
- `lottery start` 启动抽奖
|
||||
- `lottery check` 检测中奖
|
||||
- `lottery clear` 清理动态
|
||||
|
||||
[下载](https://github.com/shanmiteko/LotteryAutoScript/releases)
|
||||
或者 新建文本文档写入`lottery start`然后更改扩展名为.bat点击运行(已自带start.bat可直接点击)
|
||||
7. 运行截图
|
||||

|
||||
|
||||
[cnpmjs镜像下载](https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript/releases)
|
||||
|
||||
[Fastgit镜像下载](https://hub.fastgit.org/shanmiteko/LotteryAutoScript/releases)
|
||||
|
||||
|
||||
#### 搭建运行环境
|
||||
#### 以源码方式运行
|
||||
|
||||
<details>
|
||||
|
||||
@@ -91,7 +116,7 @@ step1: 下载代码到本地
|
||||
|
||||
[点此下载](https://github.com/shanmiteko/LotteryAutoScript/archive/refs/heads/main.zip)或如图示下载↓
|
||||
|
||||

|
||||

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

|
||||

|
||||
|
||||
step3:修改env.example.js文件及创建运行文件(打开扩展名显示)
|
||||
|
||||
@@ -137,7 +162,9 @@ npm i && npm run clear
|
||||
|
||||
注: **本地运行时可在设置中增大扫描页数**
|
||||
|
||||
> [windows系统定时运行](./doc/win_schedule.md)
|
||||
> ~~[windows系统定时运行](./doc/win_schedule.md)~~
|
||||
|
||||
脚本已内置定时运行功能
|
||||
|
||||
##### Linux
|
||||
[linux系统配置与定时运行](./doc/linux_schedule.md)
|
||||
@@ -179,16 +206,19 @@ cd lottery
|
||||
进入lottery上一级目录
|
||||
|
||||
```bash
|
||||
docker image rm shanmite/lottery_auto_docker
|
||||
docker image rm -f shanmite/lottery_auto_docker
|
||||
rm -rf lottery/
|
||||
```
|
||||
|
||||
----------------------------------------
|
||||
|
||||
## 防重复转发
|
||||
脚本将所转发过的动态都写入`dyids/dyid*.txt`文件中
|
||||
~~存储在专栏草稿~~
|
||||
|
||||
~~脚本将转发过的动态和被过滤的动态都写入`dyids/dyid*.txt`文件中~~
|
||||
|
||||
是否点赞
|
||||
|
||||
完整转发一轮后才会进行写入操作, 勿过早关闭运行
|
||||
|
||||
----------------------------------------
|
||||
|
||||
@@ -211,14 +241,14 @@ rm -rf lottery/
|
||||
| :---------------: | :--------------------------------------------------------------------------------: | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `SCKEY` | 微信server酱推送(于2021/4月下线) | 非必须 | server酱的微信通知[官方文档](http://sc.ftqq.com/3.version) |
|
||||
| `SENDKEY` | 微信server酱(Turbo版)推送 | 非必须 | [获取SENDKEY](https://sct.ftqq.com/sendkey) [选择消息通道](https://sct.ftqq.com/forward) |
|
||||
| `BARK_PUSH` | [BARK推送](https://apps.apple.com/us/app/bark-customed-notifications/id1403753865) | 非必须 | IOS用户下载BARK这个APP,填写内容是app提供的`设备码`,例如:https://api.day.app/123 ,那么此处的设备码就是`123`,再不懂看 [这个图](doc/pic/bark.jpg)(注:支持自建填完整链接即可) |
|
||||
| `BARK_PUSH` | [BARK推送](https://apps.apple.com/us/app/bark-customed-notifications/id1403753865) | 非必须 | IOS用户下载BARK这个APP,填写内容是app提供的`设备码`,例如:https://api.day.app/123 ,那么此处的设备码就是`123`,再不懂看 [这个图](https://gitee.com/shanmite/LotteryAutoScript/raw/main/doc/pic/bark.jpg)(注:支持自建填完整链接即可) |
|
||||
| `BARK_SOUND` | [BARK推送](https://apps.apple.com/us/app/bark-customed-notifications/id1403753865) | 非必须 | bark推送声音设置,例如`choo`,具体值请在`bark`-`推送铃声`-`查看所有铃声` |
|
||||
| `TG_BOT_TOKEN` | telegram推送 | 非必须 | tg推送(需设备可连接外网),`TG_BOT_TOKEN`和`TG_USER_ID`两者必需,填写自己申请[@BotFather](https://t.me/BotFather)的Token,如`10xxx4:AAFcqxxxxgER5uw` , [具体教程](doc/TG_PUSH.md) |
|
||||
| `TG_USER_ID` | telegram推送 | 非必须 | tg推送(需设备可连接外网),`TG_BOT_TOKEN`和`TG_USER_ID`两者必需,填写[@getuseridbot](https://t.me/getuseridbot)中获取到的纯数字ID, [具体教程](doc/TG_PUSH.md) |
|
||||
| `TG_PROXY_HOST` | Telegram 代理的 IP | 非必须 | 代理类型为 http。例子:http代理 http://127.0.0.1:1080 则填写 127.0.0.1 |
|
||||
| `TG_PROXY_PORT` | Telegram 代理的端口 | 非必须 | 例子:http代理 http://127.0.0.1:1080 则填写 1080 |
|
||||
| `DD_BOT_TOKEN` | 钉钉推送 | 非必须 | 钉钉推送(`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需)[官方文档](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) ,只需`https://oapi.dingtalk.com/robot/send?access_token=XXX` 等于`=`符号后面的XXX即可 |
|
||||
| `DD_BOT_SECRET` | 钉钉推送 | 非必须 | (`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需) ,密钥,机器人安全设置页面,加签一栏下面显示的SEC开头的`SECXXXXXXXXXX`等字符 , 注:钉钉机器人安全设置只需勾选`加签`即可,其他选项不要勾选,再不懂看 [这个图](doc/pic/DD_bot.png) |
|
||||
| `DD_BOT_SECRET` | 钉钉推送 | 非必须 | (`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需) ,密钥,机器人安全设置页面,加签一栏下面显示的SEC开头的`SECXXXXXXXXXX`等字符 , 注:钉钉机器人安全设置只需勾选`加签`即可,其他选项不要勾选,再不懂看 [这个图](https://gitee.com/shanmite/LotteryAutoScript/raw/main/doc/pic/DD_bot.png) |
|
||||
| `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/) |
|
||||
@@ -234,4 +264,6 @@ rm -rf lottery/
|
||||
----------------------------------------
|
||||
|
||||
## 设置说明
|
||||
详见[my_config.example.js](./my_config.example.js)文件内部注释
|
||||
详见[env.example.js](./env.example.js)文件内部注释
|
||||
|
||||
详见[my_config.example.js](./my_config.example.js)文件内部注释
|
||||
|
||||
+3
-3
@@ -4,16 +4,16 @@
|
||||
|
||||
Ⅰ.首先在Telegram上搜索[BotFather](https://t.me/BotFather)机器人<br>
|
||||
|
||||

|
||||

|
||||
|
||||
Ⅱ.利用[BotFather](https://t.me/BotFather)创建一个属于自己的通知机器人,按照下图中的1、2、3步骤拿到token,格式形如```10xxx4:AAFcqxxxxgER5uw```。填入```TG_BOT_TOKEN```<br>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
**新创建的机器人需要跟它发一条消息来开启对话,否则可能会遇到secret填对了但是收不到消息的情况**<br>
|
||||
|
||||
Ⅲ.再次在Telegram上搜索[getuserIDbot](https://t.me/getuserIDbot)机器人,获取UserID。填入```TG_USER_ID```<br>
|
||||
|
||||

|
||||

|
||||
|
||||
至此,获取**TG_BOT_TOKEN**以及**TG_USER_ID**的教程结束
|
||||
|
||||
+18
-18
@@ -10,15 +10,14 @@
|
||||
2.下载脚本到本地
|
||||
|
||||
```sh
|
||||
git clone https://github.com/shanmite/LotteryAutoScript.git
|
||||
git clone https://github.com/shanmiteko/LotteryAutoScript.git
|
||||
```
|
||||
|
||||

|
||||
|
||||
**注意**: github访问下载速度可能很慢, 如果卡住了可以通过Github镜像网站下载
|
||||
|
||||
```sh
|
||||
git clone https://github.com.cnpmjs.org/shanmite/LotteryAutoScript.git
|
||||
git clone https://github.com.cnpmjs.org/shanmiteko/LotteryAutoScript.git
|
||||
```
|
||||
|
||||
|
||||
@@ -26,6 +25,7 @@ git clone https://github.com.cnpmjs.org/shanmite/LotteryAutoScript.git
|
||||
|
||||
```sh
|
||||
mv env.example.js env.js
|
||||
mv my_config.example.js my_config.js
|
||||
```
|
||||
|
||||
|
||||
@@ -38,14 +38,14 @@ vim env.js
|
||||
# 此处可查阅Vim的使用手册
|
||||
```
|
||||
|
||||

|
||||
|
||||
说明: `"CLEAR"`项设置为`true`, 才可以开启自动清理动态功能
|
||||
|
||||
`"PAT"`和`"GITHUB_REPOSITORY"`不填也行
|
||||
详见[env.example.js](https://github.com/shanmiteko/LotteryAutoScript/blob/main/env.example.js)文件内部注释
|
||||
|
||||
|
||||
5.设置定时工作
|
||||
[my_config.example.js](https://github.com/shanmiteko/LotteryAutoScript/blob/main/my_config.example.js)同理
|
||||
|
||||
|
||||
~~5.设置定时工作~~
|
||||
|
||||
> [linux系统定时运行](https://zhuanlan.zhihu.com/p/58719487)
|
||||
|
||||
输入:
|
||||
@@ -53,14 +53,14 @@ vim env.js
|
||||
```sh
|
||||
crontab -e
|
||||
```
|
||||
cd 后的路径修改为你的脚本路径
|
||||
```sh
|
||||
SHELL=/bin/bash
|
||||
PATH=/sbin:/bin:/usr/sbin/:/usr/bin
|
||||
|
||||

|
||||
|
||||
`SHELL` 和 `PATH`照着填
|
||||
|
||||
`MAILTO`不填也行
|
||||
|
||||
注意`HOME`后面跟脚本所在的目录, 这样才能到那个目录下去执行命令
|
||||
1 */3 * * * cd /root/LotteryAutoScript && npm i && npm run check
|
||||
1 */3 * * * cd /root/LotteryAutoScript && npm i && npm run start
|
||||
```
|
||||
|
||||
|
||||
6.手动运行一波
|
||||
@@ -73,7 +73,7 @@ crontab -e
|
||||
|
||||
看看有没有效果
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
7.如果本地的脚本需要更新
|
||||
@@ -82,4 +82,4 @@ crontab -e
|
||||
|
||||
```sh
|
||||
git pull
|
||||
```
|
||||
```
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 123 KiB |
+3
-3
@@ -16,13 +16,13 @@
|
||||
|
||||
7.在`操作`页面中点击`新建`,选择操作为`启动程序`,在设置里点击浏览找到`start.bat`文件并选择,在`起始于(可选)(T):`中的空白框里输入`start.bat`文件的目录地址,也就是`程序或脚本(P):`里`start.bat`的前面那一串目录地址,最后是以`\`结尾的 ,填好东西后按下面`确认`
|
||||
|
||||

|
||||

|
||||
|
||||
8.在`条件`页面中选择`网络`,设定启动条件为任何连接
|
||||
|
||||
9.在`设置`页面中选择如图示选项,或者不修改默认设置
|
||||
|
||||

|
||||

|
||||
|
||||
10.最后按`确定`
|
||||
|
||||
@@ -30,6 +30,6 @@
|
||||
|
||||
最后你可以在任务列表中选择已有的任务,右边的操作框中选择`运行`点击,启动计划的任务,如下图所示
|
||||
|
||||

|
||||

|
||||
|
||||
具体看任务是否正常执行,你可以看看自己的账号动态的最新转发,运行成功每几分钟自动转发抽奖动态
|
||||
|
||||
+63
-80
@@ -1,87 +1,70 @@
|
||||
/**
|
||||
* 使用时请将此文件命名为env.js
|
||||
* RELEASE内可执行文件包中已有env.js文件
|
||||
* 注: 请打开扩展名显示
|
||||
*/
|
||||
|
||||
/**
|
||||
* ## 账号相关参数
|
||||
* - `COOKIE` 是必填项
|
||||
* - `NUMBER` 表示是第几个账号
|
||||
* - `PAT` 与 `GITHUB_REPOSITORY` 如果之前在Github Action上运行过脚本, 可填写已下载转发过的动态dyid, 之后可移除
|
||||
*
|
||||
* ## 多账号
|
||||
* 1. 将 ENABLE_MULTIPLE_ACCOUNT 的值改为true
|
||||
* 2. 将账号信息依次填写于 multiple_account_parm 中, 参考例子类推
|
||||
* - `WAIT` 表示下一个账号运行等待时间(毫秒)
|
||||
*
|
||||
* **按顺序依次执行, 防止访问频繁封禁IP**
|
||||
*/
|
||||
const account_parm = {
|
||||
COOKIE: "",
|
||||
NUMBER: 1,
|
||||
CLEAR: true,
|
||||
LOCALLAUNCH: true,
|
||||
PAT: "",
|
||||
GITHUB_REPOSITORY: "用户名/仓库名",
|
||||
ENABLE_MULTIPLE_ACCOUNT: false
|
||||
}
|
||||
|
||||
/**
|
||||
* 为防止环境变量过长, 请将多账号填在此处
|
||||
*/
|
||||
const multiple_account_parm = [
|
||||
{
|
||||
module.exports = Object.freeze({
|
||||
/**
|
||||
* ## 账号相关
|
||||
* - `COOKIE` 是必填项
|
||||
* - `NUMBER` 表示是第几个账号
|
||||
* - `CLEAR` 是否启用清理功能
|
||||
* - `ENABLE_MULTIPLE_ACCOUNT` 是否启用多账号
|
||||
* - `MULTIPLE_ACCOUNT_PARM` 多账号参数(JSON格式)
|
||||
* ## 调试相关
|
||||
* - `LOTTERY_LOG_LEVEL` 输出日志等级 Error<Warn<Info<Debug 1<2<3<4
|
||||
* - `NOT_GO_LOTTERY` 关闭抽奖行为
|
||||
* ## 多账号
|
||||
* 1. 将 ENABLE_MULTIPLE_ACCOUNT 的值改为true
|
||||
* 2. 将账号信息依次填写于 multiple_account_parm 中, 参考例子类推
|
||||
* - `WAIT` 表示下一个账号运行等待时间(毫秒)
|
||||
*
|
||||
* **按顺序依次执行, 防止访问频繁封禁IP**
|
||||
*/
|
||||
account_parm: {
|
||||
COOKIE: "",
|
||||
NUMBER: 1,
|
||||
CLEAR: true,
|
||||
WAIT: 60 * 1000,
|
||||
|
||||
ENABLE_MULTIPLE_ACCOUNT: false,
|
||||
|
||||
MULTIPLE_ACCOUNT_PARM: "",
|
||||
LOTTERY_LOG_LEVEL: 3,
|
||||
NOT_GO_LOTTERY: ""
|
||||
},
|
||||
// {
|
||||
// COOKIE: "",
|
||||
// NUMBER: 2,
|
||||
// CLEAR: true,
|
||||
// WAIT: 60 * 1000,
|
||||
// },
|
||||
]
|
||||
|
||||
/**
|
||||
* 推送相关参数
|
||||
*/
|
||||
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: ""
|
||||
}
|
||||
/**
|
||||
* 为防止环境变量过长, 请将多账号填在此处
|
||||
* 以大括号内容为模板依次复制(包含大括号),逗号分割
|
||||
*/
|
||||
multiple_account_parm: [
|
||||
{
|
||||
COOKIE: "",
|
||||
NUMBER: 1,
|
||||
CLEAR: true,
|
||||
WAIT: 60 * 1000
|
||||
}
|
||||
],
|
||||
|
||||
/**
|
||||
* 初始化环境变量
|
||||
*/
|
||||
function initEnv() {
|
||||
process.env = {
|
||||
...process.env,
|
||||
...account_parm,
|
||||
...push_parm
|
||||
/**
|
||||
* 推送相关参数
|
||||
*/
|
||||
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: ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { initEnv, multiple_account_parm };
|
||||
})
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
const { HttpRequest } = require('./HttpRequest');
|
||||
const GlobalVar = require("./GlobalVar");
|
||||
|
||||
/**
|
||||
* Ajax请求对象
|
||||
*/
|
||||
module.exports = (() => {
|
||||
const get = ({ url, retry, queryStringsObj, success }) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url,
|
||||
config: {
|
||||
retry
|
||||
},
|
||||
query: queryStringsObj,
|
||||
headers: {
|
||||
"accept": 'application/json, text/plain, */*',
|
||||
"cookie": GlobalVar.get("cookie")
|
||||
},
|
||||
success: res => success(res.body),
|
||||
failure: err => success(err)
|
||||
})
|
||||
};
|
||||
const post = ({ url, retry, data, success }) => {
|
||||
HttpRequest({
|
||||
method: 'POST',
|
||||
url,
|
||||
contents: data,
|
||||
config: {
|
||||
retry
|
||||
},
|
||||
headers: {
|
||||
"accept": 'application/json, text/plain, */*',
|
||||
"content-type": 'application/x-www-form-urlencoded; charset=utf-8',
|
||||
"cookie": GlobalVar.get("cookie")
|
||||
},
|
||||
success: res => success(res.body),
|
||||
failure: err => success(err)
|
||||
})
|
||||
};
|
||||
return { get, post };
|
||||
})();
|
||||
-248
@@ -1,248 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { HttpRequest } = require("./HttpRequest");
|
||||
|
||||
/**
|
||||
* 基础工具
|
||||
*/
|
||||
const Base = {
|
||||
/**环境变量设置文件 */
|
||||
env_file: path.join(process.cwd(), "env.js"),
|
||||
/**配置文件 */
|
||||
config_file: path.join(process.cwd(), "my_config.js"),
|
||||
/**dyid存储文件 */
|
||||
dyids_dir: path.join(process.cwd(), "dyids"),
|
||||
/**
|
||||
* 安全的将JSON字符串转为对象
|
||||
* 超出精度的数转为字符串
|
||||
* @param {string} params
|
||||
* @return {object}
|
||||
* 返回对象
|
||||
*/
|
||||
strToJson(params) {
|
||||
const isJSON = (str => {
|
||||
if (typeof str === 'string') {
|
||||
try {
|
||||
const obj = JSON.parse(str);
|
||||
return typeof obj === 'object' ? obj : false
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
})(params);
|
||||
return isJSON ? isJSON : {}
|
||||
},
|
||||
/**
|
||||
* 函数柯里化
|
||||
* @param {function} func
|
||||
* 要被柯里化的函数
|
||||
* @returns {function}
|
||||
* 一次接受一个参数并返回一个接受余下参数的函数
|
||||
*/
|
||||
curryify(func) {
|
||||
function _c(restNum, argsList) {
|
||||
return restNum === 0 ?
|
||||
func.apply(null, argsList) :
|
||||
function (x) {
|
||||
return _c(restNum - 1, argsList.concat(x));
|
||||
};
|
||||
}
|
||||
return _c(func.length, []);
|
||||
},
|
||||
/**
|
||||
* 延时函数
|
||||
* @param {number} time ms
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
delay(time) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, time);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 计数器 0..Infinity
|
||||
* @typedef Counter
|
||||
* @property {()=>Number} next
|
||||
* @property {()=>boolean} clear
|
||||
* @property {()=>Number} value
|
||||
* @returns {Counter}
|
||||
*/
|
||||
counter() {
|
||||
let c = {
|
||||
i: 0,
|
||||
next: () => c.i++,
|
||||
clear: () => { c.i = 0 },
|
||||
value: () => c.i
|
||||
}
|
||||
return c
|
||||
},
|
||||
/**
|
||||
* 随机获取数组中的一个元素
|
||||
* @param {any[]} arr
|
||||
* @returns {any}
|
||||
*/
|
||||
getRandomOne(arr) {
|
||||
let RandomOne = null;
|
||||
if (arr instanceof Array && arr.length) {
|
||||
RandomOne = arr[parseInt(Math.random() * arr.length)];
|
||||
}
|
||||
return RandomOne
|
||||
},
|
||||
/**提示信息 */
|
||||
tooltip: {
|
||||
log: (msg) => {
|
||||
console.log("%s: %s", new Date().toLocaleString(), msg)
|
||||
},
|
||||
warn: (msg) => {
|
||||
console.log("%s: %s", new Date().toLocaleString(), msg)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 提取开奖信息
|
||||
* @param {string} des 描述
|
||||
* @returns {
|
||||
{
|
||||
ts: number|0;
|
||||
text:string|'开奖时间: 未填写开奖时间';
|
||||
item:string|'请自行查看';
|
||||
isMe:string|'请自行查看';
|
||||
}
|
||||
* }
|
||||
*/
|
||||
getLotteryNotice(des) {
|
||||
const r = /([\d零一二两三四五六七八九十]+)[.月]([\d零一二两三四五六七八九十]+)[日号]?/;
|
||||
if (des === '') return {
|
||||
ts: 0,
|
||||
text: `开奖时间: 未填写开奖时间`,
|
||||
item: '请自行查看',
|
||||
isMe: '请自行查看'
|
||||
}
|
||||
const _date = r.exec(des) || [];
|
||||
const timestamp10 = ((month, day) => {
|
||||
if (month && day) {
|
||||
let date = new Date(`${new Date(Date.now()).getFullYear()}-${month}-${day} 23:59:59`).getTime()
|
||||
if (!isNaN(date)) return date / 1000;
|
||||
}
|
||||
return 0
|
||||
})(_date[1], _date[2])
|
||||
if (timestamp10 === 0) return {
|
||||
ts: 0,
|
||||
text: `开奖时间: 未填写开奖时间`,
|
||||
item: '请自行查看',
|
||||
isMe: '请自行查看'
|
||||
}
|
||||
const timestamp13 = timestamp10 * 1000,
|
||||
time = new Date(timestamp13);
|
||||
const remain = (() => {
|
||||
const timestr = ((timestamp13 - Date.now()) / 86400000).toString()
|
||||
, timearr = timestr.replace(/(\d+)\.(\d+)/, "$1,0.$2").split(',');
|
||||
const text = timearr[0][0] === '-' ? `开奖时间已过${timearr[0].substring(1)}天余${parseInt(timearr[1] * 24)}小时` : `还有${timearr[0]}天余${parseInt(timearr[1] * 24)}小时`;
|
||||
return text
|
||||
})();
|
||||
return {
|
||||
ts: timestamp10,
|
||||
text: `开奖时间: ${time.toLocaleString()} ${remain}`,
|
||||
item: '请自行查看',
|
||||
isMe: '请自行查看'
|
||||
};
|
||||
},
|
||||
/**
|
||||
* 获取远程设置
|
||||
* @returns {Promise<JSON>}
|
||||
*/
|
||||
getRemoteConfig: () => new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: 'https://gitee.com/shanmite/lottery-notice/raw/master/notice.json',
|
||||
headers: {
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
|
||||
accept: 'text/plain; charset=utf-8',
|
||||
referer: 'https://gitee.com/shanmite/lottery-notice/blob/master/notice.json',
|
||||
},
|
||||
success: res => {
|
||||
try {
|
||||
const body = JSON.parse(res.body);
|
||||
if (body.node_msg) console.log(body.node_msg);
|
||||
resolve(body.config)
|
||||
} catch (error) {
|
||||
resolve(JSON.parse('{}'))
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
console.log('获取远程设置错误: ' + err);
|
||||
resolve(JSON.parse('{}'));
|
||||
}
|
||||
})
|
||||
}),
|
||||
/**
|
||||
*
|
||||
* @param {string} ts 13位时间戳
|
||||
* @param {number} zoneOffset 东时区记做正数
|
||||
*/
|
||||
transformTimeZone: (ts, zoneOffset) => new Date(new Date(ts).getTime() + zoneOffset * 60 * 60 * 1000).toLocaleString(),
|
||||
/**
|
||||
* 生成文件夹
|
||||
* @param {string} dirname
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
createDir(dirname) {
|
||||
return new Promise((resolve) => {
|
||||
fs.stat(dirname, (err) => {
|
||||
if (err) {
|
||||
fs.mkdirSync(dirname)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* CreateFile
|
||||
* @param {string} filepath 相对于dyids的文件路径
|
||||
* @param {string} [defaultValue] 写入默认值
|
||||
* @param {string} flag
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
createFile(filepath, defaultValue, flag) {
|
||||
const fpath = path.join(this.dyids_dir, filepath);
|
||||
const buffer = Buffer.from(defaultValue);
|
||||
return new Promise((resolve, rejects) => {
|
||||
fs.open(fpath, flag, (err, fd) => {
|
||||
if (err) {
|
||||
rejects(err)
|
||||
} else {
|
||||
fs.write(fd, buffer, 0, buffer.length, 0, err => {
|
||||
if (err) {
|
||||
rejects(err)
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 读取dyid文件
|
||||
* @param {number} num
|
||||
* @returns {fs.ReadStream}
|
||||
*/
|
||||
readDyidFile(num) {
|
||||
const fpath = num < 2 ? path.join(this.dyids_dir, 'dyid.txt') : path.join(this.dyids_dir, `dyid${num}.txt`);
|
||||
return fs.createReadStream(fpath, { encoding: 'utf8', highWaterMark: 19 * 1000 })
|
||||
},
|
||||
/**
|
||||
* 追加dyid
|
||||
* @param {number} num
|
||||
* @returns {fs.WriteStream}
|
||||
*/
|
||||
writeDyidFile(num) {
|
||||
const fpath = num < 2 ? path.join(this.dyids_dir, 'dyid.txt') : path.join(this.dyids_dir, `dyid${num}.txt`);
|
||||
return fs.createWriteStream(fpath, { flags: 'a' })
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Base;
|
||||
-825
@@ -1,825 +0,0 @@
|
||||
const Ajax = require('./Ajax');
|
||||
const { strToJson, tooltip } = require('./Base');
|
||||
const GlobalVar = require('./GlobalVar');
|
||||
|
||||
/**
|
||||
* 网络请求
|
||||
*/
|
||||
const BiliAPI = {
|
||||
/**
|
||||
* 判断是否成功登录
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async getMyinfo() {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/space/myinfo',
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
resolve(true);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取被at的信息
|
||||
* @typedef AtInfo
|
||||
* @property {number} at_time
|
||||
* @property {string} up_uname
|
||||
* @property {string} business
|
||||
* @property {string} source_content
|
||||
* @property {string} url
|
||||
* @returns {Promise<AtInfo[]>}
|
||||
*/
|
||||
async getMyAtInfo() {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/msgfeed/at',
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
const atInfo = [];
|
||||
if (res.code === 0) {
|
||||
const items = res.data.items;
|
||||
if (items.length !== 0) {
|
||||
items.forEach(i => {
|
||||
const { at_time, item, user } = i
|
||||
, { nickname: up_uname } = user
|
||||
, { business, uri: url, source_content } = item;
|
||||
atInfo.push({
|
||||
at_time,
|
||||
up_uname,
|
||||
business,
|
||||
source_content,
|
||||
url
|
||||
});
|
||||
});
|
||||
}
|
||||
resolve(atInfo);
|
||||
} else {
|
||||
resolve(atInfo);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取未读@
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
async getUnreadAtNum() {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/msgfeed/unread',
|
||||
hasCookies: true,
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
const { at } = res.data;
|
||||
resolve(at)
|
||||
tooltip.log(`[获取未读@]成功 数量: ${at}`)
|
||||
} else {
|
||||
resolve(-1)
|
||||
tooltip.log(`[获取未读@]失败\n${responseText}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取私信
|
||||
* @typedef SessionData
|
||||
* @property {string} session_ts
|
||||
* @property {string} content
|
||||
* @property {number} timestamp
|
||||
* @property {number} sender_uid
|
||||
* @property {number} talker_id
|
||||
*
|
||||
* @typedef SessionInfo
|
||||
* @property {number} has_more
|
||||
* @property {SessionData[]} data
|
||||
*
|
||||
* @param {number} session_type 1 已关注 2 未关注
|
||||
* @param {string} [ts_16]
|
||||
* @returns {Promise<SessionInfo>}
|
||||
*/
|
||||
async getSessionInfo(session_type, ts_16 = '') {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/get_sessions',
|
||||
data: {
|
||||
session_type,
|
||||
group_fold: 1,
|
||||
unfollow_fold: 1,
|
||||
sort_rule: 2,
|
||||
build: 0,
|
||||
mobi_app: 'web',
|
||||
end_ts: ts_16,
|
||||
},
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
tooltip.log('[获取一页私信](20)成功 ' + (ts_16 ? 'end_ts->' + ts_16 : '第一页'));
|
||||
/**@type {Array} */
|
||||
const sessions = res.data.session_list || [];
|
||||
const has_more = res.data.has_more;
|
||||
const data = sessions.map(session => {
|
||||
const { session_ts, last_msg = {}, unread_count, talker_id } = session;
|
||||
const { content = '', timestamp = 0, sender_uid = 0 } = last_msg;
|
||||
return { session_ts, content, timestamp, sender_uid, talker_id: unread_count ? talker_id : undefined }
|
||||
})
|
||||
resolve({ has_more, data })
|
||||
} else {
|
||||
tooltip.log(`[获取私信]失败\n${responseText}`);
|
||||
resolve({ has_more: 0, data: [] });
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取未读私信数量
|
||||
* @returns {Promise<{ unfollow_unread: number, follow_unread: number }>}
|
||||
*/
|
||||
async getUnreadSessionNum() {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread',
|
||||
hasCookies: true,
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
const { unfollow_unread, follow_unread } = res.data;
|
||||
resolve({ unfollow_unread, follow_unread });
|
||||
tooltip.log(`[获取未读私信]成功 已关注未读数: ${follow_unread}, 未关注未读数 ${unfollow_unread}`);
|
||||
} else {
|
||||
resolve(null);
|
||||
tooltip.log(`[获取未读私信]失败\n${responseText}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 私信已读
|
||||
* @param {number} talker_id
|
||||
*/
|
||||
updateSessionStatus(talker_id) {
|
||||
Ajax.post({
|
||||
url: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/update_ack',
|
||||
retry: false,
|
||||
data: {
|
||||
talker_id,
|
||||
session_type: 1,
|
||||
ack_seqno: 1,
|
||||
mobi_app: "web",
|
||||
csrf_token: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
tooltip.log(`[私信已读]成功 -> talker_id: ${talker_id}`);
|
||||
} else {
|
||||
tooltip.log(`[私信已读]失败 -> talker_id: ${talker_id}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取关注列表
|
||||
* @param {number} uid
|
||||
* @returns {Promise<string | null>}
|
||||
*/
|
||||
getAttentionList(uid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/feed/v1/feed/get_attention_list',
|
||||
queryStringsObj: {
|
||||
uid: uid
|
||||
},
|
||||
success: responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
tooltip.log('[获取关注列表]成功');
|
||||
resolve(res.data.list.toString());
|
||||
} else {
|
||||
tooltip.log(`[获取关注列表]失败\n${responseText}`);
|
||||
resolve(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取一组动态的信息
|
||||
* @param {number} UID
|
||||
* 被查看者的uid
|
||||
* @param {string} offset
|
||||
* 此动态偏移量
|
||||
* 初始为 0
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getOneDynamicInfoByUID(UID, offset) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history',
|
||||
queryStringsObj: {
|
||||
visitor_uid: GlobalVar.get("myUID"),
|
||||
host_uid: UID,
|
||||
offset_dynamic_id: offset,
|
||||
},
|
||||
retry: false,
|
||||
success: responseText => {
|
||||
/* 鉴别工作交由modifyDynamicRes完成 */
|
||||
resolve(responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 通过tag名获取tag的id
|
||||
* @param {string} tagename
|
||||
* tag名
|
||||
* @returns {Promise<number | -1>}
|
||||
* 正确:tag_ID
|
||||
* 错误:-1
|
||||
*/
|
||||
getTagIDByTagName(tagename) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/tag/info',
|
||||
queryStringsObj: {
|
||||
tag_name: tagename
|
||||
},
|
||||
hasCookies: false,
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code !== 0) {
|
||||
tooltip.log('获取TagID失败');
|
||||
resolve(-1);
|
||||
} else {
|
||||
resolve(res.data.tag_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取tag下的热门动态以及一条最新动态
|
||||
* @param {number} tagid
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getHotDynamicInfoByTagID(tagid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new',
|
||||
queryStringsObj: {
|
||||
topic_id: tagid
|
||||
},
|
||||
success: responseText => {
|
||||
resolve(responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取tag下的最新动态
|
||||
* @param {string} tagname
|
||||
* @param {string} offset
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getOneDynamicInfoByTag(tagname, offset) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_history',
|
||||
queryStringsObj: {
|
||||
topic_name: tagname,
|
||||
offset_dynamic_id: offset
|
||||
},
|
||||
retry: false,
|
||||
success: responseText => {
|
||||
resolve(responseText);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取粉丝数
|
||||
* @param {number} uid
|
||||
* @returns {Promise<number | -1>}
|
||||
*/
|
||||
getUserInfo(uid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/web-interface/card',
|
||||
queryStringsObj: {
|
||||
mid: uid,
|
||||
photo: false
|
||||
},
|
||||
retry: false,
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
resolve(res.data.follower);
|
||||
} else {
|
||||
tooltip.warn(`[获取粉丝数]尝试切换线路`);
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/relation/stat',
|
||||
queryStringsObj: {
|
||||
vmid: uid
|
||||
},
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
resolve(res.data.follower);
|
||||
tooltip.log(`[获取粉丝数]ok`);
|
||||
} else {
|
||||
tooltip.warn(`获取粉丝数出错,可能是访问过频繁\n${responseText}`);
|
||||
resolve(-1);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取开奖信息
|
||||
* @param {string} dyid
|
||||
* 动态id
|
||||
* @typedef LotteryNotice
|
||||
* @property {number | -1} ts
|
||||
* @property {string | "获取开奖信息失败"} text
|
||||
* @property {string | "null"} item
|
||||
* @property {string | "未知"} isMe
|
||||
* @returns {Promise<LotteryNotice>} 开奖时间
|
||||
*/
|
||||
getLotteryNotice(dyid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.vc.bilibili.com/lottery_svr/v1/lottery_svr/lottery_notice',
|
||||
queryStringsObj: {
|
||||
dynamic_id: dyid
|
||||
},
|
||||
hasCookies: false,
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
/(?<=_prize_cmt":").*(?=")/.exec();
|
||||
if (res.code === 0) {
|
||||
const timestamp10 = res.data.lottery_time,
|
||||
timestamp13 = timestamp10 * 1000,
|
||||
time = new Date(timestamp13);
|
||||
const remain = (() => {
|
||||
const timestr = ((timestamp13 - Date.now()) / 86400000).toString(),
|
||||
timearr = timestr.replace(/(\d+)\.(\d+)/, "$1,0.$2").split(',');
|
||||
const text = timearr[0][0] === '-' ? `开奖时间已过${timearr[0].substring(1)}天余${parseInt(timearr[1] * 24)}小时` : `还有${timearr[0]}天余${parseInt(timearr[1] * 24)}小时`;
|
||||
return text;
|
||||
})();
|
||||
let isMeB = (new RegExp(GlobalVar.get("myUID"))).test(responseText);
|
||||
const isMe = isMeB ? '中奖了!!!' : '未中奖';
|
||||
const iteminfo = res.data.first_prize_cmt || '' + ' ' + res.data.second_prize_cmt || '' + ' ' + res.data.third_prize_cmt || '';
|
||||
resolve({
|
||||
ts: timestamp10,
|
||||
text: `开奖时间: ${time.toLocaleString()} ${remain}`,
|
||||
item: iteminfo,
|
||||
isMe: isMe
|
||||
});
|
||||
} else {
|
||||
tooltip.log(`获取开奖信息失败\n${responseText}`);
|
||||
resolve({
|
||||
ts: -1,
|
||||
text: '获取开奖信息失败',
|
||||
item: 'null',
|
||||
isMe: '未知'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 之前不检查是否重复关注
|
||||
* 自动关注
|
||||
* 并转移分组
|
||||
* @param {Number} uid
|
||||
* 被关注者的UID
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
* 2 - 异常
|
||||
*/
|
||||
autoAttention(uid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.bilibili.com/x/relation/modify',
|
||||
retry: false,
|
||||
data: {
|
||||
fid: uid,
|
||||
act: 1,
|
||||
re_src: 11,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
/* 重复关注code also equal 0 */
|
||||
const res = strToJson(responseText)
|
||||
if (res.code === 0) {
|
||||
tooltip.log('[自动关注]关注+1');
|
||||
resolve(0);
|
||||
} else if (res.code === 22002) {
|
||||
tooltip.log('[自动关注]您已被对方拉入黑名单');
|
||||
resolve(1);
|
||||
} else if (res.code === 22015) {
|
||||
tooltip.log('[自动关注]您的账号异常无法关注');
|
||||
resolve(2);
|
||||
} else {
|
||||
tooltip.log(`[自动关注]失败 尝试切换线路\n${responseText}`);
|
||||
Ajax.post({
|
||||
url: 'https://api.vc.bilibili.com/feed/v1/feed/SetUserFollow',
|
||||
data: {
|
||||
type: 1,
|
||||
follow: uid,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
tooltip.log('[自动关注]关注+1');
|
||||
resolve(0);
|
||||
} else {
|
||||
tooltip.log(`[自动关注]失败 尝试切换另一条线路\n${responseText}`);
|
||||
Ajax.post({
|
||||
url: 'https://api.bilibili.com/x/relation/batch/modify',
|
||||
data: {
|
||||
fid: uid,
|
||||
act: 1,
|
||||
re_src: 11,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
tooltip.log('[自动关注]关注+1');
|
||||
resolve(0);
|
||||
} else {
|
||||
tooltip.log(`[自动关注]失败\n${responseText}`);
|
||||
resolve(1);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 移动分区
|
||||
* @param {number} uid
|
||||
* @param {number} tagid 关注分区的ID
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
*/
|
||||
movePartition(uid, tagid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.bilibili.com/x/relation/tags/addUsers',
|
||||
data: {
|
||||
fids: uid,
|
||||
tagids: tagid,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
/* 重复移动code also equal 0 */
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
tooltip.log('[移动分区]up主分区移动成功');
|
||||
resolve(0);
|
||||
} else {
|
||||
tooltip.log(`[移动分区]up主分区移动失败\n${responseText}`);
|
||||
resolve(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 取消关注
|
||||
* @param {number} uid
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
cancelAttention(uid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.bilibili.com/x/relation/modify',
|
||||
retry: false,
|
||||
data: {
|
||||
fid: uid,
|
||||
act: 2,
|
||||
re_src: 11,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
tooltip.log('[自动取关]取关成功');
|
||||
resolve(true)
|
||||
} else {
|
||||
tooltip.log(`[自动取关]取关失败\n${responseText}`);
|
||||
resolve(false)
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 动态自动点赞
|
||||
* @param {string} dyid
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
*/
|
||||
autolike(dyid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.vc.bilibili.com/dynamic_like/v1/dynamic_like/thumb',
|
||||
data: {
|
||||
uid: GlobalVar.get("myUID"),
|
||||
dynamic_id: dyid,
|
||||
up: 1,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
tooltip.log('[自动点赞]点赞成功');
|
||||
resolve(0);
|
||||
} else {
|
||||
tooltip.log(`[转发动态]点赞失败\n${responseText}`);
|
||||
resolve(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 转发前应查看是否重复转发
|
||||
* 自动转发
|
||||
* @param {Number} uid
|
||||
* 自己的UID
|
||||
* @param {string} dyid
|
||||
* @param {string} [msg]
|
||||
* 动态的ID
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
*/
|
||||
autoRelay(uid, dyid, msg = '转发动态', ctrl = '[]') {
|
||||
const len = msg.length;
|
||||
if (len > 233) {
|
||||
msg = msg.slice(0, 233 - len)
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/repost',
|
||||
retry: false,
|
||||
data: {
|
||||
uid: `${uid}`,
|
||||
dynamic_id: dyid,
|
||||
content: msg,
|
||||
ctrl,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
tooltip.log('[转发动态]成功转发一条动态');
|
||||
resolve(0);
|
||||
} else {
|
||||
tooltip.log(`[转发动态]转发动态失败\n${responseText}`);
|
||||
resolve(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @typedef Picture
|
||||
* @property {string} img_src
|
||||
* @property {number} img_width
|
||||
* @property {number} img_height
|
||||
* 发布一条动态
|
||||
* @param { string | Picture[] } content
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
createDynamic(content) {
|
||||
let data = {
|
||||
csrf: GlobalVar.get("csrf"),
|
||||
extension: '{"emoji_type":1,"from":{"emoji_type":1},"flag_cfg":{}}'
|
||||
}
|
||||
let url = '';
|
||||
if (content instanceof Array) {
|
||||
url = 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create_draw'
|
||||
data = {
|
||||
...data,
|
||||
biz: 3,
|
||||
category: 3,
|
||||
pictures: JSON.stringify(content)
|
||||
}
|
||||
} else {
|
||||
url = 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create'
|
||||
data = {
|
||||
...data,
|
||||
content,
|
||||
}
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url,
|
||||
data,
|
||||
success: responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
tooltip.log('[发布动态]成功创建一条随机内容的动态');
|
||||
} else {
|
||||
tooltip.warn(`[发布动态]发布动态失败\n${responseText}`);
|
||||
}
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 移除动态
|
||||
* @param {string} dyid
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
rmDynamic(dyid) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/rm_dynamic',
|
||||
data: {
|
||||
dynamic_id: dyid,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
retry: false,
|
||||
success: responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
tooltip.log('[删除动态]成功删除一条动态');
|
||||
resolve(true);
|
||||
} else {
|
||||
tooltip.log(`[删除动态]删除动态失败\n${responseText}`);
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 发送评论
|
||||
* @param {string} rid
|
||||
* cid_str
|
||||
* @param {string} msg
|
||||
* @param {number} type
|
||||
* 1(视频)
|
||||
* 11(有图)
|
||||
* 17(无图)
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
*/
|
||||
sendChat(rid, msg, type, show = true) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.bilibili.com/x/v2/reply/add',
|
||||
data: {
|
||||
oid: rid,
|
||||
type: type,
|
||||
message: msg,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
show ? tooltip.log('[自动评论]评论成功') : void 0;
|
||||
resolve(0);
|
||||
} else if (res.code === -404) {
|
||||
show ? tooltip.log('[自动评论]原动态已删除') : void 0;
|
||||
resolve(0);
|
||||
} else if (res.code === 12002) {
|
||||
show ? tooltip.log('[自动评论]评论区已关闭') : void 0;
|
||||
resolve(0);
|
||||
} else if (res.code === 12015) {
|
||||
show ? tooltip.log('[自动评论]需要输入验证码') : void 0;
|
||||
resolve(1);
|
||||
} else {
|
||||
show ? tooltip.log(`[自动评论]评论失败\n${responseText}`) : void 0;
|
||||
resolve(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 检查分区
|
||||
* 不存在指定分区时创建
|
||||
* 获取到tagid添加为对象的属性
|
||||
* @param {string} [name]
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
checkMyPartition(name) {
|
||||
if (!name) name = '此处存放因抽奖临时关注的up';
|
||||
return new Promise((resolve) => {
|
||||
Ajax.get({
|
||||
url: 'https://api.bilibili.com/x/relation/tags',
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
let tagid = undefined;
|
||||
if (res.code === 0) {
|
||||
const data = res.data.filter((it) => it.name === name);
|
||||
if (data.length) {
|
||||
tooltip.log('[获取分区id]成功');
|
||||
tagid = data[0].tagid
|
||||
} else {
|
||||
tooltip.log('[获取分区id]失败 无指定分区');
|
||||
}
|
||||
if (name === '此处存放因抽奖临时关注的up') {
|
||||
if (typeof tagid === 'undefined') {
|
||||
BiliAPI.createPartition(name).then(id => resolve(id))
|
||||
} else {
|
||||
resolve(tagid)
|
||||
}
|
||||
} else {
|
||||
resolve(tagid)
|
||||
}
|
||||
} else {
|
||||
tooltip.warn(`[获取分区id]访问出错 可在my_config里手动填入\n${responseText}`)
|
||||
resolve(tagid)
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 创造分区
|
||||
* @param {string} partition_name
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
createPartition(partition_name) {
|
||||
return new Promise((resolve) => {
|
||||
Ajax.post({
|
||||
url: 'https://api.bilibili.com/x/relation/tag/create',
|
||||
data: {
|
||||
tag: partition_name,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
success: responseText => {
|
||||
let obj = strToJson(responseText);
|
||||
if (obj.code === 0) {
|
||||
tooltip.log('[新建分区]分区新建成功')
|
||||
let { tagid } = obj.data /* 获取tagid */
|
||||
resolve(tagid)
|
||||
} else {
|
||||
tooltip.warn(`[新建分区]分区新建失败\n${responseText}`);
|
||||
resolve(undefined);
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取一个分区中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.get("myUID"),
|
||||
tagid: tagid,
|
||||
pn: n,
|
||||
ps: 50
|
||||
},
|
||||
success: responseText => {
|
||||
const res = strToJson(responseText);
|
||||
let uids = [];
|
||||
if (res.code === 0) {
|
||||
res.data.forEach(d => {
|
||||
uids.push(d.mid);
|
||||
})
|
||||
tooltip.log(`[获取分组${tagid}]成功获取取关分区列表${n}`);
|
||||
resolve(uids)
|
||||
} else {
|
||||
tooltip.warn(`[获取分组]获取取关分区列表失败\n${responseText}`);
|
||||
resolve(uids)
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = BiliAPI;
|
||||
@@ -1,156 +0,0 @@
|
||||
const { createReadStream, createWriteStream } = require('fs')
|
||||
const unzip = require('unzipper');
|
||||
const { strToJson, tooltip } = require("./Base")
|
||||
const { HttpRequest } = require("./HttpRequest")
|
||||
|
||||
const { GITHUB_REPOSITORY } = process.env;
|
||||
|
||||
|
||||
const GihubAPI = {
|
||||
/**
|
||||
* 列出第一个构件
|
||||
* @returns {Promise<{id: number, size_in_bytes: number}>}
|
||||
*/
|
||||
listArtifacts() {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts`,
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
query: {
|
||||
page: 1,
|
||||
per_page: 5
|
||||
},
|
||||
headers: {
|
||||
Accept: 'application/json, text/plain, */*',
|
||||
},
|
||||
success: res => {
|
||||
const data = strToJson(res.body);
|
||||
if (data.total_count) {
|
||||
resolve(data.artifacts[0])
|
||||
} else {
|
||||
resolve({})
|
||||
tooltip.log('之前无构件');
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve({})
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 下载构件
|
||||
* @param {number} id
|
||||
* @returns {Promise<boolean>} success: true
|
||||
*/
|
||||
downloadArtifacts(id) {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts/${id}/zip`,
|
||||
headers: {
|
||||
accept: 'application/vnd.github.v3+json',
|
||||
authorization: `token ${process.env.PAT}`
|
||||
},
|
||||
config: {
|
||||
redirect: true,
|
||||
},
|
||||
stream: true,
|
||||
success: res => {
|
||||
let recv_length = 0;
|
||||
const wtbs = createWriteStream('dyid.zip');
|
||||
res.resStream.on('data', chuck => {
|
||||
recv_length += chuck.length
|
||||
tooltip.log(`已收到:${recv_length} Bytes`)
|
||||
})
|
||||
res.resStream.pipe(wtbs)
|
||||
wtbs.on('finish', () => {
|
||||
tooltip.log('下载完成开始解压')
|
||||
createReadStream('dyid.zip').pipe(unzip.Extract({
|
||||
path: 'lib',
|
||||
}).on('close', () => {
|
||||
tooltip.log('解压完成')
|
||||
resolve(true)
|
||||
}))
|
||||
}).on('error', () => {
|
||||
wtbs.destroy()
|
||||
resolve(false)
|
||||
})
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 检查是否正在抽奖或取关
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
hasLotteryRun() {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs`,
|
||||
query: {
|
||||
status: "in_progress"
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/vnd.github.v3+json',
|
||||
},
|
||||
success: res => {
|
||||
const { workflow_runs } = strToJson(res.body);
|
||||
if (workflow_runs instanceof Array) {
|
||||
workflow_runs.filter(wr => /sweepstakes|clear/.test(wr.name)).length > 1 ?
|
||||
resolve(true) : resolve(false)
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 触发一个workflow
|
||||
* @param {string} yaml_file
|
||||
*/
|
||||
trigger(yaml_file) {
|
||||
return new Promise((resolve) => {
|
||||
HttpRequest({
|
||||
method: 'POST',
|
||||
url: `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${yaml_file}/dispatches`,
|
||||
contents: {
|
||||
ref: 'main'
|
||||
},
|
||||
headers: {
|
||||
accept: 'application/vnd.github.v3+json',
|
||||
'content-type': 'application/json',
|
||||
authorization: `token ${process.env.PAT}`
|
||||
},
|
||||
success: res => {
|
||||
if (res.body === '') {
|
||||
tooltip.log('成功触发'+yaml_file);
|
||||
} else {
|
||||
tooltip.log(`触发${yaml_file}失败 响应:\n${res.body}`);
|
||||
}
|
||||
resolve()
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(err);
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GihubAPI;
|
||||
@@ -1,12 +0,0 @@
|
||||
let GlobalVar = {
|
||||
inner: {},
|
||||
get(key) {
|
||||
return this.inner[key]
|
||||
},
|
||||
set(key, value) {
|
||||
this.inner[key] = value
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
module.exports = GlobalVar;
|
||||
-290
@@ -1,290 +0,0 @@
|
||||
const Base = require('./Base');
|
||||
const BiliAPI = require('./BiliAPI');
|
||||
const { sendNotify } = require('./sendNotify');
|
||||
const eventBus = require('./eventBus');
|
||||
const Public = require('./Public');
|
||||
const GlobalVar = require("./GlobalVar");
|
||||
const config = require("./config");
|
||||
const MyStorage = require('./MyStorage');
|
||||
|
||||
/**
|
||||
* 监视器
|
||||
*/
|
||||
class Monitor extends Public {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {number | string} param
|
||||
*/
|
||||
constructor(param) {
|
||||
super();
|
||||
typeof param === 'number' ? this.UID = param : this.tag_name = param;
|
||||
this.tagid = config.partition_id; /* tagid初始化 */
|
||||
this.attentionList = ''; /* 转为字符串的所有关注的up主uid */
|
||||
}
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
async init() {
|
||||
if (config.model === '00') {
|
||||
eventBus.emit('Turn_off_the_Monitor', '已关闭所有转发行为')
|
||||
return
|
||||
}
|
||||
if (!this.tagid) {
|
||||
this.tagid = await BiliAPI.checkMyPartition() /* 检查关注分区 */
|
||||
if (!this.tagid) {
|
||||
eventBus.emit('Turn_off_the_Monitor', '分区获取失败')
|
||||
return
|
||||
}
|
||||
}
|
||||
this.attentionList = await BiliAPI.getAttentionList(GlobalVar.get("myUID")); /* 获取关注列表 */
|
||||
await this.startLottery();
|
||||
}
|
||||
/**
|
||||
* 启动
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async startLottery() {
|
||||
const allLottery = await this.filterLotteryInfo();
|
||||
let status = 1;
|
||||
if (allLottery instanceof Array) {
|
||||
if (allLottery.length) {
|
||||
let dyids = [];
|
||||
for (const Lottery of allLottery) {
|
||||
status = await this.go(Lottery);
|
||||
if (status % 2) break
|
||||
dyids.push(Lottery.dyid);
|
||||
}
|
||||
if (dyids.length) MyStorage.updateDyid(dyids.toString())
|
||||
Base.tooltip.log('开始转发下一组动态');
|
||||
} else {
|
||||
status = 0;
|
||||
Base.tooltip.log('无未转发抽奖');
|
||||
}
|
||||
}
|
||||
switch (status) {
|
||||
case 0:
|
||||
eventBus.emit('Turn_on_the_Monitor')
|
||||
break;
|
||||
case 11:
|
||||
eventBus.emit('Turn_off_the_Monitor', '评论失败')
|
||||
break
|
||||
case 21:
|
||||
eventBus.emit('Turn_on_the_Monitor')
|
||||
break
|
||||
case 22:
|
||||
if (!config.is_exception) {
|
||||
config.is_exception = true;
|
||||
await sendNotify('[动态抽奖]账号异常通知', `UID: ${GlobalVar.get('myUID')}\n\n已自动跳过异常关注(异常号只会对部分UP出现关注异常)\n\n可在设置中令is_exception为true关闭此推送`)
|
||||
}
|
||||
eventBus.emit('Turn_on_the_Monitor')
|
||||
break
|
||||
case 31:
|
||||
eventBus.emit('Turn_on_the_Monitor')
|
||||
break
|
||||
case 41:
|
||||
eventBus.emit('Turn_off_the_Monitor', '转发失败')
|
||||
break
|
||||
default:
|
||||
eventBus.emit('Turn_off_the_Monitor', '出错 status:' + status)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 抽奖配置
|
||||
* @typedef {object} LotteryOptions
|
||||
* @property {number[]} uid 用户标识
|
||||
* @property {string} dyid 动态标识
|
||||
* @property {number} type 动态类型
|
||||
* @property {string} relay_chat 动态类型
|
||||
* @property {string} ctrl 定位@
|
||||
* @property {string} rid 评论类型
|
||||
*/
|
||||
/**
|
||||
* @returns {Promise<LotteryOptions[] | null>}
|
||||
*/
|
||||
async filterLotteryInfo() {
|
||||
const self = this,
|
||||
protoLotteryInfo = typeof self.UID === 'number'
|
||||
? await self.getLotteryInfoByUID(self.UID)
|
||||
: await self.getLotteryInfoByTag(self.tag_name);
|
||||
|
||||
if (protoLotteryInfo === null)
|
||||
return [];
|
||||
|
||||
/** 所有抽奖信息 */
|
||||
let alllotteryinfo = [];
|
||||
const { key_words, 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;
|
||||
|
||||
/**dyid去重 */
|
||||
if (dyids_set.has(dyid)) continue;
|
||||
dyids_set.add(dyid);
|
||||
|
||||
/**判断是转发源动态还是现动态 */
|
||||
const uid = lottery_info_type === 'tag' ? uids[0] : uids[1];
|
||||
|
||||
const now_ts_10 = Date.now() / 1000;
|
||||
let onelotteryinfo = {};
|
||||
let isLottery = false;
|
||||
let isSendChat = false;
|
||||
let isBlock = false;
|
||||
let ts = 0;
|
||||
const description = typeof des === 'string' ? des : '';
|
||||
for (let index = 0; index < blockword.length; index++) {
|
||||
const word = blockword[index];
|
||||
const reg = new RegExp(word);
|
||||
isBlock = reg.test(description) ? true : false;
|
||||
if (isBlock) break;
|
||||
}
|
||||
if (isBlock) continue;
|
||||
const needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description);
|
||||
const needTopic = (/(?<=[带加上](?:话题|tag))#.*#/i.exec(description) || [])[0];
|
||||
const isTwoLevelRelay = /\/\/@/.test(description);
|
||||
|
||||
/**是否包含关键词 */
|
||||
const has_key_words = key_words.map(it => new RegExp(it)).every(it => it.test(description))
|
||||
|
||||
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' && has_key_words && !isTwoLevelRelay) {
|
||||
({ ts } = Base.getLotteryNotice(description));
|
||||
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 < minfollower) continue;
|
||||
isLottery = !befilter && (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 && !isFollowed) continue;
|
||||
/* 判断是否转发过 */
|
||||
const isRelay = await MyStorage.searchDyid(dyid);
|
||||
/* 获取黑名单并去重合并 */
|
||||
const { blacklist: remote_blacklist } = GlobalVar.get("remoteconfig");
|
||||
const new_blacklist = remote_blacklist ?
|
||||
Array.from(new Set([...blacklist.split(','), ...remote_blacklist.split(',')])).toString() : blacklist;
|
||||
/* 进行判断 */
|
||||
if ((new RegExp(dyid + '|' + uid)).test(new_blacklist)) continue;
|
||||
onelotteryinfo.uid = [] /**初始化待关注列表 */
|
||||
if (!isFollowed) onelotteryinfo.uid.push(uid);
|
||||
if (!isRelay) {
|
||||
onelotteryinfo.dyid = dyid;
|
||||
let RandomStr = Base.getRandomOne(config.relay);
|
||||
let new_ctrl = [];
|
||||
if (needTopic) {
|
||||
RandomStr += needTopic
|
||||
}
|
||||
if (needAt) {
|
||||
at_users.forEach(it => {
|
||||
new_ctrl.push({
|
||||
data: String(it[1]),
|
||||
location: RandomStr.length,
|
||||
length: it[0].length + 1,
|
||||
type: 1
|
||||
})
|
||||
RandomStr += '@' + it[0]
|
||||
})
|
||||
}
|
||||
if (type === 1) {
|
||||
/* 转发内容长度+'//'+'@'+用户名+':'+源内容 */
|
||||
const addlength = RandomStr.length + 2 + uname.length + 1 + 1;
|
||||
onelotteryinfo.relay_chat = RandomStr + `//@${uname}:` + des;
|
||||
new_ctrl.push({
|
||||
data: String(uid),
|
||||
location: RandomStr.length + 2,
|
||||
length: uname.length + 1,
|
||||
type: 1
|
||||
})
|
||||
ctrl.map(item => {
|
||||
item.location += addlength;
|
||||
return item;
|
||||
}).forEach(it => new_ctrl.push(it))
|
||||
if (!(new RegExp(uids[1])).test(self.attentionList))
|
||||
onelotteryinfo.uid.push(uids[1]);
|
||||
} else {
|
||||
onelotteryinfo.relay_chat = RandomStr;
|
||||
}
|
||||
onelotteryinfo.ctrl = JSON.stringify(new_ctrl);
|
||||
}
|
||||
/* 根据动态的类型决定评论的类型 */
|
||||
onelotteryinfo.type = type === 2 ?
|
||||
11 : type === 4 || type === 1 ?
|
||||
17 : type === 8 ?
|
||||
1 : 0;
|
||||
/* 是否评论 */
|
||||
if (isSendChat) onelotteryinfo.rid = rid;
|
||||
if (onelotteryinfo.dyid) alllotteryinfo.push(onelotteryinfo);
|
||||
}
|
||||
}
|
||||
return alllotteryinfo;
|
||||
}
|
||||
/**
|
||||
* 关注转发评论
|
||||
* @param {LotteryOptions} option
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 11 - 评论错误
|
||||
* 21 - 关注错误
|
||||
* 22 - 关注异常
|
||||
* 31 - 点赞失败
|
||||
* 41 - 转发失败
|
||||
*/
|
||||
async go(option) {
|
||||
let status = 1;
|
||||
const { uid, dyid, type, rid, relay_chat, ctrl } = option;
|
||||
/* 评论 */
|
||||
if (typeof rid === 'string' && type !== 0) {
|
||||
const send = () => BiliAPI.sendChat(rid, Base.getRandomOne(config.chat) || relay_chat, type);
|
||||
const max_retry_times = 5;
|
||||
for (let times = 0; times < max_retry_times && status; times++) {
|
||||
status = await send();
|
||||
if (status) {
|
||||
Base.tooltip.log(`将在 ${times + 1} 分钟后再次发送评论(${times + 1}/${max_retry_times})`)
|
||||
await Base.delay(60 * 1000 * (times + 1))
|
||||
}
|
||||
}
|
||||
if (status) return 11;
|
||||
}
|
||||
|
||||
/* 关注 */
|
||||
if (uid.length) {
|
||||
status = 0
|
||||
for (let index = 0; index < uid.length && !status; index++) {
|
||||
const one_uid = uid[index];
|
||||
if (typeof one_uid === 'number') {
|
||||
status = await BiliAPI.autoAttention(uid);
|
||||
await Base.delay(5000);
|
||||
if (!status) await BiliAPI.movePartition(uid, this.tagid);
|
||||
}
|
||||
}
|
||||
if (status) return 20 + status;
|
||||
}
|
||||
|
||||
/* 点赞 */
|
||||
if (await BiliAPI.autolike(dyid)) return 31;
|
||||
|
||||
/* 转发 */
|
||||
if (await BiliAPI.autoRelay(GlobalVar.get("myUID"), dyid, relay_chat, ctrl)) return 41;
|
||||
|
||||
/* 延时 */
|
||||
await Base.delay(config.wait * (Math.random() + 0.5));
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Monitor;
|
||||
@@ -1,73 +0,0 @@
|
||||
const Base = require("./Base");
|
||||
const GihubAPI = require("./GithubAPI");
|
||||
|
||||
const MyStorage = {
|
||||
/**
|
||||
* 初始化dyid.txt
|
||||
*/
|
||||
init: () => {
|
||||
return new Promise((resolve) => {
|
||||
GihubAPI.listArtifacts().then(async artifact => {
|
||||
const { id, size_in_bytes } = artifact;
|
||||
if (size_in_bytes) {
|
||||
GihubAPI.downloadArtifacts(id).then(async status => {
|
||||
if (status) {
|
||||
Base.tooltip.log('存储初始化成功');
|
||||
} else {
|
||||
Base.tooltip.log('存储初始化失败');
|
||||
await Base.createFile('dyid.txt', '', 'a')
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
} else {
|
||||
await Base.createFile('dyid.txt', '', 'a')
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 搜索dyid
|
||||
* @param {string} dyid
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
searchDyid: (dyid) => {
|
||||
return new Promise((resolve) => {
|
||||
const Rdyid = new RegExp(dyid);
|
||||
const rs = Base.readDyidFile(Number(process.env.NUMBER));
|
||||
let status = false;
|
||||
rs.on('data', chunk => {
|
||||
if (Rdyid.test(chunk)) {
|
||||
status = true
|
||||
}
|
||||
})
|
||||
rs.on('end', () => {
|
||||
resolve(status)
|
||||
})
|
||||
rs.on('error', err => {
|
||||
Base.tooltip.log(err)
|
||||
resolve(status)
|
||||
})
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 更新dyid
|
||||
* @param {string} dyid
|
||||
*/
|
||||
updateDyid: (dyid) => {
|
||||
Base.tooltip.log('写入已转发过的动态信息');
|
||||
return new Promise((resolve) => {
|
||||
const ws = Base.writeDyidFile(Number(process.env.NUMBER));
|
||||
ws.write(dyid + ',', () => {
|
||||
ws.destroy();
|
||||
resolve()
|
||||
})
|
||||
ws.on('error', err => {
|
||||
Base.tooltip.log(err)
|
||||
resolve()
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MyStorage;
|
||||
-248
@@ -1,248 +0,0 @@
|
||||
const Base = require('./Base');
|
||||
const BiliAPI = require('./BiliAPI');
|
||||
const config = require("./config");
|
||||
/**
|
||||
* 基础功能
|
||||
*/
|
||||
class Public {
|
||||
constructor() { }
|
||||
/**
|
||||
* 提取出的有用动态信息
|
||||
* @typedef {object} UsefulDynamicInfo
|
||||
* @property {number} uid
|
||||
* @property {string} uname
|
||||
* @property {boolean} official_verify
|
||||
* @property {number} createtime 10
|
||||
* @property {string} rid_str
|
||||
* @property {string} dynamic_id
|
||||
* @property {number} type
|
||||
* @property {string} description
|
||||
* @property {boolean} hasOfficialLottery
|
||||
* @property {Array<Object.<string,string|number>>} ctrl
|
||||
*
|
||||
* @property {number} origin_uid
|
||||
* @property {string} origin_uname
|
||||
* @property {boolean} origin_official_verify
|
||||
* @property {string} origin_rid_str
|
||||
* @property {string} origin_dynamic_id
|
||||
* @property {number} orig_type
|
||||
* @property {string} origin_description
|
||||
* @property {boolean} origin_hasOfficialLottery
|
||||
*/
|
||||
/**
|
||||
* 检查所有的动态信息
|
||||
* @param {string} UID 指定的用户UID
|
||||
* @param {number} pages 读取页数
|
||||
* @param {number} time 时延
|
||||
* @param {string} [_offset] 默认'0'
|
||||
* @returns {Promise<{allModifyDynamicResArray: UsefulDynamicInfo[];offset: string}>} 获取前 `pages*12` 个动态信息
|
||||
*/
|
||||
async checkAllDynamic(hostuid, pages, time = 0, _offset = '0') {
|
||||
Base.tooltip.log(`准备读取${pages}页动态`);
|
||||
const mDR = this.modifyDynamicRes,
|
||||
getOneDynamicInfoByUID = BiliAPI.getOneDynamicInfoByUID,
|
||||
curriedGetOneDynamicInfoByUID = Base.curryify(getOneDynamicInfoByUID); /* 柯里化的请求函数 */
|
||||
/**
|
||||
* 储存了特定UID的请求函数
|
||||
*/
|
||||
let hadUidGetOneDynamicInfoByUID = curriedGetOneDynamicInfoByUID(hostuid);
|
||||
/**
|
||||
* 储存所有经过整理后信息
|
||||
* [{}{}...{}]
|
||||
*/
|
||||
let allModifyDynamicResArray = [];
|
||||
let offset = _offset;
|
||||
for (let i = 0; i < pages; i++) {
|
||||
Base.tooltip.log(`正在读取其中第${i + 1}页动态`);
|
||||
let OneDynamicInfo = await hadUidGetOneDynamicInfoByUID(offset);
|
||||
const mDRdata = mDR(OneDynamicInfo);
|
||||
if (mDRdata === null) {
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* 储存一片动态信息
|
||||
* [{}{}...{}]
|
||||
*/
|
||||
const mDRArry = mDRdata.modifyDynamicResArray,
|
||||
nextinfo = mDRdata.nextinfo;
|
||||
if (nextinfo.has_more === 0) {
|
||||
offset = nextinfo.next_offset;
|
||||
Base.tooltip.log(`成功读取${i + 1}页信息(已经是最后一页了故无法读取更多)`);
|
||||
break;
|
||||
} else {
|
||||
allModifyDynamicResArray.push.apply(allModifyDynamicResArray, mDRArry);
|
||||
i + 1 < pages ? Base.tooltip.log(`开始读取第${i + 2}页动态信息`) : Base.tooltip.log(`${pages}页信息全部成功读取完成`);
|
||||
offset = nextinfo.next_offset;
|
||||
}
|
||||
await Base.delay(time);
|
||||
}
|
||||
return ({ allModifyDynamicResArray, offset });
|
||||
}
|
||||
/**
|
||||
* 互动抽奖
|
||||
* 处理来自动态页面的数据
|
||||
* @param {String} res
|
||||
* @returns {{modifyDynamicResArray: UsefulDynamicInfo[];nextinfo: {has_more: number;next_offset: string;};} | null}
|
||||
*/
|
||||
modifyDynamicRes(res) {
|
||||
const strToJson = Base.strToJson,
|
||||
jsonRes = strToJson(res),
|
||||
{ data } = jsonRes;
|
||||
if (jsonRes.code !== 0) {
|
||||
Base.tooltip.warn('获取动态数据出错,可能是访问太频繁');
|
||||
return null;
|
||||
}
|
||||
/* 字符串防止损失精度 */
|
||||
const offset = typeof data.offset === 'string' ? data.offset : /(?<=next_offset":)[0-9]*/.exec(res)[0]
|
||||
, next = {
|
||||
has_more: data.has_more,
|
||||
next_offset: offset
|
||||
};
|
||||
/**
|
||||
* 储存获取到的一组动态中的信息
|
||||
*/
|
||||
let array = [];
|
||||
if (next.has_more === 0) {
|
||||
Base.tooltip.log('动态数据读取完毕');
|
||||
} else {
|
||||
/**
|
||||
* 空动态无cards
|
||||
*/
|
||||
const Cards = data.cards;
|
||||
Cards.forEach(onecard => {
|
||||
/**临时储存单个动态中的信息 */
|
||||
let obj = {};
|
||||
const { desc, card } = onecard
|
||||
, { info, card: user_profile_card } = desc.user_profile
|
||||
, { official_verify } = user_profile_card
|
||||
, cardToJson = strToJson(card);
|
||||
obj.uid = info.uid; /* 转发者的UID */
|
||||
obj.uname = info.uname;/* 转发者的name */
|
||||
obj.official_verify = official_verify.type > -1 ? true : false; /* 是否官方号 */
|
||||
obj.createtime = desc.timestamp /* 动态的ts10 */
|
||||
obj.type = desc.type /* 动态类型 */
|
||||
obj.rid_str = desc.rid_str.length > 12 ? desc.dynamic_id_str : desc.rid_str;/* 用于发送评论 */
|
||||
obj.orig_type = desc.orig_type /* 源动态类型 */
|
||||
obj.dynamic_id = desc.dynamic_id_str; /* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
const { extension, extend_json } = onecard;
|
||||
obj.ctrl = (typeof extend_json === 'undefined') ? [] : strToJson(extend_json).ctrl || []; /* 定位@信息 */
|
||||
obj.hasOfficialLottery = (typeof extension === 'undefined') ? false : typeof extension.lott === 'undefined' ? false : true; /* 是否有官方抽奖 */
|
||||
const item = cardToJson.item || {};
|
||||
obj.description = item.content || item.description || ''; /* 转发者的描述 */
|
||||
if (obj.type === 1) {
|
||||
obj.origin_uid = desc.origin.uid; /* 被转发者的UID */
|
||||
obj.origin_rid_str = desc.origin.rid_str.length > 12 ? desc.origin.dynamic_id_str : desc.origin.rid_str; /* 被转发者的rid(用于发评论) */
|
||||
obj.origin_dynamic_id = desc.orig_dy_id_str; /* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
const { origin_extension, origin_user } = cardToJson;
|
||||
try {
|
||||
obj.origin_official_verify = typeof origin_user === 'undefined' ?
|
||||
false : origin_user.card.official_verify.type < 0 ?
|
||||
false : true; /* 是否官方号 */
|
||||
} catch (error) {
|
||||
obj.origin_official_verify = false;
|
||||
}
|
||||
obj.origin_hasOfficialLottery = typeof origin_extension === 'undefined' ?
|
||||
false : typeof origin_extension.lott === 'undefined' ?
|
||||
false : true; /* 是否有官方抽奖 */
|
||||
const origin = cardToJson.origin || '{}';
|
||||
const { user, item } = strToJson(origin);
|
||||
obj.origin_uname = typeof user === 'undefined' ? '' : user.name || user.uname || ''; /* 被转发者的name */
|
||||
obj.origin_description = typeof item === 'undefined' ? '' : item.content || item.description || ''; /* 被转发者的描述 */
|
||||
}
|
||||
array.push(obj);
|
||||
});
|
||||
}
|
||||
return {
|
||||
modifyDynamicResArray: array,
|
||||
nextinfo: next
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @typedef {object} LotteryInfo
|
||||
* @property {string} lottery_info_type
|
||||
* @property {number[]} uids `[uid,ouid]`
|
||||
* @property {string} uname
|
||||
* @property {Array<{}>} ctrl
|
||||
* @property {string} dyid
|
||||
* @property {boolean} befilter
|
||||
* @property {boolean} official_verify 官方认证
|
||||
* @property {string} rid
|
||||
* @property {string} des
|
||||
* @property {number} type
|
||||
* @property {boolean} hasOfficialLottery 是否官方
|
||||
*/
|
||||
/**
|
||||
* 获取tag下的抽奖信息(转发母动态)
|
||||
* 并初步整理
|
||||
* @param {string} tag_name
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByTag(tag_name) {
|
||||
const self = this,
|
||||
tag_id = await BiliAPI.getTagIDByTagName(tag_name),
|
||||
hotdy = await BiliAPI.getHotDynamicInfoByTagID(tag_id),
|
||||
modDR = self.modifyDynamicRes(hotdy);
|
||||
if (modDR === null) return null;
|
||||
Base.tooltip.log(`开始获取带话题#${tag_name}#的动态信息`);
|
||||
Base.tooltip.log('成功获取热门动态');
|
||||
let mDRdata = modDR.modifyDynamicResArray; /* 热门动态 */
|
||||
let next_offset = modDR.nextinfo.next_offset;
|
||||
for (let index = 0; index < config.scan_page_num; index++) {
|
||||
Base.tooltip.log(`成功读取${index + 1}页动态`);
|
||||
const newdy = await BiliAPI.getOneDynamicInfoByTag(tag_name, next_offset);
|
||||
const _modify = self.modifyDynamicRes(newdy);
|
||||
if (_modify === null) return null;
|
||||
mDRdata.push.apply(mDRdata, _modify.modifyDynamicResArray);
|
||||
next_offset = _modify.nextinfo.next_offset;
|
||||
await Base.delay(config.search_wait);
|
||||
}
|
||||
const fomatdata = mDRdata.map(o => {
|
||||
const hasOrigin = o.type === 1;
|
||||
return {
|
||||
lottery_info_type: 'tag',
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.uname,
|
||||
ctrl: o.ctrl,
|
||||
dyid: o.dynamic_id,
|
||||
official_verify: o.official_verify,
|
||||
befilter: hasOrigin,
|
||||
rid: o.rid_str,
|
||||
des: o.description,
|
||||
type: o.type,
|
||||
hasOfficialLottery: o.hasOfficialLottery
|
||||
};
|
||||
})
|
||||
Base.tooltip.log(`成功获取带话题#${tag_name}#的动态信息`);
|
||||
return fomatdata
|
||||
}
|
||||
/**
|
||||
* 获取最新动态信息(转发子动态)
|
||||
* 并初步整理
|
||||
* @param {string} UID
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByUID(UID) {
|
||||
Base.tooltip.log(`开始获取用户${UID}的动态信息`);
|
||||
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 {
|
||||
lottery_info_type: 'uid',
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.origin_uname,
|
||||
ctrl: [],
|
||||
dyid: o.origin_dynamic_id,
|
||||
official_verify: o.origin_official_verify,
|
||||
befilter: false,
|
||||
rid: o.origin_rid_str,
|
||||
des: o.origin_description,
|
||||
type: o.orig_type,
|
||||
hasOfficialLottery: o.origin_hasOfficialLottery
|
||||
}
|
||||
}).filter(a => a.type === 0 ? false : true)
|
||||
Base.tooltip.log(`成功获取用户${UID}的动态信息`);
|
||||
return fomatdata;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Public;
|
||||
@@ -0,0 +1,78 @@
|
||||
const { log, delay, infiniteNumber, judge } = require('./utils')
|
||||
const { sendNotify } = require('./helper/notify')
|
||||
const config = require('./data/config')
|
||||
const global_var = require('./data/global_var')
|
||||
const bili = require('./net/bili')
|
||||
|
||||
/**
|
||||
* 是否中奖
|
||||
*/
|
||||
async function isMe() {
|
||||
let desp = '';
|
||||
const UnreadAtNum = await bili.getUnreadAtNum();
|
||||
const UnreadSessionNum = await bili.getUnreadSessionNum();
|
||||
const { follow_unread, unfollow_unread } = UnreadSessionNum || { unfollow_unread: 0, follow_unread: 0 };
|
||||
if (UnreadAtNum > 0) {
|
||||
log.info('中奖检测', '<-- 正在检查at');
|
||||
const MyAtInfo = await bili.getMyAtInfo();
|
||||
MyAtInfo.forEach(async AtInfo => {
|
||||
const { at_time, up_uname, business, source_content, url } = AtInfo
|
||||
desp += `发生时间: ${new Date(at_time * 1000).toLocaleString()} \n\n`
|
||||
desp += `用户: ${up_uname} \n\n`
|
||||
desp += `在${business}中@了你(${global_var.get("myUID")}) \n\n`
|
||||
desp += `原内容为: ${source_content} \n\n`
|
||||
desp += `[直达链接](${url}) \n\n`
|
||||
desp += `\n\n`
|
||||
});
|
||||
log.info('中奖检测', '--> OK');
|
||||
}
|
||||
if (follow_unread + unfollow_unread > 0) {
|
||||
const check = async (type) => {
|
||||
let session_t = '';
|
||||
let MySession = await bili.getSessionInfo(type)
|
||||
for (const index of infiniteNumber()) {
|
||||
for (const Session of MySession.data) {
|
||||
const { content, sender_uid, session_ts, timestamp, unread_count, talker_id, msg_seqno } = Session;
|
||||
session_t = session_ts;
|
||||
if (unread_count) {
|
||||
bili.updateSessionStatus(talker_id, type, msg_seqno);
|
||||
await delay(1000);
|
||||
if (judge(content, config.notice_key_words)) {
|
||||
desp += `发生时间: ${new Date(timestamp * 1000).toLocaleString()} \n\n`
|
||||
desp += `用户: ${sender_uid} \n\n`
|
||||
desp += `私信你(${global_var.get("myUID")})说: ${content} \n\n`
|
||||
desp += `[直达链接](https://message.bilibili.com/#/whisper/mid${sender_uid}) \n\n`
|
||||
desp += `\n\n`
|
||||
}
|
||||
}
|
||||
}
|
||||
if (MySession.has_more && index < 16) {
|
||||
await delay(3e3);
|
||||
MySession = await bili.getSessionInfo(type, session_t)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (follow_unread) {
|
||||
log.info('中奖检测', '<-- 正在检查已关注者的私信')
|
||||
await check(1)
|
||||
}
|
||||
if (unfollow_unread) {
|
||||
log.info('中奖检测', '<-- 正在检查未关注者的私信')
|
||||
await check(2)
|
||||
}
|
||||
log.info('中奖检测', '--> OK');
|
||||
}
|
||||
if (desp) {
|
||||
desp += '中奖了别忘给脚本(https://github.com/shanmiteko/LotteryAutoScript)点一个Star哦, 赞助一两块也不是不可以_(:з」∠)_\n\n'
|
||||
log.info('可能中奖了', desp);
|
||||
await sendNotify('可能中奖了', desp);
|
||||
} else {
|
||||
log.info('中奖检测', "暂未中奖");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
module.exports = { isMe };
|
||||
+62
-55
@@ -1,32 +1,28 @@
|
||||
const Base = require("./Base");
|
||||
const BiliAPI = require("./BiliAPI");
|
||||
const { trigger } = require("./GithubAPI");
|
||||
const Public = require("./Public");
|
||||
const GlobalVar = require('./GlobalVar');
|
||||
const { followWhiteList } = require("./config");
|
||||
const config = require("./config");
|
||||
|
||||
/** Github运行限制时间*/
|
||||
const MAX_TIME = 6 * 60 * 60 * 1000 - 6 * 60 * 1000;
|
||||
/**动态偏移量 */
|
||||
let offset = '0';
|
||||
const { log, delay, infiniteNumber } = require("./utils");
|
||||
const bili = require("./net/bili");
|
||||
const { Searcher } = require("./core/searcher");
|
||||
const global_var = require('./data/global_var');
|
||||
const config = require("./data/config");
|
||||
|
||||
/**
|
||||
* 获取关注分区里的uid
|
||||
* @returns { Promise<number[]> }
|
||||
*/
|
||||
async function getFollowList() {
|
||||
const tagid = await BiliAPI.checkMyPartition(config.clear_partition);
|
||||
if (typeof tagid === 'undefined') { Base.tooltip.log('未能成功获取关注分区id'); return }
|
||||
const tagid = await bili.checkMyPartition(config.clear_partition);
|
||||
if (typeof tagid === 'undefined') {
|
||||
log.info('获取关注列表', '未能成功获取关注分区id');
|
||||
return
|
||||
}
|
||||
let rmup = [];
|
||||
for (let index = 1; index < 42; index++) {
|
||||
const uids = await BiliAPI.getPartitionUID(tagid, index);
|
||||
await Base.delay(2e3);
|
||||
const uids = await bili.getPartitionUID(tagid, index);
|
||||
await delay(2e3);
|
||||
if (!uids.length) break;
|
||||
rmup.push(...uids)
|
||||
}
|
||||
return followWhiteList.length
|
||||
? rmup.filter(uid => followWhiteList.split(',').indexOf(String(uid)) === -1)
|
||||
return config.clear_white_list.length
|
||||
? rmup.filter(uid => config.clear_white_list.split(',').indexOf(String(uid)) === -1)
|
||||
: rmup;
|
||||
}
|
||||
|
||||
@@ -34,47 +30,55 @@ async function getFollowList() {
|
||||
* 清理动态和关注
|
||||
*/
|
||||
async function clear() {
|
||||
const { clear_max_day, clear_remove_dynamic, clear_remove_attention, clear_remove_delay, clear_dynamic_type } = config;
|
||||
if (!process.env.LOCALLAUNCH) {
|
||||
setTimeout(() => {
|
||||
Base.tooltip.log('运行时间超过Actions上限 - 6小时');
|
||||
Base.tooltip.log('尝试再次触发clear 并中止此任务')
|
||||
trigger('clear.yml').then(() => {
|
||||
process.exit(0);
|
||||
})
|
||||
}, MAX_TIME);
|
||||
}
|
||||
const { clear_white_list, clear_max_day, clear_quick_remove_attention, clear_remove_dynamic, clear_remove_attention, clear_remove_delay, clear_dynamic_type } = config;
|
||||
let success = true;
|
||||
const uid_list = await getFollowList();
|
||||
if (!clear_remove_dynamic && clear_remove_attention) {
|
||||
if (!uid_list.length) {
|
||||
log.info('清理关注', `关注为空`)
|
||||
} else {
|
||||
log.info('清理关注', `共有${uid_list.length}个关注`)
|
||||
}
|
||||
if (clear_quick_remove_attention) {
|
||||
log.info('清理关注', '进入只清理关注模式')
|
||||
/* 专清关注 */
|
||||
for (let index = 0; index < uid_list.length; index++) {
|
||||
const uid = uid_list[index];
|
||||
for (const [index, uid] of uid_list.entries()) {
|
||||
log.info('清理关注', `(${index}) (${uid})`)
|
||||
/* 取消关注 */
|
||||
success = await BiliAPI.cancelAttention(uid);
|
||||
if (await bili.cancelAttention(uid)) {
|
||||
log.info('清理关注', '成功')
|
||||
} else {
|
||||
log.error('清理关注', '失败')
|
||||
break
|
||||
}
|
||||
/* 延时 */
|
||||
await Base.delay(clear_remove_delay);
|
||||
|
||||
if (!success) break;
|
||||
await delay(clear_remove_delay);
|
||||
}
|
||||
} else {
|
||||
const now = Date.now() / 1000;
|
||||
let before_separate = [];
|
||||
const MY_UID = Number(GlobalVar.get('myUID'));
|
||||
for (let index = 0; ; index++) {
|
||||
const { allModifyDynamicResArray, offset: _offset } = await Public.prototype.checkAllDynamic(GlobalVar.get("myUID"), 1, 5 * 1000, offset);
|
||||
offset = _offset;
|
||||
Base.tooltip.log(`开始读取第${index + 1}页(12条)`);
|
||||
for (let index = 0; index < allModifyDynamicResArray.length; index++) {
|
||||
const res = allModifyDynamicResArray[index];
|
||||
const { type, dynamic_id, createtime } = res;
|
||||
const
|
||||
Now = Date.now() / 1000,
|
||||
MY_UID = Number(global_var.get('myUID'));
|
||||
|
||||
let next_offset = '0',
|
||||
before_separate = [];
|
||||
|
||||
for (const page of infiniteNumber()) {
|
||||
log.info('清理动态', `开始读取第${page + 1}页`);
|
||||
const { allModifyDynamicResArray, offset } = await Searcher.checkAllDynamic(MY_UID, 1, 5 * 1000, next_offset);
|
||||
next_offset = offset;
|
||||
for (const [index, dyinfo] of allModifyDynamicResArray.entries()) {
|
||||
log.info('清理动态', `第${page + 1}页中的第${index + 1}个动态`)
|
||||
const { type, dynamic_id, createtime } = dyinfo || {};
|
||||
if (type === clear_dynamic_type) {
|
||||
const { origin_uid } = res;
|
||||
if ((now - createtime) > 86400 * clear_max_day) {
|
||||
const
|
||||
{ origin_uid } = dyinfo,
|
||||
days_ago = (Now - createtime) / 86400;
|
||||
|
||||
if (days_ago > clear_max_day) {
|
||||
/* 移除动态 */
|
||||
if (dynamic_id
|
||||
&& clear_remove_dynamic) {
|
||||
success = await BiliAPI.rmDynamic(dynamic_id)
|
||||
&& clear_remove_dynamic
|
||||
&& !(new RegExp(dynamic_id).test(clear_white_list))) {
|
||||
success = await bili.rmDynamic(dynamic_id)
|
||||
}
|
||||
|
||||
/* 取消关注 */
|
||||
@@ -83,20 +87,23 @@ async function clear() {
|
||||
&& clear_remove_attention
|
||||
&& before_separate.indexOf(origin_uid) === -1
|
||||
&& uid_list.indexOf(origin_uid) > -1) {
|
||||
success = await BiliAPI.cancelAttention(origin_uid);
|
||||
success = await bili.cancelAttention(origin_uid);
|
||||
}
|
||||
|
||||
/* 延时 */
|
||||
await Base.delay(clear_remove_delay);
|
||||
|
||||
if (!success) break;
|
||||
/* 延时 */
|
||||
await delay(clear_remove_delay);
|
||||
} else {
|
||||
log.info('清理动态', `已设置跳过${clear_max_day}天 当前动态发布时间: ${~~days_ago}天前`)
|
||||
log.info('清理动态', `储存用户(${origin_uid})防止误删`)
|
||||
before_separate.push(origin_uid)
|
||||
}
|
||||
} else {
|
||||
log.info('清理动态', `此动态类型为${type} != 要清理的动态类型${clear_dynamic_type}`)
|
||||
}
|
||||
}
|
||||
Base.tooltip.log(`第${index}页中的转发动态与关注全部处理成功`)
|
||||
if (offset === '0' || !success) break;
|
||||
log.info('清理动态', `第${page + 1}页(${allModifyDynamicResArray.length})中的转发动态与关注全部处理成功`)
|
||||
if (next_offset === '0' || !success) break;
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
const { config_file, tooltip } = require('./Base');
|
||||
|
||||
const my_config = (() => {
|
||||
let _my_config = {}
|
||||
try {
|
||||
_my_config = require(config_file)
|
||||
} catch (e) {
|
||||
tooltip.log("[config]自定义设置异常 原因如下:\n" + e);
|
||||
}
|
||||
return _my_config;
|
||||
})();
|
||||
|
||||
const config = {
|
||||
...my_config["default_config"],
|
||||
/**
|
||||
* @param {string} n
|
||||
*/
|
||||
updata(n) {
|
||||
const new_config = my_config[`config_${n}`];
|
||||
if (new_config) {
|
||||
Object.entries(new_config)
|
||||
.forEach(([k, v]) => this[k] = v)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = config;
|
||||
@@ -0,0 +1,395 @@
|
||||
const utils = require('../utils');
|
||||
const bili = require('../net/bili');
|
||||
const { sendNotify } = require('../helper/notify');
|
||||
const event_bus = require('../helper/event_bus');
|
||||
const { Searcher } = require('./searcher');
|
||||
const global_var = require("../data/global_var");
|
||||
const config = require("../data/config");
|
||||
const { log, hasEnv } = utils;
|
||||
|
||||
/**
|
||||
* 监视器
|
||||
*/
|
||||
class Monitor extends Searcher {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {[string, number | string]} lottery_param
|
||||
*/
|
||||
constructor(lottery_param) {
|
||||
super();
|
||||
this.lottery_param = lottery_param
|
||||
this.tagid = config.partition_id; /* tagid初始化 */
|
||||
this.attentionList = ''; /* 转为字符串的所有关注的up主uid */
|
||||
this.LotteryInfoMap = new Map([
|
||||
['UIDs', this.getLotteryInfoByUID.bind(this)],
|
||||
['TAGs', this.getLotteryInfoByTag.bind(this)],
|
||||
['Articles', this.getLotteryInfoByArticle.bind(this)],
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
async init() {
|
||||
if (config.model === '00') {
|
||||
event_bus.emit('Turn_off_the_Monitor', '已关闭所有转发行为')
|
||||
return
|
||||
}
|
||||
if (!this.tagid) {
|
||||
this.tagid = await bili.checkMyPartition() /* 检查关注分区 */
|
||||
if (!this.tagid) {
|
||||
event_bus.emit('Turn_off_the_Monitor', '分区获取失败')
|
||||
return
|
||||
}
|
||||
}
|
||||
/** 关注列表初始化 */
|
||||
this.attentionList = await bili.getAttentionList(global_var.get("myUID"));
|
||||
switch (await this.startLottery()) {
|
||||
case 0:
|
||||
event_bus.emit('Turn_on_the_Monitor')
|
||||
break;
|
||||
case 11:
|
||||
event_bus.emit('Turn_off_the_Monitor', '评论失败')
|
||||
break
|
||||
case 21:
|
||||
event_bus.emit('Turn_on_the_Monitor')
|
||||
break
|
||||
case 22:
|
||||
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关闭此推送`)
|
||||
}
|
||||
config.is_exception = true;
|
||||
event_bus.emit('Turn_on_the_Monitor')
|
||||
break
|
||||
case 31:
|
||||
event_bus.emit('Turn_off_the_Monitor', '转发失败')
|
||||
break
|
||||
case 41:
|
||||
event_bus.emit('Turn_off_the_Monitor', '获取开奖时间失败')
|
||||
break
|
||||
case 51:
|
||||
event_bus.emit('Turn_off_the_Monitor', '获取关注数失败')
|
||||
break
|
||||
default:
|
||||
event_bus.emit('Turn_off_the_Monitor', '未知错误')
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 启动
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
async startLottery() {
|
||||
const allLottery = await this.filterLotteryInfo()
|
||||
, len = allLottery.length
|
||||
, { dy_contents, create_dy, create_dy_mode, wait } = config;
|
||||
|
||||
log.info('筛选动态', `筛选完毕(${len})`);
|
||||
|
||||
if (len) {
|
||||
let is_exception = false;
|
||||
for (const [index, Lottery] of utils.shuffle(allLottery).entries()) {
|
||||
let status = 0;
|
||||
|
||||
if (Lottery.isOfficialLottery) {
|
||||
let { ts } = await bili.getLotteryNotice(Lottery.dyid);
|
||||
const ts_10 = Date.now() / 1000;
|
||||
if (ts < 0) {
|
||||
return 41
|
||||
}
|
||||
if (ts < ts_10) {
|
||||
log.info('过滤', '已过开奖时间')
|
||||
continue
|
||||
}
|
||||
if (ts > ts_10 + config.maxday * 86400) {
|
||||
log.info('过滤', '超过指定开奖时间')
|
||||
continue
|
||||
}
|
||||
} else if (Lottery.uid[0]) {
|
||||
const followerNum = await bili.getUserInfo(Lottery.uid[0]);
|
||||
if (followerNum < 0) {
|
||||
return 51
|
||||
}
|
||||
if (followerNum < config.minfollower) {
|
||||
log.info('过滤', `粉丝数(${followerNum})小于指定数量`)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (create_dy
|
||||
&& create_dy_mode instanceof Array
|
||||
&& index > 0
|
||||
&& index % create_dy_mode[0] === 0) {
|
||||
for (let i = 0; i < create_dy_mode[1]; i++) {
|
||||
await bili.createDynamic(utils.getRandomOne(dy_contents));
|
||||
await utils.delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
status = await this.go(Lottery)
|
||||
switch (status) {
|
||||
case 0:
|
||||
break;
|
||||
case 22:
|
||||
is_exception = true
|
||||
break;
|
||||
default:
|
||||
return status
|
||||
}
|
||||
|
||||
await utils.delay(wait * (Math.random() + 0.5));
|
||||
}
|
||||
log.info('抽奖', '开始转发下一组动态');
|
||||
if (is_exception) {
|
||||
return 22
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
} else {
|
||||
log.info('抽奖', '无未转发抽奖');
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖配置
|
||||
* @typedef {object} LotteryOptions
|
||||
* @property {number[]} uid 用户标识
|
||||
* @property {string} dyid 动态标识
|
||||
* @property {boolean} isOfficialLottery 是否官方抽奖
|
||||
* @property {string} relay_chat 转发词
|
||||
* @property {string} ctrl 定位@
|
||||
* @property {string} rid 评论标识
|
||||
* @property {number} chat_type 评论类型
|
||||
*/
|
||||
/**
|
||||
* @returns {Promise<LotteryOptions[]>}
|
||||
*/
|
||||
async filterLotteryInfo() {
|
||||
const { lottery_param, LotteryInfoMap, attentionList } = this;
|
||||
let protoLotteryInfo = await LotteryInfoMap.get(lottery_param[0])(lottery_param[1]);
|
||||
|
||||
if (protoLotteryInfo === null)
|
||||
return [];
|
||||
|
||||
log.info('筛选动态', `开始筛选(${protoLotteryInfo.length})`);
|
||||
|
||||
log.debug('未进行筛选的动态信息', protoLotteryInfo);
|
||||
|
||||
/** 所有抽奖信息 */
|
||||
let alllotteryinfo = [];
|
||||
const { key_words, model, chatmodel, is_imitator, only_followed, at_users, blockword, blacklist } = config;
|
||||
|
||||
/**Map<String, Boolean> */
|
||||
let dyids_map = new Map();
|
||||
|
||||
/**去重 */
|
||||
protoLotteryInfo = protoLotteryInfo.filter(({ dyid }) => {
|
||||
if (dyids_map.has(dyid)) {
|
||||
return false
|
||||
}
|
||||
dyids_map.set(dyid, false);
|
||||
return true
|
||||
});
|
||||
|
||||
/* 检查动态是否满足要求 */
|
||||
await utils.try_for_each(protoLotteryInfo, async function ({
|
||||
lottery_info_type, is_liked,
|
||||
uids, uname, dyid,
|
||||
ctrl, rid, des, type,
|
||||
hasOfficialLottery
|
||||
}) {
|
||||
/* 遇到转发过就退出 */
|
||||
if (is_liked) return false;
|
||||
|
||||
const
|
||||
/**判断是转发源动态还是现动态 */
|
||||
uid = lottery_info_type === 'uid' ? uids[1] : uids[0],
|
||||
isFollowed = (new RegExp(uid)).test(attentionList),
|
||||
description = typeof des === 'string' ? des : '',
|
||||
needAt = /(?:@|艾特)[^@|(艾特)]*?好友/.test(description),
|
||||
needTopic = [...new Set(description.match(/(?<=[带加上](?:话题|tag).*)#.+?#|(?<=[带加上])#.+?#(?=话题|tag)/ig) || [])].join(' '),
|
||||
isRelayDynamic = type === 1,
|
||||
isTwoLevelDynamic = /\/\/@/.test(description),
|
||||
has_key_words = key_words.every(it => new RegExp(it).test(description)),
|
||||
isBlock = new RegExp(blockword.join('|')).test(description),
|
||||
isLottery =
|
||||
(is_imitator && lottery_info_type === 'uid' && model !== '00')
|
||||
|| (hasOfficialLottery && model[0] === '1')
|
||||
|| (!hasOfficialLottery && model[1] === '1' && !isTwoLevelDynamic && has_key_words),
|
||||
isSendChat =
|
||||
(is_imitator && lottery_info_type === 'uid' && chatmodel !== '00')
|
||||
|| (hasOfficialLottery && chatmodel[0] === '1')
|
||||
|| (!hasOfficialLottery && chatmodel[1] === '1');
|
||||
|
||||
/**屏蔽词 */
|
||||
if (isBlock) return false;
|
||||
|
||||
/**若勾选只转已关注 */
|
||||
if (only_followed && !isFollowed) return false;
|
||||
|
||||
/* 获取黑名单并去重合并 */
|
||||
const { blacklist: remote_blacklist } = global_var.get("remoteconfig")
|
||||
, new_blacklist = remote_blacklist
|
||||
? [...new Set([...blacklist.split(','), ...remote_blacklist.split(',')])].join()
|
||||
: blacklist;
|
||||
if ((new RegExp(dyid + '|' + uid)).test(new_blacklist)) return false;
|
||||
|
||||
|
||||
if (isLottery) {
|
||||
let onelotteryinfo = {};
|
||||
|
||||
onelotteryinfo.isOfficialLottery = hasOfficialLottery;
|
||||
|
||||
/**初始化待关注列表 */
|
||||
onelotteryinfo.uid = []
|
||||
|
||||
if (!isFollowed) {
|
||||
onelotteryinfo.uid.push(uid);
|
||||
}
|
||||
|
||||
onelotteryinfo.dyid = dyid;
|
||||
|
||||
let
|
||||
/**转发评语 */
|
||||
RandomStr = utils.getRandomOne(config.relay),
|
||||
/**控制字段 */
|
||||
new_ctrl = [];
|
||||
|
||||
/* 是否需要带话题 */
|
||||
if (needTopic) {
|
||||
RandomStr += needTopic
|
||||
}
|
||||
|
||||
/* 是否需要@ */
|
||||
if (needAt) {
|
||||
at_users.forEach(it => {
|
||||
new_ctrl.push({
|
||||
data: String(it[1]),
|
||||
location: RandomStr.length,
|
||||
length: it[0].length + 1,
|
||||
type: 1
|
||||
})
|
||||
RandomStr += '@' + it[0]
|
||||
})
|
||||
}
|
||||
|
||||
/* 是否是转发的动态 */
|
||||
if (isRelayDynamic) {
|
||||
/* 转发内容长度+'//'+'@'+用户名+':'+源内容 */
|
||||
const addlength = RandomStr.length + 2 + uname.length + 1 + 1;
|
||||
onelotteryinfo.relay_chat = RandomStr + `//@${uname}:` + des;
|
||||
new_ctrl.push({
|
||||
data: String(uid),
|
||||
location: RandomStr.length + 2,
|
||||
length: uname.length + 1,
|
||||
type: 1
|
||||
})
|
||||
ctrl.map(item => {
|
||||
item.location += addlength;
|
||||
return item;
|
||||
}).forEach(it => new_ctrl.push(it))
|
||||
if (!(new RegExp(uids[1])).test(attentionList))
|
||||
onelotteryinfo.uid.push(uids[1]);
|
||||
} else {
|
||||
onelotteryinfo.relay_chat = RandomStr;
|
||||
}
|
||||
|
||||
onelotteryinfo.ctrl = JSON.stringify(new_ctrl);
|
||||
|
||||
/* 根据动态的类型决定评论的类型 */
|
||||
onelotteryinfo.chat_type =
|
||||
type === 2
|
||||
? 11
|
||||
: type === 4 || type === 1
|
||||
? 17
|
||||
: type === 8
|
||||
? 1
|
||||
: 0;
|
||||
|
||||
/* 是否评论 */
|
||||
if (isSendChat) onelotteryinfo.rid = rid;
|
||||
|
||||
alllotteryinfo.push(onelotteryinfo);
|
||||
}
|
||||
})
|
||||
|
||||
return alllotteryinfo;
|
||||
}
|
||||
/**
|
||||
* 关注转发评论
|
||||
* @param {LotteryOptions} option
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 11 - 评论错误
|
||||
* 21 - 关注错误
|
||||
* 22 - 关注异常
|
||||
* 31 - 转发失败
|
||||
*/
|
||||
async go(option) {
|
||||
log.debug('正在转发的动态信息', option);
|
||||
if (hasEnv('NOT_GO_LOTTERY')) {
|
||||
log.info('NOT_GO_LOTTERY', 'ON');
|
||||
return 0
|
||||
}
|
||||
const { uid, dyid, chat_type, rid, relay_chat, ctrl } = option;
|
||||
/* 评论 */
|
||||
if (rid && chat_type) {
|
||||
let status = 0;
|
||||
const max_retry_times = 5;
|
||||
for (let times = 0; times < max_retry_times; times++) {
|
||||
status = await bili.sendChat(rid, utils.getRandomOne(config.chat), chat_type)
|
||||
if (status === -1) {
|
||||
log.warn('抽奖信息', `uid: ${uid},dyid: ${dyid}`)
|
||||
return 0
|
||||
}
|
||||
if (!status) {
|
||||
break
|
||||
}
|
||||
log.error('抽奖信息', `uid: ${uid},dyid: ${dyid}`)
|
||||
log.info('自动评论', `将在 ${times + 1} 分钟后再次发送评论(${times + 1}/${max_retry_times})`)
|
||||
await utils.delay(60 * 1000 * (times + 1))
|
||||
}
|
||||
if (status) return 11;
|
||||
}
|
||||
|
||||
/* 关注 */
|
||||
const [u1, u2] = uid
|
||||
if (u1) {
|
||||
let status = await bili.autoAttention(u1)
|
||||
if (status) {
|
||||
log.error('抽奖信息', `uid: ${uid},dyid: ${dyid}`)
|
||||
return 20 + status
|
||||
};
|
||||
status = await bili.movePartition(u1, this.tagid)
|
||||
if (status) {
|
||||
log.error('抽奖信息', `uid: ${uid},dyid: ${dyid}`)
|
||||
return 20 + status
|
||||
};
|
||||
if (u2) {
|
||||
utils.delay(5000)
|
||||
status = await bili.autoAttention(u2)
|
||||
if (status) {
|
||||
log.error('抽奖信息', `uid: ${uid},dyid: ${dyid}`)
|
||||
return 20 + status
|
||||
};
|
||||
status = await bili.movePartition(u2, this.tagid)
|
||||
if (status) {
|
||||
log.error('抽奖信息', `uid: ${uid},dyid: ${dyid}`)
|
||||
return 20 + status
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* 点赞 */
|
||||
await bili.autolike(dyid)
|
||||
|
||||
/* 转发 */
|
||||
if (await bili.autoRelay(global_var.get("myUID"), dyid, relay_chat, ctrl)) return 31;
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { Monitor };
|
||||
@@ -0,0 +1,402 @@
|
||||
const utils = require('../utils');
|
||||
const bili = require('../net/bili');
|
||||
const config = require("../data/config");
|
||||
|
||||
const { log } = utils
|
||||
|
||||
/**
|
||||
* 解析dynamic_detail_card
|
||||
* 提取出的有用动态信息
|
||||
* @typedef {object} UsefulDynamicInfo
|
||||
* @property {number} uid
|
||||
* @property {string} uname
|
||||
* @property {boolean} is_liked
|
||||
* @property {number} createtime 10
|
||||
* @property {string} rid_str
|
||||
* @property {string} dynamic_id
|
||||
* @property {number} type
|
||||
* @property {string} description
|
||||
* @property {boolean} hasOfficialLottery
|
||||
* @property {Array<Object.<string,string|number>>} ctrl
|
||||
*
|
||||
* @property {number} origin_uid
|
||||
* @property {string} origin_uname
|
||||
* @property {string} origin_rid_str
|
||||
* @property {string} origin_dynamic_id
|
||||
* @property {number} orig_type
|
||||
* @property {string} origin_description
|
||||
* @property {boolean} origin_hasOfficialLottery
|
||||
*
|
||||
* @param {object} dynamic_detail_card
|
||||
* @return {UsefulDynamicInfo}
|
||||
*/
|
||||
function parseDynamicCard(dynamic_detail_card) {
|
||||
const { strToJson } = utils;
|
||||
/**临时储存单个动态中的信息 */
|
||||
let obj = {};
|
||||
const { desc, card, extension, extend_json } = dynamic_detail_card
|
||||
, { is_liked, user_profile } = desc
|
||||
, { info } = user_profile
|
||||
, cardToJson = strToJson(card)
|
||||
, { item } = cardToJson;
|
||||
/* 转发者的UID */
|
||||
obj.uid = info.uid
|
||||
/* 转发者的name */
|
||||
obj.uname = info.uname
|
||||
/* 动态是否点过赞 */
|
||||
obj.is_liked = is_liked > 0
|
||||
/* 动态的ts10 */
|
||||
obj.createtime = desc.timestamp
|
||||
/* 动态类型 */
|
||||
obj.type = desc.type
|
||||
/* 用于发送评论 */
|
||||
obj.rid_str = desc.rid_str.length > 12 ? desc.dynamic_id_str : desc.rid_str;
|
||||
/* 源动态类型 */
|
||||
obj.orig_type = desc.orig_type
|
||||
/* 转发者的动态ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
obj.dynamic_id = desc.dynamic_id_str;
|
||||
/* 定位@信息 */
|
||||
obj.ctrl = (extend_json && strToJson(extend_json).ctrl) || [];
|
||||
/* 是否有官方抽奖 */
|
||||
obj.hasOfficialLottery = extension && extension.lott && true;
|
||||
/* 转发者的描述 后两个分别是视频动态的描述和视频本身的描述*/
|
||||
obj.description = (item && (item.content || item.description || cardToJson.dynamic || cardToJson.desc)) || '';
|
||||
if (obj.type === 1) {
|
||||
const { origin_extension, origin } = cardToJson
|
||||
, originToJson = strToJson(origin)
|
||||
, { user, item } = originToJson;
|
||||
/* 被转发者的UID */
|
||||
obj.origin_uid = desc.origin.uid;
|
||||
/* 被转发者的rid(用于发评论) */
|
||||
obj.origin_rid_str = desc.origin.rid_str.length > 12 ? desc.origin.dynamic_id_str : desc.origin.rid_str;
|
||||
/* 被转发者的动态的ID !!!!此为大数需使用字符串值,不然JSON.parse()会有丢失精度 */
|
||||
obj.origin_dynamic_id = desc.orig_dy_id_str;
|
||||
/* 是否有官方抽奖 */
|
||||
obj.origin_hasOfficialLottery = origin_extension && origin_extension.lott;
|
||||
/* 被转发者的name */
|
||||
obj.origin_uname = (user && (user.name || user.uname)) || '';
|
||||
/* 被转发者的描述 */
|
||||
obj.origin_description = (item && (item.content || item.description || originToJson.dynamic || originToJson.desc)) || '';
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理来自个人动态或话题页面的一组动态数据
|
||||
* @param {String} res
|
||||
* @returns {{modifyDynamicResArray: UsefulDynamicInfo[], nextinfo: {has_more: number, next_offset: string}} | UsefulDynamicInfo |null}
|
||||
*/
|
||||
function modifyDynamicRes(res) {
|
||||
const
|
||||
{ data, code } = utils.strToJson(res),
|
||||
{ cards = [], has_more, offset } = data || {};
|
||||
|
||||
if (code !== 0) {
|
||||
log.error('处理动态数据', '获取动态数据出错,可能是访问太频繁 \n' + res);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!cards.length) {
|
||||
log.warn('处理动态数据', '未找到任何动态信息')
|
||||
}
|
||||
|
||||
const
|
||||
/**
|
||||
* 字符串offset防止损失精度
|
||||
*/
|
||||
next = {
|
||||
has_more,
|
||||
next_offset: typeof offset === 'string'
|
||||
? offset
|
||||
: /(?<=next_offset":)[0-9]+/.exec(res)[0]
|
||||
},
|
||||
/**
|
||||
* 储存获取到的一组动态中的信息
|
||||
*/
|
||||
array = next.has_more === 0
|
||||
? []
|
||||
: cards.map(parseDynamicCard)
|
||||
|
||||
log.info('处理动态数据', `动态数据读取完毕(${cards.length})(${next.has_more})`);
|
||||
|
||||
return {
|
||||
modifyDynamicResArray: array,
|
||||
nextinfo: next
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础搜索功能
|
||||
*/
|
||||
class Searcher {
|
||||
constructor() { }
|
||||
/**
|
||||
* 整理后的抽奖信息
|
||||
* @typedef {object} LotteryInfo
|
||||
* @property {string} lottery_info_type
|
||||
* @property {boolean} is_liked
|
||||
* @property {number[]} uids `[uid,ouid]`
|
||||
* @property {string} uname
|
||||
* @property {Array<{}>} ctrl
|
||||
* @property {string} dyid
|
||||
* @property {string} rid
|
||||
* @property {string} des
|
||||
* @property {number} type
|
||||
* @property {boolean} hasOfficialLottery 是否官方
|
||||
*/
|
||||
/**
|
||||
* 检查指定用户的所有的动态信息
|
||||
* @param {number} hostuid 指定的用户UID
|
||||
* @param {number} pages 读取页数
|
||||
* @param {number} time 时延
|
||||
* @param {string} [offset] 默认'0'
|
||||
* @returns {Promise<{allModifyDynamicResArray: UsefulDynamicInfo[], offset: string}>} 获取前 `pages*12` 个动态信息
|
||||
*/
|
||||
static async checkAllDynamic(hostuid, pages, time = 0, offset = '0') {
|
||||
log.info('检查所有动态', `准备读取${pages}页动态`);
|
||||
|
||||
const { getOneDynamicInfoByUID } = bili,
|
||||
/**
|
||||
* 柯里化请求函数
|
||||
*/
|
||||
curriedGetOneDynamicInfoByUID = utils.curryify(getOneDynamicInfoByUID),
|
||||
/**
|
||||
* 储存了特定UID的请求函数
|
||||
*/
|
||||
hadUidGetOneDynamicInfoByUID = curriedGetOneDynamicInfoByUID(hostuid);
|
||||
|
||||
/**
|
||||
* 储存所有经过整理后信息
|
||||
* @type { UsefulDynamicInfo[] }
|
||||
*/
|
||||
let allModifyDynamicResArray = [];
|
||||
|
||||
for (let i = 0; i < pages; i++) {
|
||||
log.info('检查所有动态', `正在读取其中第${i + 1}页动态`);
|
||||
|
||||
const
|
||||
OneDynamicInfo = await hadUidGetOneDynamicInfoByUID(offset),
|
||||
mDRdata = modifyDynamicRes(OneDynamicInfo);
|
||||
|
||||
if (mDRdata === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
const
|
||||
/**
|
||||
* 一片动态
|
||||
*/
|
||||
mDRArry = mDRdata.modifyDynamicResArray,
|
||||
nextinfo = mDRdata.nextinfo;
|
||||
|
||||
if (nextinfo.has_more === 0) {
|
||||
offset = nextinfo.next_offset;
|
||||
log.info('检查所有动态', `已经是最后一页了故无法读取更多`);
|
||||
break;
|
||||
} else {
|
||||
/**合并 */
|
||||
allModifyDynamicResArray.push.apply(allModifyDynamicResArray, mDRArry);
|
||||
offset = nextinfo.next_offset;
|
||||
}
|
||||
|
||||
await utils.delay(time);
|
||||
}
|
||||
|
||||
log.info('检查所有动态', `${pages}页信息读取完成`)
|
||||
|
||||
return ({ allModifyDynamicResArray, offset });
|
||||
}
|
||||
/**
|
||||
* 获取最新动态信息(转发子动态)
|
||||
* 并初步整理
|
||||
* @param {string} UID
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByUID(UID) {
|
||||
log.info('获取动态', `开始获取用户${UID}的动态信息`);
|
||||
const { allModifyDynamicResArray } = await Searcher.checkAllDynamic(UID, config.uid_scan_page, config.search_wait);
|
||||
|
||||
let { length } = allModifyDynamicResArray
|
||||
|
||||
if (!length) return null;
|
||||
|
||||
const fomatdata = await allModifyDynamicResArray
|
||||
.filter(d => {
|
||||
if (d.type === 1) {
|
||||
return true
|
||||
} else {
|
||||
length--
|
||||
return false
|
||||
}
|
||||
})
|
||||
.reduce(async (pre, cur) => {
|
||||
const results = await pre
|
||||
, { origin_dynamic_id } = cur;
|
||||
|
||||
log.info('获取动态', `查看源动态(${origin_dynamic_id})的细节 (${length--})`)
|
||||
|
||||
const card = await bili.getOneDynamicByDyid(origin_dynamic_id)
|
||||
|
||||
if (card) {
|
||||
await utils.delay(2000)
|
||||
|
||||
const { is_liked } = parseDynamicCard(card)
|
||||
|
||||
return [...results, {
|
||||
lottery_info_type: 'uid',
|
||||
is_liked,
|
||||
uids: [cur.uid, cur.origin_uid],
|
||||
uname: cur.origin_uname,
|
||||
ctrl: [],
|
||||
dyid: cur.origin_dynamic_id,
|
||||
rid: cur.origin_rid_str,
|
||||
des: cur.origin_description,
|
||||
type: cur.orig_type,
|
||||
hasOfficialLottery: cur.origin_hasOfficialLottery
|
||||
}]
|
||||
}
|
||||
|
||||
return results
|
||||
|
||||
}, Promise.resolve([]))
|
||||
|
||||
log.info('获取动态', `成功获取用户${UID}的动态信息`);
|
||||
|
||||
return fomatdata;
|
||||
}
|
||||
/**
|
||||
* 获取tag下的抽奖信息(转发母动态)
|
||||
* 并初步整理
|
||||
* @param {string} tag_name
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByTag(tag_name) {
|
||||
const
|
||||
tag_id = await bili.getTagIDByTagName(tag_name),
|
||||
hotdy = await bili.getHotDynamicInfoByTagID(tag_id),
|
||||
modDR = modifyDynamicRes(hotdy);
|
||||
|
||||
if (modDR === null) return null;
|
||||
|
||||
log.info('获取动态', `开始获取带话题#${tag_name}#的动态信息`);
|
||||
log.info('获取动态', '成功获取热门动态');
|
||||
|
||||
/**
|
||||
* 热门动态
|
||||
*/
|
||||
let mDRdata = modDR.modifyDynamicResArray;
|
||||
let next_offset = modDR.nextinfo.next_offset;
|
||||
|
||||
for (let index = 0; index < config.tag_scan_page; index++) {
|
||||
log.info('获取动态', `读取第${index + 1}页动态`);
|
||||
const
|
||||
newdy = await bili.getOneDynamicInfoByTag(tag_name, next_offset),
|
||||
_modify = modifyDynamicRes(newdy);
|
||||
|
||||
if (_modify === null) return null;
|
||||
|
||||
mDRdata.push.apply(mDRdata, _modify.modifyDynamicResArray);
|
||||
next_offset = _modify.nextinfo.next_offset;
|
||||
|
||||
await utils.delay(config.search_wait);
|
||||
}
|
||||
const fomatdata = mDRdata.map(o => {
|
||||
return {
|
||||
lottery_info_type: 'tag',
|
||||
is_liked: o.is_liked,
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.uname,
|
||||
ctrl: o.ctrl,
|
||||
dyid: o.dynamic_id,
|
||||
rid: o.rid_str,
|
||||
des: o.description,
|
||||
type: o.type,
|
||||
hasOfficialLottery: o.hasOfficialLottery
|
||||
};
|
||||
})
|
||||
log.info('获取动态', `成功获取带话题#${tag_name}#的动态信息`);
|
||||
|
||||
return fomatdata
|
||||
}
|
||||
/**
|
||||
* 从专栏中获取抽奖信息
|
||||
* @param {string} key_words
|
||||
* @returns {Promise<LotteryInfo[] | null>}
|
||||
*/
|
||||
async getLotteryInfoByArticle(key_words) {
|
||||
log.info('获取动态', `开始获取含关键词${key_words}的专栏信息`);
|
||||
const cvs = (await bili.searchArticlesByKeyword(key_words)).slice(0, config.article_scan_page);
|
||||
|
||||
/**存储所有专栏中的dyid */
|
||||
let dyinfos = [];
|
||||
/**遍历专栏s */
|
||||
for (const cv of cvs) {
|
||||
const
|
||||
content = await bili.getOneArticleByCv(cv),
|
||||
dyids = content.match(/(?<=t.bilibili.com\/)[0-9]+/g) || [],
|
||||
dyids_set = [...new Set(dyids)],
|
||||
/**判断此专栏是否查看过的权重 */
|
||||
weight = dyids_set.length / 2;
|
||||
|
||||
let { length } = dyids_set,
|
||||
/**初始权重 */
|
||||
_weight = 0,
|
||||
/**单个专栏中的dyid */
|
||||
_dyinfos = [];
|
||||
log.info('获取动态', `提取专栏(${cv})中提及的dyid(${length})`)
|
||||
|
||||
/**遍历某专栏中的dyids */
|
||||
for (const dyid of dyids_set) {
|
||||
if (dyid.length === utils.dyid_length) {
|
||||
log.info('获取动态', `查看专栏中所提及动态(${dyid})的细节 (${length--})`)
|
||||
|
||||
const card = await bili.getOneDynamicByDyid(dyid)
|
||||
|
||||
if (card) {
|
||||
await utils.delay(2000)
|
||||
|
||||
const parsed_card = parseDynamicCard(card)
|
||||
, { is_liked } = parsed_card;
|
||||
|
||||
if (is_liked) {
|
||||
log.info('获取动态', `动态(${dyid})已转发过`)
|
||||
_weight += 1;
|
||||
}
|
||||
|
||||
if (_weight >= weight && !config.not_check_article) {
|
||||
log.warn('获取动态', `1/2动态曾经转过,该专栏或已查看,故中止`)
|
||||
_dyinfos = []
|
||||
break
|
||||
}
|
||||
|
||||
_dyinfos.push(parsed_card);
|
||||
}
|
||||
} else {
|
||||
log.warn('获取动态', `动态(${dyid})无效 (${length--})`)
|
||||
}
|
||||
}
|
||||
dyinfos.push(..._dyinfos)
|
||||
}
|
||||
const fomatdata = dyinfos.map(o => {
|
||||
return {
|
||||
lottery_info_type: 'article',
|
||||
is_liked: o.is_liked,
|
||||
uids: [o.uid, o.origin_uid],
|
||||
uname: o.uname,
|
||||
ctrl: o.ctrl,
|
||||
dyid: o.dynamic_id,
|
||||
rid: o.rid_str,
|
||||
des: o.description,
|
||||
type: o.type,
|
||||
hasOfficialLottery: o.hasOfficialLottery
|
||||
};
|
||||
})
|
||||
log.info('获取动态', `成功获取含关键词${key_words}的专栏信息`);
|
||||
|
||||
return fomatdata
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { Searcher };
|
||||
@@ -0,0 +1,30 @@
|
||||
const { config_file } = require('../utils');
|
||||
|
||||
const config = {
|
||||
/**
|
||||
* 原始设置
|
||||
* @returns {Object}
|
||||
*/
|
||||
raw_config() {
|
||||
delete require.cache[config_file];
|
||||
return require(config_file)
|
||||
},
|
||||
/**
|
||||
* @param {string} n
|
||||
*/
|
||||
updata(n) {
|
||||
const new_config = this.raw_config()[`config_${n}`];
|
||||
if (new_config) {
|
||||
this.setObject(new_config)
|
||||
}
|
||||
},
|
||||
init() {
|
||||
this.setObject(this.raw_config()["default_config"])
|
||||
},
|
||||
setObject(o) {
|
||||
Object.entries(o).forEach(([k, v]) => this[k] = v)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = config;
|
||||
@@ -0,0 +1,34 @@
|
||||
const { env_file } = require("../utils");
|
||||
|
||||
const env = {
|
||||
/**
|
||||
* 原始环境
|
||||
* @returns {Object}
|
||||
*/
|
||||
raw_env() {
|
||||
delete require.cache[env_file];
|
||||
return require(env_file)
|
||||
},
|
||||
init() {
|
||||
const raw_env = this.raw_env()
|
||||
this.setEnv({
|
||||
...raw_env["account_parm"],
|
||||
...raw_env["push_parm"]
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @returns {Object[]}
|
||||
*/
|
||||
get_multiple_account() {
|
||||
return this.raw_env()["multiple_account_parm"]
|
||||
},
|
||||
setEnv(o) {
|
||||
process.env = {
|
||||
...process.env,
|
||||
...o
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = env;
|
||||
@@ -0,0 +1,44 @@
|
||||
const { getRemoteConfig, createDir, createFile } = require("../utils");
|
||||
const config = require("../data/config");
|
||||
|
||||
const key_map = new Map([['DedeUserID', 'myUID'], ['bili_jct', 'csrf']]);
|
||||
|
||||
let global_var = {
|
||||
inner: {},
|
||||
get(key) {
|
||||
return this.inner[key]
|
||||
},
|
||||
set(key, value) {
|
||||
this.inner[key] = value
|
||||
},
|
||||
/**
|
||||
* 全局变量初始化
|
||||
* 更新config
|
||||
* @param {string} cookie
|
||||
* @param {number} n
|
||||
*/
|
||||
async init(cookie, n) {
|
||||
if (cookie) {
|
||||
config.updata(process.env.NUMBER);
|
||||
|
||||
this.set('cookie', cookie);
|
||||
|
||||
cookie.split(/\s*;\s*/).forEach(item => {
|
||||
const _item = item.split('=');
|
||||
if (key_map.has(_item[0]))
|
||||
this.set(key_map.get(_item[0]), _item[1]);
|
||||
});
|
||||
|
||||
const { UIDs = [], TAGs = [], Articles = [] } = config;
|
||||
this.set('Lottery', [
|
||||
...UIDs.map(it => ['UIDs', it]),
|
||||
...TAGs.map(it => ['TAGs', it]),
|
||||
...Articles.map(it => ['Articles', it])
|
||||
]);
|
||||
this.set('remoteconfig', await getRemoteConfig());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = global_var;
|
||||
@@ -3,7 +3,7 @@ const { EventEmitter } = require('events');
|
||||
/**
|
||||
* 事件总线
|
||||
*/
|
||||
const eventBus = {
|
||||
const event_bus = {
|
||||
ee: new EventEmitter(),
|
||||
event_list: [],
|
||||
on(event, fn) {
|
||||
@@ -22,4 +22,4 @@ const eventBus = {
|
||||
}
|
||||
|
||||
|
||||
module.exports = eventBus;
|
||||
module.exports = event_bus;
|
||||
@@ -1,5 +1,5 @@
|
||||
const { tooltip } = require("./Base");
|
||||
const { HttpRequest } = require("./HttpRequest");
|
||||
const { log } = require("../utils");
|
||||
const { send } = require("../net/http");
|
||||
const { createTransport } = require("nodemailer");
|
||||
|
||||
// =======================================微信server酱通知设置区域===========================================
|
||||
@@ -185,7 +185,7 @@ async function sendNotify(text, desp, params = {}) {
|
||||
function serverNotify(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (SCKEY) {
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'GET',
|
||||
url: `https://sc.ftqq.com/${SCKEY}.send`,
|
||||
query: {
|
||||
@@ -202,26 +202,26 @@ function serverNotify(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.errno === 0) {
|
||||
tooltip.log('server酱发送通知消息成功\n')
|
||||
log.info('发送通知', 'server酱发送通知消息成功')
|
||||
} else if (data.errno === 1024) {
|
||||
// 一分钟内发送相同的内容会触发
|
||||
tooltip.log(`server酱发送通知消息异常: ${data.errmsg}\n`)
|
||||
log.error('发送通知', `server酱发送通知消息异常: ${data.errmsg}`)
|
||||
} else {
|
||||
tooltip.log(`server酱发送通知消息异常\n${JSON.stringify(data)}`)
|
||||
log.error('发送通知', `server酱发送通知消息异常\n${JSON.stringify(data)}`)
|
||||
}
|
||||
} catch (error) {
|
||||
tooltip.log(error);
|
||||
log.error('发送通知', error);
|
||||
} finally {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('server酱 发送通知调用API失败!!\n')
|
||||
log.error('发送通知', 'server酱 发送通知调用API失败!!')
|
||||
throw new Error(err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供server酱的SCKEY,取消微信推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供server酱的SCKEY,取消微信推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -230,7 +230,7 @@ function serverNotify(text, desp) {
|
||||
function serverNotifyTurbo(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (SENDKEY) {
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://sctapi.ftqq.com/${SENDKEY}.send`,
|
||||
contents: {
|
||||
@@ -247,23 +247,23 @@ function serverNotifyTurbo(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.code === 0) {
|
||||
tooltip.log('server酱(Turbo版)发送通知消息成功\n')
|
||||
log.info('发送通知', 'server酱(Turbo版)发送通知消息成功')
|
||||
} else {
|
||||
tooltip.log(`server酱(Turbo版)发送通知消息异常\n${JSON.stringify(data)}`)
|
||||
log.error('发送通知', `server酱(Turbo版)发送通知消息异常\n${JSON.stringify(data)}`)
|
||||
}
|
||||
} catch (error) {
|
||||
tooltip.log(error);
|
||||
log.error('发送通知', error);
|
||||
} finally {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('server酱(Turbo版) 发送通知调用API失败!!\n')
|
||||
log.error('发送通知', 'server酱(Turbo版) 发送通知调用API失败!!')
|
||||
throw new Error(err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供server酱(Turbo版)的SCKEY,取消微信推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供server酱(Turbo版)的SCKEY,取消微信推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -286,7 +286,7 @@ function coolPush(text, desp) {
|
||||
return "未知方式"
|
||||
}
|
||||
}
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://push.xuthus.cc/${QQ_MODE}/${QQ_SKEY}`,
|
||||
contents: `${text}\n${desp}`,
|
||||
@@ -301,25 +301,25 @@ function coolPush(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.code === 200) {
|
||||
tooltip.log(`酷推发送${pushMode(QQ_MODE)}通知消息成功\n`)
|
||||
log.info('发送通知', `酷推发送${pushMode(QQ_MODE)}通知消息成功`)
|
||||
} else if (data.code === 400) {
|
||||
tooltip.log(`QQ酷推(Cool Push)发送${pushMode(QQ_MODE)}推送失败:${data}\n`)
|
||||
log.error('发送通知', `QQ酷推(Cool Push)发送${pushMode(QQ_MODE)}推送失败:${data}`)
|
||||
} else {
|
||||
tooltip.log(`酷推推送异常: ${data.msg}`);
|
||||
log.error('发送通知', `酷推推送异常: ${data.msg}`);
|
||||
}
|
||||
} catch (error) {
|
||||
tooltip.log(error);
|
||||
log.error('发送通知', error);
|
||||
} finally {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(`酷推 发送${pushMode(QQ_MODE)}通知调用API失败!!\n`)
|
||||
log.error('发送通知', `酷推 发送${pushMode(QQ_MODE)}通知调用API失败!!`)
|
||||
throw new Error(err);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供酷推的SKEY,取消QQ推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供酷推的SKEY,取消QQ推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -328,7 +328,7 @@ function coolPush(text, desp) {
|
||||
function barkNotify(text, desp, params = {}) {
|
||||
return new Promise(resolve => {
|
||||
if (BARK_PUSH) {
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'GET',
|
||||
url: `${BARK_PUSH}/${encodeURIComponent(text)}/${encodeURIComponent(desp)}`,
|
||||
query: {
|
||||
@@ -345,24 +345,24 @@ function barkNotify(text, desp, params = {}) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.code === 200) {
|
||||
tooltip.log('Bark APP发送通知消息成功\n')
|
||||
log.info('发送通知', 'Bark APP发送通知消息成功')
|
||||
} else {
|
||||
tooltip.log(`${data.message}\n`);
|
||||
log.error('发送通知', `${data.message}`);
|
||||
}
|
||||
} catch (error) {
|
||||
tooltip.log(error);
|
||||
log.error('发送通知', error);
|
||||
} finally {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('Bark APP发送通知调用API失败!!\n');
|
||||
log.error('发送通知', 'Bark APP发送通知调用API失败!!');
|
||||
resolve();
|
||||
throw new Error(err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供Bark的APP推送BARK_PUSH,取消Bark推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -391,20 +391,20 @@ function tgBotNotify(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.ok) {
|
||||
tooltip.log('Telegram发送通知消息完成。\n')
|
||||
log.info('发送通知', 'Telegram发送通知消息完成。')
|
||||
} else if (data.error_code === 400) {
|
||||
tooltip.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n')
|
||||
log.error('发送通知', '请主动给bot发送一条消息并检查接收用户ID是否正确。')
|
||||
} else if (data.error_code === 401) {
|
||||
tooltip.log('Telegram bot token 填写错误。\n')
|
||||
log.error('发送通知', 'Telegram bot token 填写错误。')
|
||||
}
|
||||
} catch (error) {
|
||||
tooltip.log(error);
|
||||
log.error('发送通知', error);
|
||||
} finally {
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('telegram发送通知消息失败!!\n')
|
||||
log.error('发送通知', 'telegram发送通知消息失败!!')
|
||||
resolve()
|
||||
throw new Error(err)
|
||||
}
|
||||
@@ -415,9 +415,9 @@ function tgBotNotify(text, desp) {
|
||||
port: TG_PROXY_PORT * 1
|
||||
}
|
||||
}
|
||||
HttpRequest(options)
|
||||
send(options)
|
||||
} else {
|
||||
tooltip.log('您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -430,8 +430,8 @@ function ddBotNotify(text, desp) {
|
||||
const dateNow = Date.now();
|
||||
const hmac = crypto.createHmac('sha256', DD_BOT_SECRET);
|
||||
hmac.update(`${dateNow}\n${DD_BOT_SECRET}`);
|
||||
const result = encodeURIComponent(hmac.digest('base64'));
|
||||
HttpRequest({
|
||||
const result = encodeURIComponent(hmac.digest().toString('base64'));
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://oapi.dingtalk.com/robot/send`,
|
||||
query: {
|
||||
@@ -456,23 +456,23 @@ function ddBotNotify(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.errcode === 0) {
|
||||
tooltip.log('钉钉发送通知消息完成。\n')
|
||||
log.info('发送通知', '钉钉发送通知消息完成。')
|
||||
} else {
|
||||
tooltip.log(`${data.errmsg}\n`)
|
||||
log.error('发送通知', `${data.errmsg}`)
|
||||
}
|
||||
} catch (e) {
|
||||
tooltip.log(e);
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('钉钉发送通知消息失败!!\n')
|
||||
log.error('发送通知', '钉钉发送通知消息失败!!')
|
||||
throw new Error(err);
|
||||
}
|
||||
})
|
||||
} else if (DD_BOT_TOKEN) {
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://oapi.dingtalk.com/robot/send`,
|
||||
query: {
|
||||
@@ -495,24 +495,24 @@ function ddBotNotify(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.errcode === 0) {
|
||||
tooltip.log('钉钉发送通知消息完成。\n')
|
||||
log.info('发送通知', '钉钉发送通知消息完成。')
|
||||
} else {
|
||||
tooltip.log(`${data.errmsg}\n`)
|
||||
log.error('发送通知', `${data.errmsg}`)
|
||||
}
|
||||
} catch (e) {
|
||||
tooltip.log(e);
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('钉钉发送通知消息失败!!\n');
|
||||
log.error('发送通知', '钉钉发送通知消息失败!!');
|
||||
resolve();
|
||||
throw new Error(err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供钉钉机器人推送所需的DD_BOT_TOKEN或者DD_BOT_SECRET,取消钉钉推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -521,7 +521,7 @@ function ddBotNotify(text, desp) {
|
||||
function qywxBotNotify(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (QYWX_KEY) {
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${QYWX_KEY}`,
|
||||
contents: {
|
||||
@@ -541,24 +541,24 @@ function qywxBotNotify(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.errcode === 0) {
|
||||
tooltip.log('企业微信发送通知消息完成。\n');
|
||||
log.info('发送通知', '企业微信发送通知消息完成。');
|
||||
} else {
|
||||
tooltip.log(`${data.errmsg}\n`);
|
||||
log.error('发送通知', `${data.errmsg}`);
|
||||
}
|
||||
} catch (e) {
|
||||
tooltip.log(e);
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('企业微信发送通知消息失败!!\n');
|
||||
log.error('发送通知', '企业微信发送通知消息失败!!');
|
||||
resolve();
|
||||
throw new Error(err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供企业微信机器人推送所需的QYWX_KEY,取消企业微信推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供企业微信机器人推送所需的QYWX_KEY,取消企业微信推送消息通知');
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
@@ -570,11 +570,11 @@ function iGotNotify(text, desp, params = {}) {
|
||||
// 校验传入的IGOT_PUSH_KEY是否有效
|
||||
const IGOT_PUSH_KEY_REGX = new RegExp("^[a-zA-Z0-9]{24}$")
|
||||
if (!IGOT_PUSH_KEY_REGX.test(IGOT_PUSH_KEY)) {
|
||||
tooltip.log('您所提供的IGOT_PUSH_KEY无效\n')
|
||||
log.error('发送通知', '您所提供的IGOT_PUSH_KEY无效')
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'POST',
|
||||
url: `https://push.hellyw.com/${IGOT_PUSH_KEY.toLowerCase()}`,
|
||||
contents: {
|
||||
@@ -593,24 +593,24 @@ function iGotNotify(text, desp, params = {}) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.ret === 0) {
|
||||
tooltip.log('iGot发送通知消息成功\n')
|
||||
log.info('发送通知', 'iGot发送通知消息成功')
|
||||
} else {
|
||||
tooltip.log(`iGot发送通知消息失败:${data.errMsg}\n`)
|
||||
log.error('发送通知', `iGot发送通知消息失败:${data.errMsg}`)
|
||||
}
|
||||
} catch (e) {
|
||||
tooltip.log(e);
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log('iGot 发送通知调用API失败!!\n')
|
||||
log.error('发送通知', 'iGot 发送通知调用API失败!!')
|
||||
resolve();
|
||||
throw new Error(err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供iGot的推送IGOT_PUSH_KEY,取消iGot推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -619,7 +619,7 @@ function iGotNotify(text, desp, params = {}) {
|
||||
function pushPlusNotify(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (PUSH_PLUS_TOKEN) {
|
||||
HttpRequest({
|
||||
send({
|
||||
method: 'POST',
|
||||
url: 'https://pushplus.hxtrip.com/send',
|
||||
contents: {
|
||||
@@ -639,24 +639,24 @@ function pushPlusNotify(text, desp) {
|
||||
try {
|
||||
const data = JSON.parse(res.body);
|
||||
if (data.code === 200) {
|
||||
tooltip.log(`push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息完成。\n`)
|
||||
log.info('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息完成。`)
|
||||
} else {
|
||||
tooltip.log(`push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败:${data.msg}\n`)
|
||||
log.error('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败:${data.msg}`)
|
||||
}
|
||||
} catch (e) {
|
||||
tooltip.log(e);
|
||||
log.error('发送通知', e);
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
tooltip.log(`push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败!!\n`)
|
||||
log.error('发送通知', `push+发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败!!`)
|
||||
resolve();
|
||||
throw new Error(err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
tooltip.log('您未提供push+推送所需的PUSH_PLUS_TOKEN,取消push+推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供push+推送所需的PUSH_PLUS_TOKEN,取消push+推送消息通知');
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
@@ -679,15 +679,13 @@ async function email(text, desp) {
|
||||
text: desp,
|
||||
})
|
||||
} catch (e) {
|
||||
tooltip.log(`email发送失败 原因: ${e.message}`);
|
||||
log.error('发送通知', `email发送失败 原因: ${e.message}`);
|
||||
return
|
||||
}
|
||||
tooltip.log('email发送成功');
|
||||
log.info('发送通知', 'email发送成功');
|
||||
} else {
|
||||
tooltip.log('您未提供email推送所需的所有参数故取消email推送消息通知\n');
|
||||
log.debug('发送通知', '您未提供email推送所需的所有参数故取消email推送消息通知');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sendNotify
|
||||
}
|
||||
module.exports = { sendNotify }
|
||||
@@ -0,0 +1,27 @@
|
||||
const { isMe } = require('./check');
|
||||
const { clear } = require('./clear');
|
||||
const { start } = require('./lottery');
|
||||
const { update } = require('./update');
|
||||
const global_var = require('./data/global_var')
|
||||
const bili = require('./net/bili')
|
||||
const { log } = require('./utils')
|
||||
const { sendNotify } = require('./helper/notify');
|
||||
|
||||
/**
|
||||
* 检查cookie是否有效
|
||||
* @param {string} num
|
||||
*/
|
||||
async function checkCookie(num) {
|
||||
const My_UID = global_var.get("myUID");
|
||||
if (await bili.getMyinfo()) {
|
||||
log.info('Cookie有效性检测', `成功登录 UID:${My_UID}`);
|
||||
return true;
|
||||
} else {
|
||||
log.error('Cookie有效性检测', `登录失败 COOKIE${num} 已失效 UID:${My_UID}`);
|
||||
await sendNotify('动态抽奖出错-登录失败', `COOKIE${num} 已失效 UID:${My_UID}`)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { start, isMe, clear, update, checkCookie }
|
||||
@@ -1,169 +0,0 @@
|
||||
const Base = require('./Base');
|
||||
const BiliAPI = require('./BiliAPI');
|
||||
const GihubAPI = require("./GithubAPI");
|
||||
const eventBus = require('./eventBus');
|
||||
const GlobalVar = require('./GlobalVar');
|
||||
const Public = require('./Public');
|
||||
const Monitor = require('./Monitor');
|
||||
const { sendNotify } = require('./sendNotify');
|
||||
const config = require('./config');
|
||||
|
||||
/** Github运行限制时间*/
|
||||
const MAX_TIME = 6 * 60 * 60 * 1000 - 6 * 60 * 1000;
|
||||
|
||||
async function createRandomDynamic(num) {
|
||||
Base.tooltip.log(`准备创建${num}条随机动态`);
|
||||
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++) {
|
||||
await BiliAPI.createDynamic(Base.getRandomOne(config.dy_contents));
|
||||
await Base.delay(2000);
|
||||
}
|
||||
} else {
|
||||
Base.tooltip.log('已有非抽奖动态故无需创建');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主函数
|
||||
* @param {string} cookie
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function start() {
|
||||
return new Promise(resolve => {
|
||||
let times = Base.counter();
|
||||
/* 注册事件 */
|
||||
eventBus.on('Turn_on_the_Monitor', async () => {
|
||||
const lotterys = GlobalVar.get("Lottery");
|
||||
if (lotterys.length === 0) {
|
||||
Base.tooltip.log('抽奖信息为空');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
if (times.value() === lotterys.length) {
|
||||
await createRandomDynamic(config.create_dy_num);
|
||||
Base.tooltip.log('所有动态转发完毕');
|
||||
times.clear();
|
||||
eventBus.emit('Turn_off_the_Monitor', '目前无抽奖信息,过一会儿再来看看吧')
|
||||
return;
|
||||
}
|
||||
const lottery = lotterys[times.next()];
|
||||
const nlottery = Number(lottery);
|
||||
await (new Monitor(isNaN(nlottery) ? lottery : nlottery)).init();
|
||||
});
|
||||
eventBus.on('Turn_off_the_Monitor', async (msg) => {
|
||||
await createRandomDynamic(config.create_dy_num);
|
||||
Base.tooltip.log('[运行结束]程序自动关闭 原因: ' + msg);
|
||||
eventBus.flush();
|
||||
resolve();
|
||||
})
|
||||
if (process.env.LOCALLAUNCH) {
|
||||
eventBus.emit('Turn_on_the_Monitor');
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
eventBus.emit('Turn_off_the_Monitor', '运行时间超过Actions上限 - 6小时')
|
||||
}, MAX_TIME);
|
||||
GihubAPI.hasLotteryRun().then(s => {
|
||||
if (s) {
|
||||
Base.tooltip.log("有冲突的工作流故终止此任务");
|
||||
resolve()
|
||||
} else {
|
||||
eventBus.emit('Turn_on_the_Monitor');
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否中奖
|
||||
*/
|
||||
async function isMe() {
|
||||
let desp = '';
|
||||
const UnreadAtNum = await BiliAPI.getUnreadAtNum();
|
||||
const UnreadSessionNum = await BiliAPI.getUnreadSessionNum();
|
||||
const { follow_unread, unfollow_unread } = UnreadSessionNum || { unfollow_unread: 0, follow_unread: 0 };
|
||||
if (UnreadAtNum > 0) {
|
||||
Base.tooltip.log('<-- 正在检查at');
|
||||
const MyAtInfo = await BiliAPI.getMyAtInfo();
|
||||
MyAtInfo.forEach(async AtInfo => {
|
||||
const { at_time, up_uname, business, source_content, url } = AtInfo
|
||||
desp += `发生时间: ${Base.transformTimeZone(at_time * 1000, 8)} \n\n`
|
||||
desp += `用户: ${up_uname} \n\n`
|
||||
desp += `在${business}中@了你(${GlobalVar.get("myUID")}) \n\n`
|
||||
desp += `原内容为: ${source_content} \n\n`
|
||||
desp += `[直达链接](${url}) \n\n`
|
||||
desp += `\n\n\n\n`
|
||||
});
|
||||
Base.tooltip.log('--> OK');
|
||||
}
|
||||
if (follow_unread + unfollow_unread > 0) {
|
||||
const check = async (type) => {
|
||||
let session_t = '';
|
||||
let max = 0;
|
||||
let MySession = await BiliAPI.getSessionInfo(type)
|
||||
do {
|
||||
for (const Session of MySession.data) {
|
||||
const { content, sender_uid, session_ts, timestamp, talker_id } = Session;
|
||||
session_t = session_ts;
|
||||
if (talker_id) {
|
||||
BiliAPI.updateSessionStatus(talker_id);
|
||||
await Base.delay(1000);
|
||||
if (/中奖|获得|填写|写上|提供|地址|支付宝账号|码|大会员/.test(content)) {
|
||||
desp += `发生时间: ${Base.transformTimeZone(timestamp * 1000, 8)} \n\n`
|
||||
desp += `用户: ${sender_uid} \n\n`
|
||||
desp += `私信你(${GlobalVar.get("myUID")})说: ${content} \n\n`
|
||||
desp += `[直达链接](https://message.bilibili.com/#/whisper/mid${sender_uid}) \n\n`
|
||||
desp += `\n\n\n\n`
|
||||
}
|
||||
}
|
||||
}
|
||||
if (MySession.has_more) {
|
||||
await Base.delay(3e3);
|
||||
MySession = await BiliAPI.getSessionInfo(type, session_t)
|
||||
}
|
||||
max++
|
||||
} while (MySession.has_more && max < 10);
|
||||
}
|
||||
if (follow_unread) {
|
||||
Base.tooltip.log('<-- 正在检查已关注者的私信')
|
||||
await check(1)
|
||||
}
|
||||
if (unfollow_unread) {
|
||||
Base.tooltip.log('<-- 正在检查未关注者的私信')
|
||||
await check(2)
|
||||
}
|
||||
Base.tooltip.log('--> OK');
|
||||
}
|
||||
if (desp) {
|
||||
Base.tooltip.log(desp);
|
||||
await sendNotify('可能中奖了', desp);
|
||||
} else {
|
||||
Base.tooltip.log("未中奖");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查cookie是否有效
|
||||
* @param {string} num
|
||||
*/
|
||||
async function checkCookie(num) {
|
||||
if (await BiliAPI.getMyinfo()) {
|
||||
Base.tooltip.log('成功登录');
|
||||
return true;
|
||||
} else {
|
||||
Base.tooltip.log(`登录失败 COOKIE${num} 已失效 UID:${GlobalVar.get("myUID")}`);
|
||||
await sendNotify('动态抽奖出错-登录失败', `COOKIE${num} 已失效 UID:${GlobalVar.get("myUID")}`)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
start,
|
||||
isMe,
|
||||
checkCookie
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
const utils = require('./utils');
|
||||
const bili = require('./net/bili');
|
||||
const event_bus = require('./helper/event_bus');
|
||||
const global_var = require('./data/global_var');
|
||||
const { Searcher } = require('./core/searcher');
|
||||
const { Monitor } = require('./core/monitor');
|
||||
const config = require('./data/config');
|
||||
const { log } = utils;
|
||||
|
||||
async function createRandomDynamic(num) {
|
||||
if (config.create_dy) {
|
||||
log.info('随机动态', `准备创建${num}条随机动态`);
|
||||
const Dynamic = await Searcher.checkAllDynamic(global_var.get("myUID"), 1);
|
||||
if ((Dynamic.allModifyDynamicResArray[0] || { type: 0 }).type === 1) {
|
||||
for (let index = 0; index < num; index++) {
|
||||
await bili.createDynamic(utils.getRandomOne(config.dy_contents));
|
||||
await utils.delay(2000);
|
||||
}
|
||||
} else {
|
||||
log.info('随机动态', '已有非抽奖动态故无需创建');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖主函数
|
||||
* @param {string} cookie
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function start() {
|
||||
return new Promise(resolve => {
|
||||
let times = utils.counter();
|
||||
/* 注册事件 */
|
||||
event_bus.on('Turn_on_the_Monitor', async () => {
|
||||
const lotterys = global_var.get("Lottery");
|
||||
if (lotterys.length === 0) {
|
||||
log.info('抽奖', '抽奖信息为空');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
if (times.value() === lotterys.length) {
|
||||
await createRandomDynamic(config.create_dy_num);
|
||||
log.info('抽奖', '所有动态转发完毕');
|
||||
times.clear();
|
||||
event_bus.emit('Turn_off_the_Monitor', '目前无抽奖信息,过一会儿再来看看吧')
|
||||
return;
|
||||
}
|
||||
const lottery = lotterys[times.next()];
|
||||
|
||||
await (new Monitor(lottery)).init();
|
||||
});
|
||||
event_bus.on('Turn_off_the_Monitor', async (msg) => {
|
||||
await createRandomDynamic(config.create_dy_num);
|
||||
log.info('结束抽奖', '原因: ' + msg);
|
||||
event_bus.flush();
|
||||
resolve();
|
||||
})
|
||||
event_bus.emit('Turn_on_the_Monitor');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
module.exports = { start }
|
||||
@@ -0,0 +1,32 @@
|
||||
module.exports = Object.freeze({
|
||||
DYNAMIC_LIKE_THUMB: 'https://api.vc.bilibili.com/dynamic_like/v1/dynamic_like/thumb',
|
||||
DYNAMIC_REPOST_REPOST: 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/repost',
|
||||
DYNAMIC_SVR_CREATE_DRAW: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create_draw',
|
||||
DYNAMIC_SVR_CREATE: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/create',
|
||||
DYNAMIC_SVR_GET_DYNAMIC_DETAIL: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail',
|
||||
DYNAMIC_SVR_RM_DYNAMIC: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/rm_dynamic',
|
||||
DYNAMIC_SVR_SPACE_HISTORY: 'https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history',
|
||||
FEED_GET_ATTENTION_LIST: 'https://api.vc.bilibili.com/feed/v1/feed/get_attention_list',
|
||||
FEED_SETUSERFOLLOW: 'https://api.vc.bilibili.com/feed/v1/feed/SetUserFollow',
|
||||
LOTTERY_SVR_LOTTERY_NOTICE: 'https://api.vc.bilibili.com/lottery_svr/v1/lottery_svr/lottery_notice',
|
||||
MSGFEED_AT: 'https://api.bilibili.com/x/msgfeed/at',
|
||||
MSGFEED_UNREAD: 'https://api.bilibili.com/x/msgfeed/unread',
|
||||
READ_CV: 'https://www.bilibili.com/read/cv{{cv}}',
|
||||
RELATION_BATCH_MODIFY: 'https://api.bilibili.com/x/relation/batch/modify',
|
||||
RELATION_MODIFY: 'https://api.bilibili.com/x/relation/modify',
|
||||
RELATION_STAT: 'https://api.bilibili.com/x/relation/stat',
|
||||
RELATION_TAG_CREATE: 'https://api.bilibili.com/x/relation/tag/create',
|
||||
RELATION_TAG: 'https://api.bilibili.com/x/relation/tag',
|
||||
RELATION_TAGS_ADDUSERS: 'https://api.bilibili.com/x/relation/tags/addUsers',
|
||||
RELATION_TAGS: 'https://api.bilibili.com/x/relation/tags',
|
||||
REPLY_ADD: 'https://api.bilibili.com/x/v2/reply/add',
|
||||
SESSION_SVR_GET_SESSIONS: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/get_sessions',
|
||||
SESSION_SVR_SINGLE_UNREAD: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread',
|
||||
SESSION_SVR_UPDATE_ACK: 'https://api.vc.bilibili.com/session_svr/v1/session_svr/update_ack',
|
||||
SPACE_MYINFO: 'https://api.bilibili.com/x/space/myinfo',
|
||||
TAG_INFO: 'https://api.bilibili.com/x/tag/info',
|
||||
TOPIC_SVR_TOPIC_HISTORY: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_history',
|
||||
TOPIC_SVR_TOPIC_NEW: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new',
|
||||
WEB_INTERFACE_CARD: 'https://api.bilibili.com/x/web-interface/card',
|
||||
WEB_INTERFACE_SEARCH_TYPE: 'https://api.bilibili.com/x/web-interface/search/type',
|
||||
})
|
||||
+888
@@ -0,0 +1,888 @@
|
||||
const GlobalVar = require('../data/global_var');
|
||||
const { strToJson, log } = require('../utils');
|
||||
const { send } = require('./http');
|
||||
const API = require('./api.bili');
|
||||
|
||||
/**
|
||||
* GET请求
|
||||
* @param {import('./http').RequestOptions} param0
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
function get({ url, config, contents, query }) {
|
||||
return new Promise((resolve) => {
|
||||
send({
|
||||
url,
|
||||
method: 'GET',
|
||||
config,
|
||||
headers: {
|
||||
"accept": 'application/json, text/plain, */*',
|
||||
"cookie": GlobalVar.get("cookie")
|
||||
},
|
||||
query,
|
||||
contents,
|
||||
success: res => resolve(res.body),
|
||||
failure: err => resolve(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* POST请求
|
||||
* @param {import('./http').RequestOptions} param0
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
function post({ url, config, contents, query }) {
|
||||
return new Promise((resolve) => {
|
||||
send({
|
||||
url,
|
||||
method: 'POST',
|
||||
config,
|
||||
headers: {
|
||||
"accept": 'application/json, text/plain, */*',
|
||||
"content-type": 'application/x-www-form-urlencoded; charset=utf-8',
|
||||
"cookie": GlobalVar.get("cookie")
|
||||
},
|
||||
query,
|
||||
contents,
|
||||
success: res => resolve(res.body),
|
||||
failure: err => resolve(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 网络请求
|
||||
*/
|
||||
const bili_client = {
|
||||
/**
|
||||
* 判断是否成功登录
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async getMyinfo() {
|
||||
return get({
|
||||
url: API.SPACE_MYINFO
|
||||
}).then(responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取被at的信息
|
||||
* @typedef AtInfo
|
||||
* @property {number} at_time
|
||||
* @property {string} up_uname
|
||||
* @property {string} business
|
||||
* @property {string} source_content
|
||||
* @property {string} url
|
||||
* @returns {Promise<AtInfo[]>}
|
||||
*/
|
||||
async getMyAtInfo() {
|
||||
return get({
|
||||
url: API.MSGFEED_AT
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
const atInfo = [];
|
||||
if (res.code === 0) {
|
||||
const items = res.data.items;
|
||||
if (items.length !== 0) {
|
||||
items.forEach(i => {
|
||||
const { at_time, item, user } = i
|
||||
, { nickname: up_uname } = user
|
||||
, { business, uri: url, source_content } = item;
|
||||
atInfo.push({
|
||||
at_time,
|
||||
up_uname,
|
||||
business,
|
||||
source_content,
|
||||
url
|
||||
});
|
||||
});
|
||||
}
|
||||
return atInfo;
|
||||
} else {
|
||||
return atInfo;
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取未读@
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
async getUnreadAtNum() {
|
||||
return get({
|
||||
url: API.MSGFEED_UNREAD
|
||||
}).then(responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
const { at } = res.data;
|
||||
log.info('获取未读@', `成功 数量: ${at}`)
|
||||
return at
|
||||
} else {
|
||||
log.error('获取未读@', `失败\n${responseText}`)
|
||||
return -1
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取私信
|
||||
* @typedef SessionData
|
||||
* @property {string} session_ts
|
||||
* @property {string} content
|
||||
* @property {number} timestamp
|
||||
* @property {number} unread_count
|
||||
* @property {number} sender_uid
|
||||
* @property {number} talker_id
|
||||
* @property {number} msg_seqno
|
||||
*
|
||||
* @typedef SessionInfo
|
||||
* @property {number} has_more
|
||||
* @property {SessionData[]} data
|
||||
*
|
||||
* @param {number} session_type 1 已关注 2 未关注 3 应援团
|
||||
* @param {string} [ts_16]
|
||||
* @returns {Promise<SessionInfo>}
|
||||
*/
|
||||
async getSessionInfo(session_type, ts_16 = '') {
|
||||
return get({
|
||||
url: API.SESSION_SVR_GET_SESSIONS,
|
||||
query: {
|
||||
session_type,
|
||||
end_ts: ts_16,
|
||||
}
|
||||
}).then(responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
log.info('获取一页私信(20)', '成功 ' + (ts_16 ? 'end_ts->' + ts_16 : '第一页'));
|
||||
/**@type {Array} */
|
||||
const sessions = res.data.session_list || [];
|
||||
const has_more = res.data.has_more;
|
||||
const data = sessions.map(session => {
|
||||
const { session_ts, last_msg, unread_count, talker_id } = session;
|
||||
const { content = '', timestamp = 0, sender_uid = 0, msg_seqno } = last_msg || {};
|
||||
return { session_ts, content, timestamp, sender_uid, unread_count, talker_id, msg_seqno }
|
||||
})
|
||||
return { has_more, data }
|
||||
} else if (res.code === 2) {
|
||||
log.error('获取私信', `API抽风...请再次尝试`);
|
||||
return { has_more: 0, data: [] }
|
||||
} else {
|
||||
log.error('获取私信', `失败\n${responseText}`);
|
||||
return { has_more: 0, data: [] }
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取未读私信数量
|
||||
* @returns {Promise<{ unfollow_unread: number, follow_unread: number }>}
|
||||
*/
|
||||
async getUnreadSessionNum() {
|
||||
return get({
|
||||
url: API.SESSION_SVR_SINGLE_UNREAD
|
||||
}).then(responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
const { unfollow_unread = 0, follow_unread = 0 } = res.data;
|
||||
log.info('获取未读私信', `成功 已关注未读数: ${follow_unread}, 未关注未读数 ${unfollow_unread}`);
|
||||
return { unfollow_unread, follow_unread }
|
||||
} else {
|
||||
log.error('获取未读私信', `失败\n${responseText}`);
|
||||
return null
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 私信已读
|
||||
* @param {number} talker_id
|
||||
* @param {number} session_type
|
||||
* @param {number} msg_seqno
|
||||
*/
|
||||
updateSessionStatus(talker_id, session_type, msg_seqno) {
|
||||
return post({
|
||||
url: API.SESSION_SVR_UPDATE_ACK,
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
contents: {
|
||||
talker_id,
|
||||
session_type,
|
||||
ack_seqno: msg_seqno,
|
||||
csrf_token: GlobalVar.get("csrf"),
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
log.info('私信已读', `成功 -> talker_id: ${talker_id}`);
|
||||
} else {
|
||||
log.error('私信已读', `失败 -> talker_id: ${talker_id}\n${responseText}`);
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取关注列表
|
||||
* @param {number} uid
|
||||
* @returns {Promise<string | null>}
|
||||
*/
|
||||
getAttentionList(uid) {
|
||||
return get({
|
||||
url: API.FEED_GET_ATTENTION_LIST,
|
||||
query: {
|
||||
uid
|
||||
}
|
||||
}).then(responseText => {
|
||||
let res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
log.info('获取关注列表', '成功');
|
||||
return res.data.list.toString()
|
||||
} else {
|
||||
log.error('获取关注列表', `失败\n${responseText}`);
|
||||
return null
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取一个动态的细节
|
||||
* @param {string} dynamic_id
|
||||
* @return {Promise<JSON>} 失败返回undefined
|
||||
*/
|
||||
getOneDynamicByDyid(dynamic_id) {
|
||||
return get({
|
||||
url: API.DYNAMIC_SVR_GET_DYNAMIC_DETAIL,
|
||||
query: {
|
||||
dynamic_id
|
||||
}
|
||||
}).then(responseText => {
|
||||
const { code, data } = strToJson(responseText)
|
||||
, { card } = data || {};
|
||||
|
||||
if (code !== 0) {
|
||||
log.error('获取一个动态的细节', `获取动态(${dynamic_id})数据出错:\n${responseText}`)
|
||||
return
|
||||
}
|
||||
|
||||
if (!card) {
|
||||
log.warn('获取一个动态的细节', `动态(${dynamic_id})不存在`)
|
||||
return
|
||||
}
|
||||
|
||||
return card
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取一组动态的信息
|
||||
* @param {number} host_uid 被查看者的uid
|
||||
* @param {string} offset_dynamic_id 此动态偏移量 初始为 0
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getOneDynamicInfoByUID(host_uid, offset_dynamic_id) {
|
||||
/* 鉴别工作交由modifyDynamicRes完成 */
|
||||
return get({
|
||||
url: API.DYNAMIC_SVR_SPACE_HISTORY,
|
||||
query: {
|
||||
visitor_uid: GlobalVar.get("myUID"),
|
||||
host_uid,
|
||||
offset_dynamic_id,
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 通过tag名获取tag的id
|
||||
* @param {string} tag_name
|
||||
* tag名
|
||||
* @returns {Promise<number | -1>}
|
||||
* 正确:tag_ID
|
||||
* 错误:-1
|
||||
*/
|
||||
getTagIDByTagName(tag_name) {
|
||||
return get({
|
||||
url: API.TAG_INFO,
|
||||
query: {
|
||||
tag_name
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code !== 0) {
|
||||
log.error('获取TagID', '失败');
|
||||
return -1
|
||||
} else {
|
||||
return res.data.tag_id
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取tag下的热门动态以及一条最新动态
|
||||
* @param {number} tagid
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getHotDynamicInfoByTagID(tagid) {
|
||||
return get({
|
||||
url: API.TOPIC_SVR_TOPIC_NEW,
|
||||
query: {
|
||||
topic_id: tagid
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取tag下的最新动态
|
||||
* @param {string} tagname
|
||||
* @param {string} offset
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getOneDynamicInfoByTag(tagname, offset) {
|
||||
return get({
|
||||
url: API.TOPIC_SVR_TOPIC_HISTORY,
|
||||
query: {
|
||||
topic_name: tagname,
|
||||
offset_dynamic_id: offset
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 搜索专栏
|
||||
* @param {string} keyword
|
||||
* @return {Promise<Array<number>>}
|
||||
*/
|
||||
searchArticlesByKeyword(keyword) {
|
||||
return get({
|
||||
url: API.WEB_INTERFACE_SEARCH_TYPE,
|
||||
query: {
|
||||
keyword,
|
||||
page: 1,
|
||||
order: 'pubdate',
|
||||
search_type: 'article'
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = JSON.parse(responseText);
|
||||
if (res.code === 0) {
|
||||
let cv_arr = []
|
||||
try {
|
||||
log.info('搜索专栏', '成功 关键词: ' + keyword)
|
||||
cv_arr = res.data.result.map(it => it.id)
|
||||
} catch (error) {
|
||||
log.error('搜索专栏', '失败 原因:\n' + responseText)
|
||||
cv_arr = []
|
||||
}
|
||||
return cv_arr
|
||||
} else {
|
||||
log.error('搜索专栏', '失败 原因:\n' + responseText)
|
||||
return []
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取专栏内容
|
||||
* @param {number} cv
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
getOneArticleByCv(cv) {
|
||||
return get({
|
||||
url: API.READ_CV.replace('{{cv}}', cv)
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取粉丝数
|
||||
* @param {number} uid
|
||||
* @returns {Promise<number | -1>}
|
||||
*/
|
||||
getUserInfo(uid) {
|
||||
return get({
|
||||
url: API.WEB_INTERFACE_CARD,
|
||||
query: {
|
||||
mid: uid,
|
||||
photo: false
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
return res.data.follower
|
||||
} else {
|
||||
log.warn('获取粉丝数', '尝试切换线路');
|
||||
return get({
|
||||
url: API.RELATION_STAT,
|
||||
query: {
|
||||
vmid: uid
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
log.info('获取粉丝数', 'ok');
|
||||
return res.data.follower
|
||||
} else {
|
||||
log.error('获取粉丝数', `出错 可能是访问过频繁\n${responseText}`);
|
||||
return -1
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取开奖信息
|
||||
* @param {string} dyid
|
||||
* 动态id
|
||||
* @typedef LotteryNotice
|
||||
* @property {number | -1} ts
|
||||
* @property {string | "获取开奖信息失败"} text
|
||||
* @property {string | "null"} item
|
||||
* @property {string | "未知"} isMe
|
||||
* @returns {Promise<LotteryNotice>} 开奖时间
|
||||
*/
|
||||
getLotteryNotice(dyid) {
|
||||
return get({
|
||||
url: API.LOTTERY_SVR_LOTTERY_NOTICE,
|
||||
query: {
|
||||
dynamic_id: dyid
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
/(?<=_prize_cmt":").*(?=")/.exec();
|
||||
if (res.code === 0) {
|
||||
const timestamp10 = res.data.lottery_time,
|
||||
timestamp13 = timestamp10 * 1000,
|
||||
time = new Date(timestamp13);
|
||||
const remain = (() => {
|
||||
const timestr = ((timestamp13 - Date.now()) / 86400000).toString(),
|
||||
timearr = timestr.replace(/(\d+)\.(\d+)/, "$1,0.$2").split(',');
|
||||
const text = timearr[0][0] === '-' ? `开奖时间已过${timearr[0].substring(1)}天余${parseInt(timearr[1] * 24)}小时` : `还有${timearr[0]}天余${parseInt(timearr[1] * 24)}小时`;
|
||||
return text;
|
||||
})();
|
||||
let isMeB = (new RegExp(GlobalVar.get("myUID"))).test(responseText);
|
||||
const isMe = isMeB ? '中奖了!!!' : '未中奖';
|
||||
const iteminfo = res.data.first_prize_cmt || '' + ' ' + res.data.second_prize_cmt || '' + ' ' + res.data.third_prize_cmt || '';
|
||||
return {
|
||||
ts: timestamp10,
|
||||
text: `开奖时间: ${time.toLocaleString()} ${remain}`,
|
||||
item: iteminfo,
|
||||
isMe: isMe
|
||||
};
|
||||
} else {
|
||||
log.error('获取开奖信息', `失败\n${responseText}`);
|
||||
return {
|
||||
ts: -1,
|
||||
text: '获取开奖信息失败',
|
||||
item: 'null',
|
||||
isMe: '未知'
|
||||
};
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 之前不检查是否重复关注
|
||||
* 自动关注
|
||||
* 并转移分组
|
||||
* @param {Number} uid
|
||||
* 被关注者的UID
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
* 2 - 异常
|
||||
*/
|
||||
autoAttention(uid) {
|
||||
return post({
|
||||
url: API.RELATION_MODIFY,
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
contents: {
|
||||
fid: uid,
|
||||
act: 1,
|
||||
re_src: 0,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
let _responseText = ''
|
||||
/* 重复关注code also equal 0 */
|
||||
const res = strToJson(responseText)
|
||||
_responseText += responseText
|
||||
if (res.code === 0) {
|
||||
log.info('自动关注', '关注+1');
|
||||
return 0
|
||||
} else if (res.code === 22002) {
|
||||
log.error('自动关注', '您已被对方拉入黑名单');
|
||||
return 1
|
||||
} else {
|
||||
log.warn('自动关注', `失败 尝试切换线路\n${responseText}`);
|
||||
_responseText += responseText
|
||||
return post({
|
||||
url: API.FEED_SETUSERFOLLOW,
|
||||
contents: {
|
||||
type: 1,
|
||||
follow: uid,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('自动关注', '关注+1');
|
||||
return 0
|
||||
} else {
|
||||
log.warn('自动关注', `失败 尝试切换另一条线路\n${responseText}`);
|
||||
_responseText += responseText
|
||||
return post({
|
||||
url: API.RELATION_BATCH_MODIFY,
|
||||
contents: {
|
||||
fid: uid,
|
||||
act: 1,
|
||||
re_src: 0,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('自动关注', '关注+1');
|
||||
return 0
|
||||
} else {
|
||||
log.error('自动关注', `失败\n${responseText}`);
|
||||
_responseText += responseText
|
||||
if (_responseText.includes(22015)) {
|
||||
return 2
|
||||
}
|
||||
return 1
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 移动分区
|
||||
* @param {number} uid
|
||||
* @param {number} tagid 关注分区的ID
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
*/
|
||||
movePartition(uid, tagid) {
|
||||
return post({
|
||||
url: API.RELATION_TAGS_ADDUSERS,
|
||||
contents: {
|
||||
fids: uid,
|
||||
tagids: tagid,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
/* 重复移动code also equal 0 */
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('移动分区', 'up主分区移动成功');
|
||||
return 0
|
||||
} else {
|
||||
log.error('移动分区', `up主分区移动失败\n${responseText}`);
|
||||
return 1
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 取消关注
|
||||
* @param {number} uid
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
cancelAttention(uid) {
|
||||
return post({
|
||||
url: API.RELATION_MODIFY,
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
contents: {
|
||||
fid: uid,
|
||||
act: 2,
|
||||
re_src: 0,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
log.info('自动取关', `取关成功(${uid})`);
|
||||
return true
|
||||
} else {
|
||||
log.error('自动取关', `取关失败(${uid})\n${responseText}`);
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 动态自动点赞
|
||||
* @param {string} dyid
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
*/
|
||||
autolike(dyid) {
|
||||
return post({
|
||||
url: API.DYNAMIC_LIKE_THUMB,
|
||||
contents: {
|
||||
uid: GlobalVar.get("myUID"),
|
||||
dynamic_id: dyid,
|
||||
up: 1,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('自动点赞', '点赞成功');
|
||||
return 0
|
||||
} else {
|
||||
log.error('自动点赞', `点赞失败\n${responseText}`);
|
||||
return 1
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 转发前应查看是否重复转发
|
||||
* 自动转发
|
||||
* @param {Number} uid
|
||||
* 自己的UID
|
||||
* @param {string} dyid
|
||||
* @param {string} [msg]
|
||||
* 动态的ID
|
||||
* @returns {Promise<number>}
|
||||
* 0 - 成功
|
||||
* 1 - 失败
|
||||
*/
|
||||
autoRelay(uid, dyid, msg = '转发动态', ctrl = '[]') {
|
||||
const len = msg.length;
|
||||
if (len > 233) {
|
||||
msg = msg.slice(0, 233 - len)
|
||||
}
|
||||
return post({
|
||||
url: API.DYNAMIC_REPOST_REPOST,
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
contents: {
|
||||
uid: `${uid}`,
|
||||
dynamic_id: dyid,
|
||||
content: msg,
|
||||
ctrl,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('转发动态', '成功转发一条动态');
|
||||
return 0
|
||||
} else {
|
||||
log.error('转发动态', `转发动态失败\n${responseText}`);
|
||||
return 1
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @typedef Picture
|
||||
* @property {string} img_src
|
||||
* @property {number} img_width
|
||||
* @property {number} img_height
|
||||
* 发布一条动态
|
||||
* @param { string | Picture[] } content
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
createDynamic(content) {
|
||||
let contents = {
|
||||
csrf: GlobalVar.get("csrf"),
|
||||
extension: '{"emoji_type":1,"from":{"emoji_type":1},"flag_cfg":{}}'
|
||||
}
|
||||
let url = '';
|
||||
if (content instanceof Array) {
|
||||
url = API.DYNAMIC_SVR_CREATE_DRAW
|
||||
contents = {
|
||||
...contents,
|
||||
biz: 3,
|
||||
category: 3,
|
||||
pictures: JSON.stringify(content)
|
||||
}
|
||||
} else {
|
||||
url = API.DYNAMIC_SVR_CREATE
|
||||
contents = {
|
||||
...contents,
|
||||
content,
|
||||
}
|
||||
}
|
||||
return post({
|
||||
url,
|
||||
contents,
|
||||
}).then(responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('发布动态', '成功创建一条随机内容的动态');
|
||||
} else {
|
||||
log.error('发布动态', `发布动态失败\n${responseText}`);
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 移除动态
|
||||
* @param {string} dyid
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
rmDynamic(dyid) {
|
||||
return post({
|
||||
url: API.DYNAMIC_SVR_RM_DYNAMIC,
|
||||
contents: {
|
||||
dynamic_id: dyid,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
}
|
||||
}).then(responseText => {
|
||||
if (/^{"code":0/.test(responseText)) {
|
||||
log.info('删除动态', `成功删除一条动态(${dyid})`);
|
||||
return true
|
||||
} else {
|
||||
log.error('删除动态', `删除动态失败(${dyid})\n${responseText}`);
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 发送评论
|
||||
* @param {string} rid
|
||||
* cid_str
|
||||
* @param {string} msg
|
||||
* @param {number} type
|
||||
* 1(视频)
|
||||
* 11(有图)
|
||||
* 17(无图)
|
||||
* @returns {Promise<number>}
|
||||
* - 成功 0
|
||||
* - 失败 1
|
||||
* - 黑名单 -1
|
||||
*/
|
||||
sendChat(rid, msg, type, show = true) {
|
||||
return post({
|
||||
url: API.REPLY_ADD,
|
||||
contents: {
|
||||
oid: rid,
|
||||
type: type,
|
||||
message: msg,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
if (res.code === 0) {
|
||||
show && log.info('自动评论', '评论成功');
|
||||
return 0
|
||||
} else if (res.code === -404) {
|
||||
show && log.error('自动评论', '原动态已删除');
|
||||
return 0
|
||||
} else if (res.code === 12002) {
|
||||
show && log.error('自动评论', '评论区已关闭');
|
||||
return 0
|
||||
} else if (res.code === 12015) {
|
||||
show && log.error('自动评论', '需要输入验证码');
|
||||
return 1
|
||||
} else if (res.code === 12035) {
|
||||
show && log.error('自动评论', `已被对方拉入黑名单`);
|
||||
return -1
|
||||
} else if (res.code === 12053) {
|
||||
show && log.error('自动评论', '黑名单用户无法互动');
|
||||
return -1
|
||||
} else {
|
||||
show && log.error('自动评论', `评论失败\n${responseText}`);
|
||||
return 1
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 检查分区
|
||||
* 不存在指定分区时创建
|
||||
* 获取到tagid添加为对象的属性
|
||||
* @param {string} [name]
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
checkMyPartition(name) {
|
||||
if (!name) name = '此处存放因抽奖临时关注的up';
|
||||
return get({
|
||||
url: API.RELATION_TAGS
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
let tagid = undefined;
|
||||
if (res.code === 0) {
|
||||
const data = res.data.filter((it) => it.name === name);
|
||||
if (data.length) {
|
||||
log.info('获取分区id', '成功');
|
||||
tagid = data[0].tagid
|
||||
} else {
|
||||
log.warn('获取分区id', '失败 无指定分区');
|
||||
}
|
||||
if (name === '此处存放因抽奖临时关注的up') {
|
||||
if (typeof tagid === 'undefined') {
|
||||
return bili_client.createPartition(name)
|
||||
} else {
|
||||
return tagid
|
||||
}
|
||||
} else {
|
||||
return tagid
|
||||
}
|
||||
} else {
|
||||
log.error('获取分区id', `访问出错 可在my_config里手动填入\n${responseText}`)
|
||||
return tagid
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 创造分区
|
||||
* @param {string} partition_name
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
createPartition(partition_name) {
|
||||
return post({
|
||||
url: API.RELATION_TAG_CREATE,
|
||||
contents: {
|
||||
tag: partition_name,
|
||||
csrf: GlobalVar.get("csrf")
|
||||
}
|
||||
}).then(responseText => {
|
||||
let obj = strToJson(responseText);
|
||||
if (obj.code === 0) {
|
||||
log.info('新建分区', '分区新建成功')
|
||||
/* 获取tagid */
|
||||
let { tagid } = obj.data
|
||||
return tagid
|
||||
} else {
|
||||
log.error('新建分区', `分区新建失败\n${responseText}`);
|
||||
return undefined
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 获取一个分区中50个的id
|
||||
* @param {number} tagid
|
||||
* @param {number} n 1->
|
||||
* @returns {Promise<number[]>}
|
||||
*/
|
||||
getPartitionUID(tagid, n) {
|
||||
return get({
|
||||
url: API.RELATION_TAG,
|
||||
query: {
|
||||
mid: GlobalVar.get("myUID"),
|
||||
tagid: tagid,
|
||||
pn: n,
|
||||
ps: 50
|
||||
}
|
||||
}).then(responseText => {
|
||||
const res = strToJson(responseText);
|
||||
let uids = [];
|
||||
if (res.code === 0) {
|
||||
res.data.forEach(d => {
|
||||
uids.push(d.mid);
|
||||
})
|
||||
log.info(`获取分组${tagid}`, `成功获取取关分区列表${n}`);
|
||||
return uids
|
||||
} else {
|
||||
log.error(`获取分组${tagid}`, `获取取关分区列表失败\n${responseText}`);
|
||||
return uids
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = bili_client
|
||||
@@ -14,11 +14,6 @@
|
||||
* @param {string} err
|
||||
* @returns {void}
|
||||
*
|
||||
* @typedef Proxy
|
||||
* @property {string} hostname
|
||||
* @property {string} [host]
|
||||
* @property {number} port
|
||||
*
|
||||
* @typedef RequestConfig
|
||||
* @property {number} [timeout] 超时
|
||||
* @property {number} [wait] 错误等待
|
||||
@@ -27,16 +22,16 @@
|
||||
* @property {number} [retry_times] 重试次数
|
||||
*
|
||||
* @typedef {object} RequestOptions Http请求选项
|
||||
* @property {string} method 请求方法
|
||||
* @property {string} [method] 请求方法
|
||||
* @property {string} url 完整链接
|
||||
* @property {boolean} stream 是否流式数据
|
||||
* @property {boolean} [stream] 是否流式数据
|
||||
* @property {RequestConfig} [config] 设置
|
||||
* @property {Proxy} [proxy] 代理
|
||||
* @property {string} [proxy] 代理 IP:PORT
|
||||
* @property {Object.<string, string|number>} [query] 查询选项
|
||||
* @property {Object.<string, string|number> | string} [contents] 内容
|
||||
* @property {HttpHeaders} [headers] 请求头
|
||||
* @property {SuccessCb} success 成功回调
|
||||
* @property {FailureCb} failure 失败回调
|
||||
* @property {SuccessCb} [success] 成功回调
|
||||
* @property {FailureCb} [failure] 失败回调
|
||||
*/
|
||||
|
||||
const { request: http_request } = require('http');
|
||||
@@ -64,7 +59,7 @@ const DEFAULT_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
* @param {RequestOptions} detail
|
||||
* @returns {void}
|
||||
*/
|
||||
function HttpRequest(detail) {
|
||||
function send(detail) {
|
||||
detail = setDefault(detail);
|
||||
const { method, url, stream, config, proxy, query, contents, headers, success, failure } = detail;
|
||||
const { timeout, wait, retry, redirect, retry_times } = config;
|
||||
@@ -86,9 +81,8 @@ function HttpRequest(detail) {
|
||||
}
|
||||
if (proxy) {
|
||||
options.headers.host = thisURL.host;
|
||||
[options.hostname, options.port] = proxy.host ?
|
||||
proxy.host.split(':') : [proxy.hostname, proxy.port]
|
||||
options.path = thisURL.href;
|
||||
[options.hostname, options.port] = proxy.split(':');
|
||||
}
|
||||
const req = request(options, res => {
|
||||
let protodata = '';
|
||||
@@ -100,7 +94,7 @@ function HttpRequest(detail) {
|
||||
detail.url = new URL(thisURL.origin + headers.location).href
|
||||
}
|
||||
console.log(`[重定向]状态码:${statusCode} location:${detail.url}`);
|
||||
HttpRequest(detail)
|
||||
send(detail)
|
||||
return
|
||||
}
|
||||
if (stream) {
|
||||
@@ -113,7 +107,7 @@ function HttpRequest(detail) {
|
||||
console.log(`[不期待响应]原因:${err.message} 尝试重新请求中...`);
|
||||
await delay(wait);
|
||||
detail.config.retry_times = retry_times - 1;
|
||||
HttpRequest(detail);
|
||||
send(detail);
|
||||
} else {
|
||||
failure(`[响应错误]${err.message} 响应数据:\n${protodata}`)
|
||||
}
|
||||
@@ -132,7 +126,7 @@ function HttpRequest(detail) {
|
||||
console.log(`[请求失败]原因:${err.message} 尝试重新连接中...`);
|
||||
await delay(wait);
|
||||
detail.config.retry_times = retry_times - 1;
|
||||
HttpRequest(detail);
|
||||
send(detail);
|
||||
} else {
|
||||
failure(`[请求失败]: ${err.message}`);
|
||||
}
|
||||
@@ -157,12 +151,17 @@ function formatContents(type, contents) {
|
||||
|
||||
/**
|
||||
* 设置默认
|
||||
* @param {RequestOptions} detail
|
||||
* @param {RequestOptions} detail
|
||||
* @returns {RequestOptions}
|
||||
*/
|
||||
function setDefault(detail) {
|
||||
detail = {
|
||||
method: 'GET',
|
||||
stream: false,
|
||||
proxy: '',
|
||||
headers: {},
|
||||
success: (res) => { console.log(res.headers) },
|
||||
failure: (err) => { console.log(err) },
|
||||
...detail
|
||||
}
|
||||
detail.config = {
|
||||
@@ -190,4 +189,4 @@ function delay(time) {
|
||||
}
|
||||
|
||||
|
||||
module.exports = { HttpRequest }
|
||||
module.exports = { send }
|
||||
@@ -1,39 +0,0 @@
|
||||
const Base = require("./Base");
|
||||
const GlobalVar = require("./GlobalVar");
|
||||
const MyStorage = require("./MyStorage");
|
||||
const config = require("./config");
|
||||
|
||||
const key_map = new Map([['DedeUserID', 'myUID'], ['bili_jct', 'csrf']]);
|
||||
|
||||
/**
|
||||
* 生成全局变量文件
|
||||
* @param {string} cookie
|
||||
* @param {number} n
|
||||
*/
|
||||
async function setVariable(cookie, n) {
|
||||
if (cookie) {
|
||||
config.updata(process.env.NUMBER);
|
||||
|
||||
GlobalVar.set('cookie', cookie);
|
||||
cookie.split(/\s*;\s*/).forEach(item => {
|
||||
const _item = item.split('=');
|
||||
if (key_map.has(_item[0]))
|
||||
GlobalVar.set(key_map.get(_item[0]), _item[1]);
|
||||
});
|
||||
GlobalVar.set('Lottery', [...config.UIDs, ...config.TAGs]);
|
||||
GlobalVar.set('remoteconfig', await Base.getRemoteConfig());
|
||||
}
|
||||
await Base.createDir('dyids');
|
||||
if (process.env.PAT) {
|
||||
if (process.env.CI) {
|
||||
process.env.NUMBER = 1;
|
||||
}
|
||||
await MyStorage.init()
|
||||
} else {
|
||||
await Base.createFile(n < 2 ? 'dyid.txt' : `dyid${n}.txt`, '', 'a')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
module.exports = { setVariable };
|
||||
@@ -0,0 +1,84 @@
|
||||
const { send } = require('./net/http')
|
||||
const { strToJson, download } = require('./utils')
|
||||
const { version, checkVersion, log } = require('./utils')
|
||||
|
||||
/**
|
||||
* 获取下载链接
|
||||
* @param {string} owner
|
||||
* @param {string} repo
|
||||
* @returns {Promise<{ download_url: string, text: string }>}
|
||||
*/
|
||||
function getLatestReleaseDownloadUrl(owner, repo) {
|
||||
return new Promise((resolve, reject) => {
|
||||
send({
|
||||
url: `https://api.github.com/repos/${owner}/${repo}/releases/latest`,
|
||||
headers: {
|
||||
"accept": 'application/vnd.github.v3+json'
|
||||
},
|
||||
config: {
|
||||
retry: false
|
||||
},
|
||||
success: ({ body }) => {
|
||||
const { tag_name, assets, body: text } = strToJson(body)
|
||||
if (tag_name) {
|
||||
if (checkVersion(version) < checkVersion(tag_name)) {
|
||||
const platform = new Map([
|
||||
['win32', 'win'],
|
||||
['linux', 'linux'],
|
||||
['darwin', 'macos']
|
||||
]).get(process.platform)
|
||||
const arch = new Map([
|
||||
['x64', 'x64'],
|
||||
['arm', 'armv7'],
|
||||
['arm64', 'arm64']
|
||||
]).get(process.arch)
|
||||
if (platform && arch) {
|
||||
try {
|
||||
const download_url = assets
|
||||
.filter(({ name }) => name.includes(platform) && name.includes(arch))
|
||||
.map(({ browser_download_url }) => browser_download_url)[0]
|
||||
if (!download_url) {
|
||||
reject(`未找到能在此平台(${process.platform})-(${process.arch})上运行的版本`)
|
||||
}
|
||||
resolve({ download_url, text })
|
||||
} catch (err) {
|
||||
reject(err)
|
||||
}
|
||||
} else {
|
||||
reject(`未找到能在此平台(${process.platform})-(${process.arch})上运行的版本`)
|
||||
}
|
||||
} else {
|
||||
reject('当前已是最新版本')
|
||||
}
|
||||
} else {
|
||||
reject(body)
|
||||
}
|
||||
},
|
||||
failure: error => {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 半自动更新
|
||||
*/
|
||||
async function update() {
|
||||
try {
|
||||
const { download_url, text } = await getLatestReleaseDownloadUrl('shanmiteko', 'LotteryAutoScript')
|
||||
|
||||
let proxy_url = new URL(download_url)
|
||||
proxy_url.host = 'download.fastgit.org'
|
||||
|
||||
await download(proxy_url.href, 'latest_version.zip')
|
||||
|
||||
log.info('自动下载', '成功下载到当前目录')
|
||||
log.info('更新说明', '\n' + text + '\n')
|
||||
} catch (error) {
|
||||
log.error('更新脚本', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { update }
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { send } = require("./net/http");
|
||||
const { version } = require('../package.json');
|
||||
|
||||
/**
|
||||
* 基础工具
|
||||
*/
|
||||
const utils = {
|
||||
version,
|
||||
/**环境变量设置文件 */
|
||||
env_file: path.join(process.cwd(), "env.js"),
|
||||
/**配置文件 */
|
||||
config_file: path.join(process.cwd(), "my_config.js"),
|
||||
/**dyid长度 */
|
||||
dyid_length: 18,
|
||||
/**
|
||||
* 将版本号转为数字
|
||||
* @example
|
||||
* 1.2.3 => 1.0203
|
||||
* @param {string} version
|
||||
* @returns {Number}
|
||||
*/
|
||||
checkVersion(version) {
|
||||
return (version.match(/\d.*/)[0]).split('.').reduce((a, v, i) => a + (0.01 ** i) * Number(v), 0)
|
||||
},
|
||||
/**
|
||||
* 安全的将JSON字符串转为对象
|
||||
* 超出精度的数转为字符串
|
||||
* @param {string} params
|
||||
* @return {object}
|
||||
* 返回对象 解析失败返回 `{}`
|
||||
*/
|
||||
strToJson(params) {
|
||||
const isJSON = (str => {
|
||||
if (typeof str === 'string') {
|
||||
try {
|
||||
const obj = JSON.parse(str);
|
||||
return typeof obj === 'object' ? obj : false
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
})(params);
|
||||
return isJSON ? isJSON : {}
|
||||
},
|
||||
/**
|
||||
* @template T
|
||||
* @param {Array<T>} iter
|
||||
* @param {(value: T) => Promise<Boolean>} fn 返回true整体退出
|
||||
*/
|
||||
async try_for_each(iter, fn) {
|
||||
for (const item of iter) {
|
||||
if (await fn(item)) break
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 函数柯里化
|
||||
* @template T
|
||||
* @param {(arg, arg) => T} func
|
||||
* 要被柯里化的函数
|
||||
* @returns {(arg) => (arg) => T)}
|
||||
* 一次接受一个参数并返回一个接受余下参数的函数
|
||||
*/
|
||||
curryify(func) {
|
||||
function _c(restNum, argsList) {
|
||||
return restNum === 0 ?
|
||||
func.apply(null, argsList) :
|
||||
function (x) {
|
||||
return _c(restNum - 1, argsList.concat(x));
|
||||
};
|
||||
}
|
||||
return _c(func.length, []);
|
||||
},
|
||||
/**
|
||||
* 延时函数
|
||||
* @param {number} time ms
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
delay(time) {
|
||||
utils.log.info('时延', `${~~time}ms`);
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, time);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 计数器 0..Infinity
|
||||
* @typedef Counter
|
||||
* @property {()=>Number} next
|
||||
* @property {()=>boolean} clear
|
||||
* @property {()=>Number} value
|
||||
* @returns {Counter}
|
||||
*/
|
||||
counter() {
|
||||
let c = {
|
||||
i: 0,
|
||||
next: () => c.i++,
|
||||
clear: () => { c.i = 0 },
|
||||
value: () => c.i
|
||||
}
|
||||
return c
|
||||
},
|
||||
/**
|
||||
* 无限序列
|
||||
* `[0..]`
|
||||
*/
|
||||
*infiniteNumber() {
|
||||
for (let index = 0; ; index++) {
|
||||
yield index
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 随机获取数组中的一个元素
|
||||
* @template T
|
||||
* @param {T[]} arr
|
||||
* @returns {T}
|
||||
*/
|
||||
getRandomOne(arr) {
|
||||
let RandomOne = null;
|
||||
if (Array.isArray(arr) && arr.length) {
|
||||
RandomOne = arr[parseInt(Math.random() * arr.length)];
|
||||
}
|
||||
return RandomOne
|
||||
},
|
||||
/**
|
||||
* Fisher–Yates shuffle洗牌
|
||||
* @template T
|
||||
* @param {Array<T>} array
|
||||
* @return {Array<T>}
|
||||
*/
|
||||
shuffle(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
return array;
|
||||
},
|
||||
/**
|
||||
* 关键词判断
|
||||
* @param {string} text
|
||||
* @param {string[]} key_words startwith '~' 表示黑名单
|
||||
* @return {boolean}
|
||||
*/
|
||||
judge(text, key_words) {
|
||||
return key_words.reduce((acc, word) => {
|
||||
word.startsWith('~')
|
||||
? RegExp(word.slice(1)).test(text) && (acc = false)
|
||||
: RegExp(word).test(text) && (acc = true)
|
||||
return acc
|
||||
}, false)
|
||||
},
|
||||
/**
|
||||
* 是否有指定环境变量
|
||||
* @param {string} env_name
|
||||
* @returns
|
||||
*/
|
||||
hasEnv(env_name) {
|
||||
return process.env[env_name] ? true : false;
|
||||
},
|
||||
/**日志 */
|
||||
log: {
|
||||
level: 3,
|
||||
/**
|
||||
* 初始化默认level为3
|
||||
*/
|
||||
init() {
|
||||
let _level = Number(process.env.LOTTERY_LOG_LEVEL);
|
||||
this.level = isNaN(_level) ? 3 : _level;
|
||||
},
|
||||
/**
|
||||
* @param {String|Array<String>} msg
|
||||
* @param {String} [split] 分隔符
|
||||
*/
|
||||
proPrint(msg, split = ' ') {
|
||||
console.log([msg].flat().join(split))
|
||||
},
|
||||
debug(context, msg) {
|
||||
if (this.level > 3) {
|
||||
if (msg instanceof Object) msg = JSON.stringify(msg, null, 4);
|
||||
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Debug]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#0070BB')(`[\n${msg}\n]`)])
|
||||
}
|
||||
},
|
||||
info(context, msg) {
|
||||
if (this.level > 2)
|
||||
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Info]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#48BB31')(`[${msg}]`)])
|
||||
},
|
||||
warn(context, msg) {
|
||||
if (this.level > 1)
|
||||
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Warn]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#BBBB23')(`[\n${msg}\n]`)])
|
||||
},
|
||||
error(context, msg) {
|
||||
if (this.level > 0)
|
||||
this.proPrint([chalk.hex('#64B3FF')(`[${new Date(Date.now() + 288e5).toISOString()}]`), chalk.grey("[Error]"), chalk.hex('#FFA500')(`[${context}]`), chalk.hex('#FF0006')(`[\n${msg}\n]`)])
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 下载文件
|
||||
* @param {string} url
|
||||
* @param {string} file_name
|
||||
* @returns {Promise<void | string>}
|
||||
*/
|
||||
download(url, file_name) {
|
||||
return new Promise((resolve, reject) => {
|
||||
send({
|
||||
url,
|
||||
stream: true,
|
||||
config: {
|
||||
redirect: true,
|
||||
retry: false
|
||||
},
|
||||
success: ({ resStream }) => {
|
||||
let recv_length = 0;
|
||||
const wtbs = fs.createWriteStream(file_name);
|
||||
resStream.on('data', chuck => {
|
||||
recv_length += chuck.length
|
||||
utils.log.proPrint(`已收到:${recv_length} Bytes`)
|
||||
})
|
||||
resStream.pipe(wtbs)
|
||||
wtbs.on('finish', () => {
|
||||
utils.log.proPrint('下载完成')
|
||||
resolve()
|
||||
}).on('error', error => {
|
||||
wtbs.destroy()
|
||||
resolve(error)
|
||||
})
|
||||
},
|
||||
failure: error => {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取远程设置
|
||||
* @returns {Promise<JSON>}
|
||||
*/
|
||||
getRemoteConfig() {
|
||||
return new Promise((resolve) => {
|
||||
send({
|
||||
method: 'GET',
|
||||
url: 'https://gitee.com/shanmite/lottery-notice/raw/master/notice.json',
|
||||
headers: {
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
|
||||
accept: 'text/plain; charset=utf-8',
|
||||
referer: 'https://gitee.com/shanmite/lottery-notice/blob/master/notice.json',
|
||||
},
|
||||
success: res => {
|
||||
try {
|
||||
const body = JSON.parse(res.body);
|
||||
if (body.node_msg) utils.log.info('公告', '\n' + body.node_msg + '\n');
|
||||
resolve(body.config)
|
||||
} catch (error) {
|
||||
resolve(JSON.parse('{}'))
|
||||
}
|
||||
},
|
||||
failure: err => {
|
||||
utils.log.error('获取远程设置', '获取远程设置错误: ' + err);
|
||||
resolve(JSON.parse('{}'));
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 是否存在文件或目录
|
||||
* @param {string} path
|
||||
* @returns
|
||||
*/
|
||||
hasFileOrDir(path) {
|
||||
try {
|
||||
fs.accessSync(path, fs.constants.F_OK)
|
||||
} catch (_) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
/**
|
||||
* 生成文件夹
|
||||
* @param {string} dirname
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
createDir(dirname) {
|
||||
return new Promise((resolve) => {
|
||||
fs.stat(dirname, (err) => {
|
||||
if (err) {
|
||||
fs.mkdirSync(dirname)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = utils;
|
||||
@@ -1,90 +1,168 @@
|
||||
const { env_file, tooltip, delay } = require("./lib/Base");
|
||||
const { version: ve, env_file, config_file, log, hasEnv, delay, hasFileOrDir } = require("./lib/utils");
|
||||
|
||||
const metainfo = [
|
||||
` _ _ _ _____ _ _ `,
|
||||
` | | | | | | / ____| (_) | | `,
|
||||
` | | ___ | |_| |_ ___ _ __ _ _| (___ ___ _ __ _ _ __ | |_ `,
|
||||
` | | / _ \\| __| __/ _ \\ '__| | | |\\___ \\ / __| '__| | '_ \\| __|`,
|
||||
` | |___| (_) | |_| || __/ | | |_| |____) | (__| | | | |_) | |_ `,
|
||||
` |______\\___/ \\__|\\__\\___|_| \\__, |_____/ \\___|_| |_| .__/ \\__|`,
|
||||
` __/ | | | `,
|
||||
` |___/ |_| `,
|
||||
` `,
|
||||
` Verison: v${ve}`,
|
||||
` Written By shanmite`,
|
||||
]
|
||||
/**多账号存储 */
|
||||
let multiple_account = [];
|
||||
/**循环等待时间 */
|
||||
let loop_wait = 0;
|
||||
|
||||
if (!process.env.CI) {
|
||||
const { initEnv, multiple_account_parm } = require(env_file);
|
||||
if (multiple_account_parm) {
|
||||
multiple_account = multiple_account_parm;
|
||||
}
|
||||
initEnv()
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<string>} 错误信息
|
||||
*/
|
||||
async function main() {
|
||||
const { COOKIE, NUMBER, CLEAR, PAT, LOCALLAUNCH, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT } = process.env;
|
||||
if (LOCALLAUNCH || PAT) {
|
||||
if (ENABLE_MULTIPLE_ACCOUNT) {
|
||||
let muti_acco = multiple_account.length
|
||||
? multiple_account
|
||||
: JSON.parse(MULTIPLE_ACCOUNT);
|
||||
const { COOKIE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env;
|
||||
if (ENABLE_MULTIPLE_ACCOUNT) {
|
||||
let muti_acco = multiple_account.length
|
||||
? multiple_account
|
||||
: JSON.parse(MULTIPLE_ACCOUNT_PARM);
|
||||
|
||||
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
|
||||
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
|
||||
|
||||
for (const acco of muti_acco) {
|
||||
process.env.COOKIE = acco.COOKIE;
|
||||
process.env.NUMBER = acco.NUMBER;
|
||||
process.env.CLEAR = acco.CLEAR;
|
||||
await main();
|
||||
for (const acco of muti_acco) {
|
||||
process.env.COOKIE = acco.COOKIE;
|
||||
process.env.NUMBER = acco.NUMBER;
|
||||
process.env.CLEAR = acco.CLEAR;
|
||||
const err_msg = await main();
|
||||
if (err_msg) {
|
||||
return err_msg
|
||||
} else {
|
||||
await delay(acco.WAIT);
|
||||
}
|
||||
} else {
|
||||
if (COOKIE) {
|
||||
const { setVariable } = require("./lib/setVariable");
|
||||
await setVariable(COOKIE, Number(NUMBER));
|
||||
}
|
||||
|
||||
const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs");
|
||||
const { clear } = require("./lib/clear");
|
||||
/**多账号状态还原 */
|
||||
process.env.ENABLE_MULTIPLE_ACCOUNT = ENABLE_MULTIPLE_ACCOUNT;
|
||||
} else if (COOKIE) {
|
||||
const global_var = require("./lib/data/global_var");
|
||||
await global_var.init(COOKIE, Number(NUMBER));
|
||||
|
||||
tooltip.log('[LotteryAutoScript] 账号' + NUMBER);
|
||||
/**引入基础功能 */
|
||||
const { start, isMe, clear, update, checkCookie } = require("./lib/index");
|
||||
|
||||
if (await checkCookie(NUMBER)) {
|
||||
const mode = process.env.lottery_mode;
|
||||
switch (mode) {
|
||||
case 'start':
|
||||
tooltip.log('开始参与抽奖');
|
||||
await start();
|
||||
break;
|
||||
case 'check':
|
||||
tooltip.log('检查是否中奖');
|
||||
await isMe();
|
||||
break;
|
||||
case 'clear':
|
||||
if (CLEAR) {
|
||||
tooltip.log('开始清理动态');
|
||||
await clear();
|
||||
tooltip.log('清理动态完毕');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log(`Usage: lottery-in-bili [OPTIONS]`)
|
||||
console.log(`错误OPTIONS: ${mode} 正确OPTIONS: start,check,clear`);
|
||||
log.info('main', '当前为第' + NUMBER + '个账号');
|
||||
|
||||
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, update_loop_wait } = require("./lib/data/config");
|
||||
switch (mode) {
|
||||
case 'start':
|
||||
log.info('抽奖', '开始运行');
|
||||
loop_wait = lottery_loop_wait;
|
||||
await start();
|
||||
break;
|
||||
case 'check':
|
||||
log.info('中奖检测', '检查是否中奖');
|
||||
loop_wait = check_loop_wait;
|
||||
await isMe();
|
||||
break;
|
||||
case 'clear':
|
||||
if (CLEAR) {
|
||||
log.info('清理动态', '开始运行');
|
||||
loop_wait = clear_loop_wait;
|
||||
await clear();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tooltip.log('请查看README文件, 在env.js指定位置填入cookie')
|
||||
break;
|
||||
case 'update':
|
||||
log.info('检查更新', '开始')
|
||||
loop_wait = update_loop_wait;
|
||||
await update()
|
||||
break;
|
||||
case 'help':
|
||||
return help_msg
|
||||
case undefined:
|
||||
return "未提供以下参数\n\t[OPTIONS]\n\n" + help_msg
|
||||
default:
|
||||
return `提供了错误的[OPTIONS] -> ${mode}\n\n` + help_msg
|
||||
}
|
||||
} else {
|
||||
return 'Cookie已失效, 切换账号时不要点击退出账号而应直接删除Cookie退出'
|
||||
}
|
||||
} else {
|
||||
tooltip.log('请查看README文件, 填入相应的PAT, 若是本地运行则设LOCALLAUNCH为true');
|
||||
return '请查看README文件, 在env.js指定位置填入cookie'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化环境
|
||||
* @returns {boolean} 出错true
|
||||
*/
|
||||
function initEnv() {
|
||||
if (hasFileOrDir(env_file)) {
|
||||
const
|
||||
env = require("./lib/data/env"),
|
||||
multiple_account_parm = env.get_multiple_account();
|
||||
|
||||
if (multiple_account_parm) {
|
||||
multiple_account = multiple_account_parm;
|
||||
}
|
||||
|
||||
env.init();
|
||||
log.init();
|
||||
log.info('环境变量初始化', '成功加载env.js文件');
|
||||
} else if (hasEnv('COOKIE') || hasEnv('MULTIPLE_ACCOUNT_PARM')) {
|
||||
log.init();
|
||||
log.info('环境变量初始化', '成功从环境变量中读取COOKIE设置');
|
||||
} else {
|
||||
log.init();
|
||||
log.error('环境变量初始化', '未在当前目录下找到env.js文件或者在环境变量中设置所需参数');
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化设置
|
||||
* @returns {boolean} 出错true
|
||||
*/
|
||||
function initConfig() {
|
||||
if (hasFileOrDir(config_file)) {
|
||||
const config = require("./lib/data/config");
|
||||
config.init();
|
||||
log.info('配置文件初始化', '成功加载my_config.js文件');
|
||||
} else {
|
||||
log.error('配置文件初始化', '未在当前目录下找到my_config.js文件');
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
(async function () {
|
||||
let metainfo = '';
|
||||
metainfo += ` _ _ _ _____ _ _ \n`;
|
||||
metainfo += ` | | | | | | / ____| (_) | | \n`;
|
||||
metainfo += ` | | ___ | |_| |_ ___ _ __ _ _| (___ ___ _ __ _ _ __ | |_ \n`;
|
||||
metainfo += ` | | / _ \\| __| __/ _ \\ '__| | | |\\___ \\ / __| '__| | '_ \\| __|\n`;
|
||||
metainfo += ` | |___| (_) | |_| || __/ | | |_| |____) | (__| | | | |_) | |_ \n`;
|
||||
metainfo += ` |______\\___/ \\__|\\__\\___|_| \\__, |_____/ \\___|_| |_| .__/ \\__|\n`;
|
||||
metainfo += ` __/ | | | \n`;
|
||||
metainfo += ` |___/ |_| \n`;
|
||||
metainfo += ` \n`;
|
||||
metainfo += ` by shanmite\n`;
|
||||
console.log(metainfo);
|
||||
log.proPrint(metainfo, '\n')
|
||||
|
||||
if (initEnv() || initConfig()) return;
|
||||
|
||||
/**OPTIONS */
|
||||
process.env.lottery_mode = process.argv[2]
|
||||
await main();
|
||||
await delay(5 * 1000);
|
||||
process.exit(0)
|
||||
|
||||
const err_msg = await main();
|
||||
if (err_msg) {
|
||||
log.error('错误', err_msg);
|
||||
log.warn('结束运行', '5秒后自动退出');
|
||||
await delay(5 * 1000);
|
||||
} else {
|
||||
while (loop_wait) {
|
||||
log.info('程序休眠', `${loop_wait / 1000}秒后再次启动`)
|
||||
await delay(loop_wait)
|
||||
if (initEnv() || initConfig()) return;
|
||||
await main()
|
||||
}
|
||||
log.info('结束运行', '未在config.js中设置休眠时间')
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
})()
|
||||
+88
-38
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
module.exports = Object.freeze({
|
||||
/**
|
||||
* 默认设置(公用)
|
||||
*/
|
||||
@@ -7,9 +7,15 @@ module.exports = {
|
||||
* 监视更转的用户uid
|
||||
*/
|
||||
UIDs: [
|
||||
31252386,
|
||||
35719643,
|
||||
689277291
|
||||
689277291,
|
||||
241675899
|
||||
],
|
||||
|
||||
/**
|
||||
* 监视的专栏关键词
|
||||
*/
|
||||
Articles: [
|
||||
'抽奖合集'
|
||||
],
|
||||
|
||||
/**
|
||||
@@ -17,9 +23,9 @@ module.exports = {
|
||||
*/
|
||||
TAGs: [
|
||||
'互动抽奖',
|
||||
'抽奖',
|
||||
'转发抽奖',
|
||||
'动态抽奖',
|
||||
'抽奖',
|
||||
],
|
||||
|
||||
/**
|
||||
@@ -53,9 +59,25 @@ module.exports = {
|
||||
is_imitator: false,
|
||||
|
||||
/**
|
||||
* - 在uid或tag里检索的页数
|
||||
* - 在uid里检索的页数
|
||||
*/
|
||||
scan_page_num: 3,
|
||||
uid_scan_page: 3,
|
||||
|
||||
/**
|
||||
* - 在tag里检索的页数
|
||||
*/
|
||||
tag_scan_page: 3,
|
||||
|
||||
/**
|
||||
* - 获取专栏数量
|
||||
*/
|
||||
article_scan_page: 3,
|
||||
|
||||
/**
|
||||
* - 不检查专栏是否看过,若选择检查可以提高检测效率
|
||||
* - 默认false(检查)
|
||||
*/
|
||||
not_check_article: false,
|
||||
|
||||
/**
|
||||
* - 开奖时间距离现在的最大天数
|
||||
@@ -63,12 +85,21 @@ module.exports = {
|
||||
*/
|
||||
maxday: Infinity,
|
||||
|
||||
/**
|
||||
* - 循环等待时间(指所有操作完毕后的休眠时间)
|
||||
* - 单位毫秒
|
||||
*/
|
||||
lottery_loop_wait: 0,
|
||||
check_loop_wait: 0,
|
||||
clear_loop_wait: 0,
|
||||
update_loop_wait: 0,
|
||||
|
||||
/**
|
||||
* - 转发间隔时间
|
||||
* - 单位毫秒
|
||||
* - 上下浮动50%
|
||||
*/
|
||||
wait: 100000,
|
||||
wait: 30 * 1000,
|
||||
|
||||
/**
|
||||
* - 检索动态间隔
|
||||
@@ -81,11 +112,6 @@ module.exports = {
|
||||
*/
|
||||
minfollower: 1000,
|
||||
|
||||
/**
|
||||
* 粉丝数限制是否跳过有官方认证的up
|
||||
*/
|
||||
skip_official_verify: true,
|
||||
|
||||
/**
|
||||
* - 只转发已关注的
|
||||
*/
|
||||
@@ -97,15 +123,19 @@ module.exports = {
|
||||
create_dy: false,
|
||||
|
||||
/**
|
||||
* - 发送随机动态的数量
|
||||
* - 结束运行时发送随机动态的数量
|
||||
*/
|
||||
create_dy_num: 1,
|
||||
|
||||
/**
|
||||
* - 每转发x条抽奖动态就发送x条随机动态
|
||||
* - @example [6,1] 每转发6条抽奖动态就发送1条随机动态
|
||||
*/
|
||||
create_dy_mode: [0, 0],
|
||||
|
||||
/**
|
||||
* - 随机动态内容
|
||||
* - 类型 `content[]`
|
||||
*/
|
||||
/**
|
||||
* @typedef Picture
|
||||
* @property {string} img_src 站内源
|
||||
* @property {number} img_width
|
||||
@@ -120,19 +150,15 @@ module.exports = {
|
||||
at_users: [['转发抽奖娘', 294887687], ['你的工具人老公', 100680137]],
|
||||
|
||||
/**
|
||||
* 同步 https://gitee.com/shanmite/lottery-notice/raw/master/notice.json
|
||||
* - 自动同步 https://gitee.com/shanmite/lottery-notice/raw/master/notice.json
|
||||
* - 英文逗号分隔 如: 1,2,3
|
||||
*/
|
||||
blacklist: '1,2',
|
||||
blacklist: '',
|
||||
|
||||
/**
|
||||
* 屏蔽词
|
||||
*/
|
||||
blockword: ["脚本抽奖", "恭喜", "结果", "抽奖号"],
|
||||
|
||||
/**
|
||||
* 取关白名单
|
||||
*/
|
||||
followWhiteList: '1,2',
|
||||
blockword: ["脚本抽奖", "恭喜", "结果", "抽奖号", "钓鱼", "涨粉"],
|
||||
|
||||
/**
|
||||
* 转发评语
|
||||
@@ -151,7 +177,8 @@ module.exports = {
|
||||
],
|
||||
|
||||
/**
|
||||
* 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid)
|
||||
* - 抽奖UP用户分组id(网页端点击分区后地址栏中的tagid)
|
||||
* - 自动获取
|
||||
*/
|
||||
partition_id: 0,
|
||||
|
||||
@@ -161,15 +188,38 @@ module.exports = {
|
||||
is_exception: false,
|
||||
|
||||
/**
|
||||
* 取关分区
|
||||
* - 中奖通知关键词(满足一个就推送)
|
||||
* - 符合js正则表达式的字符串
|
||||
* - 若以 ~ 开头则表示为黑名单规则
|
||||
*/
|
||||
notice_key_words: [
|
||||
"中奖|获得|填写|写上|提供|收货地址|支付宝账号|码|大会员",
|
||||
"~有奖预约通知"
|
||||
],
|
||||
|
||||
/**
|
||||
* - 清理白名单uid或dyid
|
||||
* - 英文逗号分隔 如: 1,2,3
|
||||
*/
|
||||
clear_white_list: '',
|
||||
|
||||
/**
|
||||
* - 取关分区
|
||||
* - 默认为: 此处存放因抽奖临时关注的up
|
||||
*/
|
||||
clear_partition: '',
|
||||
|
||||
/**
|
||||
* 清理多少天内的动态或关注
|
||||
* 清理多少天之前的动态或关注
|
||||
*/
|
||||
clear_max_day: 30,
|
||||
|
||||
/**
|
||||
* - 快速移除关注
|
||||
* - 不加判断只去除关注
|
||||
*/
|
||||
clear_quick_remove_attention: false,
|
||||
|
||||
/**
|
||||
* 是否移除动态
|
||||
*/
|
||||
@@ -187,15 +237,16 @@ module.exports = {
|
||||
|
||||
/**
|
||||
* 清除动态类型
|
||||
| 动态类型 | type值 |
|
||||
| ---------- | ------ |
|
||||
| 无 | `0` |
|
||||
| 转发 | `1` |
|
||||
| 含图片 | `2` |
|
||||
| 无图纯文字 | `4` |
|
||||
| 视频 | `8` |
|
||||
| 专栏 | `64` |
|
||||
| 活动 | `2048` |
|
||||
*
|
||||
* | 动态类型 | type值 |
|
||||
* | :------- |:----- |
|
||||
* | 无 | `0` |
|
||||
* | 转发 | `1` |
|
||||
* | 含图片 | `2` |
|
||||
* | 无图纯文字 | `4` |
|
||||
* | 视频 | `8` |
|
||||
* | 活动 | `2048` |
|
||||
* | 专栏 | `64` |
|
||||
*/
|
||||
clear_dynamic_type: 1
|
||||
},
|
||||
@@ -207,5 +258,4 @@ module.exports = {
|
||||
config_1: {},
|
||||
config_2: {},
|
||||
config_3: {}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Generated
-2144
File diff suppressed because it is too large
Load Diff
+22
-11
@@ -1,15 +1,26 @@
|
||||
{
|
||||
"name": "lottery-in-bili",
|
||||
"version": "3.0.0",
|
||||
"description": "自动抽奖",
|
||||
"name": "lottery-auto-script",
|
||||
"version": "2.2.1",
|
||||
"description": "自动参与B站动态抽奖",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "node main.js start",
|
||||
"clear": "node main.js clear",
|
||||
"check": "node main.js check",
|
||||
"pkg": "npx pkg . && powershell .\\script\\pkg\\pkg.ps1",
|
||||
"pkg_arm": "npx pkg -t linux-arm -o dist/lottery-in-bili-linux-arm main.js"
|
||||
"update": "node main.js update",
|
||||
"pkg_x64": "PowerShell .\\script\\pkg\\pkg.ps1",
|
||||
"pkg_arm64": "npx pkg -t node16-linux-arm64 -o dist/lottery main.js && cp my_config.example.js dist/my_config.js && cp env.example.js dist/env.js",
|
||||
"pkg_armv7": "npx pkg -t node16-linuxstatic-armv7 -o dist/lottery main.js && cp my_config.example.js dist/my_config.js && cp env.example.js dist/env.js"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"main.js",
|
||||
"package.js",
|
||||
"my_config.example.js",
|
||||
"env.example.js",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"bin": "main.js",
|
||||
"pkg": {
|
||||
"targets": [
|
||||
@@ -21,7 +32,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/shanmite/AutoScript.git"
|
||||
"url": "https://github.com/shanmiteko/AutoScript.git"
|
||||
},
|
||||
"keywords": [
|
||||
"auto",
|
||||
@@ -30,15 +41,15 @@
|
||||
"author": "shanmite",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/shanmite/AutoScript/issues"
|
||||
"url": "https://github.com/shanmiteko/AutoScript/issues"
|
||||
},
|
||||
"homepage": "https://github.com/shanmite/AutoScript#readme",
|
||||
"homepage": "https://github.com/shanmiteko/AutoScript#readme",
|
||||
"devDependencies": {
|
||||
"eslint": "^7.17.0",
|
||||
"pkg": "^5.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"nodemailer": "^6.5.0",
|
||||
"unzipper": "^0.10.11"
|
||||
"chalk": "^4.1.1",
|
||||
"nodemailer": "^6.5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-16
@@ -1,9 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# 脚本根目录
|
||||
SCRIPT_FOLDER=lottery
|
||||
# dyid存放目录
|
||||
DYID_FOLDER=dyids
|
||||
# 设置环境变量文件
|
||||
ENV_FILE=env.js
|
||||
# 自定义设置文件
|
||||
@@ -25,14 +24,6 @@ fi
|
||||
|
||||
cd $SCRIPT_FOLDER/
|
||||
|
||||
# 新建dyid储存目录
|
||||
if [ ! -d "$DYID_FOLDER" ]; then
|
||||
echo "create $DYID_FOLDER/"
|
||||
mkdir $DYID_FOLDER
|
||||
else
|
||||
echo "$DYID_FOLDER/ exists"
|
||||
fi
|
||||
|
||||
# 新建环境变量设置文件
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
echo "create $ENV_FILE"
|
||||
@@ -57,30 +48,27 @@ echo -e "#!/bin/bash\n\
|
||||
docker run \
|
||||
-v $PWD/$ENV_FILE:/lottery/$ENV_FILE \
|
||||
-v $PWD/$CONFIG_FILE:/lottery/$CONFIG_FILE \
|
||||
-v $PWD/$DYID_FOLDER/:/lottery/$DYID_FOLDER/ \
|
||||
$DOCKER_REPO \
|
||||
start" \
|
||||
> start.sh
|
||||
chmod 777 start.sh
|
||||
chmod +x start.sh
|
||||
|
||||
echo "create check.sh"
|
||||
echo -e "#!/bin/bash\n\
|
||||
docker run \
|
||||
-v $PWD/$ENV_FILE:/lottery/$ENV_FILE \
|
||||
-v $PWD/$CONFIG_FILE:/lottery/$CONFIG_FILE \
|
||||
-v $PWD/$DYID_FOLDER/:/lottery/$DYID_FOLDER/ \
|
||||
$DOCKER_REPO \
|
||||
check" \
|
||||
> check.sh
|
||||
chmod 777 check.sh
|
||||
chmod +x check.sh
|
||||
|
||||
echo "create clear.sh"
|
||||
echo -e "#!/bin/bash\n\
|
||||
docker run \
|
||||
-v $PWD/$ENV_FILE:/lottery/$ENV_FILE \
|
||||
-v $PWD/$CONFIG_FILE:/lottery/$CONFIG_FILE \
|
||||
-v $PWD/$DYID_FOLDER/:/lottery/$DYID_FOLDER/ \
|
||||
$DOCKER_REPO \
|
||||
clear" \
|
||||
> clear.sh
|
||||
chmod 777 clear.sh
|
||||
chmod +x clear.sh
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run check
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run clear
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run start
|
||||
+34
-16
@@ -1,3 +1,4 @@
|
||||
$README = "README.md"
|
||||
$TEMPLATE_CONFIG_FILE = "my_config.example.js"
|
||||
$TEMPLATE_ENV_FILE = "env.example.js"
|
||||
|
||||
@@ -6,34 +7,51 @@ $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"
|
||||
$NAME = 'lottery-auto-script'
|
||||
|
||||
$WIN_X64 = "nlts-win-x64"
|
||||
$LINUX_X64 = "nlts-linux-x64"
|
||||
$MACOS_X64 = "nlts-macos-x64"
|
||||
$TRIARR = @(
|
||||
@("$NAME-win.exe", "lottery.exe", "nlts-win-x64"),
|
||||
@("$NAME-linux", "lottery", "nlts-linux-x64"),
|
||||
@("$NAME-macos", "lottery", "nlts-macos-x64")
|
||||
)
|
||||
|
||||
$MAP = @{ $WIN_X64 = $WIN_BIN; $LINUX_X64 = $LINUX_BIN; $MACOS_X64 = $MACOS_BIN}
|
||||
if((Test-Path $TARGET_DIR) -eq "True") {
|
||||
Remove-Item -Path $TARGET_DIR -Recurse
|
||||
}
|
||||
|
||||
npx pkg .
|
||||
|
||||
Copy-Item -Path $TEMPLATE_ENV_FILE -Destination $TARGET_DIR -Force
|
||||
Copy-Item -Path $TEMPLATE_CONFIG_FILE -Destination $TARGET_DIR -Force
|
||||
Copy-Item -Path $README -Destination $TARGET_DIR -Force
|
||||
|
||||
Set-Location -Path $TARGET_DIR
|
||||
|
||||
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]
|
||||
if (!(Test-Path $X64 -PathType Container)) {
|
||||
New-Item -ItemType Directory -Force -Path $X64
|
||||
foreach ($TRI in $TRIARR) {
|
||||
$PROTO_BIN,$BIN,$DIR = $TRI
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $DIR
|
||||
|
||||
Move-Item -Path $PROTO_BIN -Destination $BIN -Force
|
||||
|
||||
Move-Item -Path $BIN -Destination $DIR -Force
|
||||
Copy-Item -Path $ENV_FILE -Destination $DIR -Force
|
||||
Copy-Item -Path $CONFIG_FILE -Destination $DIR -Force
|
||||
Copy-Item -Path $README -Destination $DIR -Force
|
||||
|
||||
if ($DIR -eq "nlts-win-x64") {
|
||||
New-Item -Path $DIR -Name "start.bat" -ItemType File -Value "@echo off && lottery start && pause" -Force
|
||||
New-Item -Path $DIR -Name "check.bat" -ItemType File -Value "@echo off && lottery check && pause" -Force
|
||||
New-Item -Path $DIR -Name "clear.bat" -ItemType File -Value "@echo off && lottery clear && pause" -Force
|
||||
New-Item -Path $DIR -Name "update.bat" -ItemType File -Value "@echo off && lottery update && pause" -Force
|
||||
}
|
||||
Move-Item -Path $BIN -Destination $X64 -Force
|
||||
Copy-Item -Path $ENV_FILE -Destination $X64 -Force
|
||||
Copy-Item -Path $CONFIG_FILE -Destination $X64 -Force
|
||||
Compress-Archive -Path $X64 -DestinationPath $X64 -Force
|
||||
|
||||
Compress-Archive -Path $DIR -DestinationPath $DIR -Force
|
||||
}
|
||||
|
||||
Remove-Item -Path $ENV_FILE
|
||||
Remove-Item -Path $CONFIG_FILE
|
||||
Remove-Item -Path $CONFIG_FILE
|
||||
Remove-Item -Path $README
|
||||
@@ -1,9 +0,0 @@
|
||||
chcp 65001
|
||||
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run check
|
||||
|
||||
# 暂停
|
||||
pause
|
||||
@@ -1,9 +0,0 @@
|
||||
chcp 65001
|
||||
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run clear
|
||||
|
||||
# 暂停
|
||||
pause
|
||||
@@ -1,9 +0,0 @@
|
||||
chcp 65001
|
||||
|
||||
cd ..
|
||||
cd ..
|
||||
npm i
|
||||
npm run start
|
||||
|
||||
# 暂停
|
||||
pause
|
||||
@@ -1,6 +0,0 @@
|
||||
const { getDyid } = require("../lib/MyStorage");
|
||||
|
||||
(async () => {
|
||||
let alldyid = await getDyid();
|
||||
console.log(alldyid);
|
||||
})()
|
||||
@@ -1,5 +0,0 @@
|
||||
const { getHiToKoTo } = require("../lib/Base");
|
||||
|
||||
getHiToKoTo().then(h => {
|
||||
console.log(h);
|
||||
})
|
||||
@@ -1,5 +0,0 @@
|
||||
const { getZhihuBillBoard } = require("../lib/Base");
|
||||
|
||||
getZhihuBillBoard().then(x => {
|
||||
console.log(x);
|
||||
})
|
||||
@@ -1,19 +0,0 @@
|
||||
const { HttpRequest } = require("../lib/HttpRequest");
|
||||
|
||||
HttpRequest({
|
||||
method: 'GET',
|
||||
url: 'https://www.www.www',
|
||||
headers: {
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
|
||||
accept: 'application/json, text/plain, */*',
|
||||
},
|
||||
config: {
|
||||
wait: 1000
|
||||
},
|
||||
success: res => {
|
||||
console.log(res.body);
|
||||
},
|
||||
failure: err => {
|
||||
console.log(err);
|
||||
}
|
||||
})
|
||||
@@ -1,26 +0,0 @@
|
||||
const { createReadStream, createWriteStream } = require('fs');
|
||||
|
||||
const file = 'test/huge_file/dyid.txt';
|
||||
const test = 'test/huge_file/test.txt';
|
||||
|
||||
const ws = createReadStream(file, { encoding: 'utf8', highWaterMark: 19 * 1000 })
|
||||
|
||||
const rs = createWriteStream(test, { flags: 'a' })
|
||||
|
||||
rs.write(Date.now() + '->', () => {
|
||||
console.log('写入完毕');
|
||||
rs.destroy()
|
||||
})
|
||||
|
||||
let i = 0;
|
||||
ws.on('data', chunk => {
|
||||
i++;
|
||||
if (/000000000000000000/.test(chunk)) {
|
||||
console.log('success')
|
||||
console.log('in ' + i)
|
||||
// 14764824 bytes
|
||||
// success
|
||||
// in 778
|
||||
// [Done] exited with code=0 in 0.331 seconds
|
||||
}
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
===1614266851666->
|
||||
Reference in New Issue
Block a user