Created
August 31, 2021 03:20
-
-
Save monsterxcn/62fb00a3564c37cccb3f2989330818ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// version v0.0.2 | |
// create by ruicky | |
// detail url: https://github.com/ruicky/jd_sign_bot | |
const exec = require('child_process').execSync; | |
const fs = require('fs'); | |
const rp = require('request-promise'); | |
const download = require('download'); | |
// 公共变量 | |
const KEY = process.env.JD_COOKIE; | |
const serverJ = process.env.PUSH_KEY; | |
const DualKey = process.env.JD_COOKIE_2; | |
async function downFile () { | |
// const url = 'https://cdn.jsdelivr.net/gh/NobyDa/Script@master/JD-DailyBonus/JD_DailyBonus.js' | |
const url = 'https://raw.githubusercontent.com/NobyDa/Script/master/JD-DailyBonus/JD_DailyBonus.js'; | |
await download(url, './'); | |
} | |
async function changeFile () { | |
let content = await fs.readFileSync('./JD_DailyBonus.js', 'utf8') | |
content = content.replace(/var Key = ''/, `var Key = '${KEY}'`); | |
if (DualKey) { | |
content = content.replace(/var DualKey = ''/, `var DualKey = '${DualKey}'`); | |
} | |
await fs.writeFileSync( './JD_DailyBonus.js', content, 'utf8') | |
} | |
async function sendNotify (text,desp) { | |
const options ={ | |
uri: `https://sc.ftqq.com/${serverJ}.send`, | |
form: { text, desp }, | |
json: true, | |
method: 'POST' | |
} | |
await rp.post(options).then(res=>{ | |
console.log(res) | |
}).catch((err)=>{ | |
console.log(err) | |
}) | |
} | |
async function start() { | |
if (!KEY) { | |
console.log('请填写 key 后在继续') | |
return | |
} | |
// 下载最新代码 | |
await downFile(); | |
console.log('下载代码完毕') | |
// 替换变量 | |
await changeFile(); | |
console.log('替换变量完毕') | |
// 执行 | |
await exec("node JD_DailyBonus.js >> result.txt"); | |
console.log('执行完毕') | |
if (serverJ) { | |
const path = "./result.txt"; | |
let content = ""; | |
if (fs.existsSync(path)) { | |
content = fs.readFileSync(path, "utf8"); | |
} | |
let t = content.match(/【签到概览】:((.|\n)*)【签到总计】/) | |
let res = t ? t[1].replace(/\n/,'') : '失败' | |
let t2 = content.match(/【签到总计】:((.|\n)*)【账号总计】/) | |
let res2 = t2 ? t2[1].replace(/\n/,'') : '总计0' | |
await sendNotify("" + ` ${res2} ` + ` ${res} ` + new Date().toLocaleDateString(), content); | |
} | |
} | |
start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "jd_sign", | |
"version": "1.0.0", | |
"description": "", | |
"main": "JD_DailyBonus.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+https://github.com/ruicky/jd_sign_bot.git" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"bugs": { | |
"url": "https://github.com/ruicky/jd_sign_bot/issues" | |
}, | |
"homepage": "https://github.com/ruicky/jd_sign_bot#readme", | |
"dependencies": { | |
"download": "^8.0.0", | |
"request": "^2.88.2", | |
"request-promise": "^4.2.5" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Github JDSign | |
on: | |
push: | |
branches: | |
- master | |
schedule: | |
- cron: '5 16 * * *' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout codes | |
uses: actions/checkout@v2 | |
- name: Use Node.js | |
uses: actions/setup-node@v1 | |
with: | |
node-version: '12.x' | |
- name: Run app | |
run: npm install | |
- run: node app.js | |
env: | |
JD_COOKIE: ${{ secrets.JD_COOKIE }} | |
JD_COOKIE_2: ${{ secrets.JD_COOKIE_2 }} | |
PUSH_KEY: ${{ secrets.PUSH_KEY }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment