Skip to content

Commit

Permalink
chore: 添加tg相关环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
shanmite committed Mar 15, 2021
1 parent 131e381 commit 2d67e0b
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
BARK_SOUND: ${{ secrets.BARK_SOUND }}
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_USER_ID: ${{ secrets.TG_USER_ID }}
TG_PROXY_HOST: ${{ secrets.TG_PROXY_HOST }}
TG_PROXY_PORT: ${{ secrets.TG_PROXY_PORT }}
DD_BOT_TOKEN: ${{ secrets.DD_BOT_TOKEN }}
DD_BOT_SECRET: ${{ secrets.DD_BOT_SECRET }}
QYWX_KEY: ${{ secrets.QYWX_KEY}}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/clear.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ env:
BARK_SOUND: ${{ secrets.BARK_SOUND }}
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_USER_ID: ${{ secrets.TG_USER_ID }}
TG_PROXY_HOST: ${{ secrets.TG_PROXY_HOST }}
TG_PROXY_PORT: ${{ secrets.TG_PROXY_PORT }}
DD_BOT_TOKEN: ${{ secrets.DD_BOT_TOKEN }}
DD_BOT_SECRET: ${{ secrets.DD_BOT_SECRET }}
QYWX_KEY: ${{ secrets.QYWX_KEY}}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ env:
BARK_SOUND: ${{ secrets.BARK_SOUND }}
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_USER_ID: ${{ secrets.TG_USER_ID }}
TG_PROXY_HOST: ${{ secrets.TG_PROXY_HOST }}
TG_PROXY_PORT: ${{ secrets.TG_PROXY_PORT }}
DD_BOT_TOKEN: ${{ secrets.DD_BOT_TOKEN }}
DD_BOT_SECRET: ${{ secrets.DD_BOT_SECRET }}
QYWX_KEY: ${{ secrets.QYWX_KEY}}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Chrome浏览器:
| `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` , [具体教程](.github/TG_PUSH.md) |
| `TG_USER_ID` | telegram推送 | 非必须 | tg推送(需设备可连接外网),`TG_BOT_TOKEN``TG_USER_ID`两者必需,填写[@getuseridbot](https://t.me/getuseridbot)中获取到的纯数字ID, [具体教程](.github/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`等字符 , 注:钉钉机器人安全设置只需勾选`加签`即可,其他选项不要勾选,再不懂看 [这个图](.github/DD_bot.png) |
| `IGOT_PUSH_KEY` | iGot推送 | 非必须 | iGot聚合推送,支持多方式推送,确保消息可达。 [参考文档](https://wahao.github.io/Bark-MP-helper ) |
Expand All @@ -155,8 +157,6 @@ Chrome浏览器:
| `QYWX_KEY` | 企业微信推送 | 非必须 | 密钥,企业微信推送 webhook 后面的 key [详见官方说明文档](https://work.weixin.qq.com/api/doc/90000/90136/91770) |
| `PUSH_PLUS_TOKEN` | pushplus推送 | 非必须 | 微信扫码登录后一对一推送或一对多推送下面的token(您的Token) [官方网站](http://pushplus.hxtrip.com/) |
| `PUSH_PLUS_USER` | pushplus推送 | 非必须 | 一对多推送的“群组编码”(一对多推送下面->您的群组(如无则新建)->群组编码)注:(1、需订阅者扫描二维码 2、如果您是创建群组所属人,也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送),只填`PUSH_PLUS_TOKEN`默认为一对一推送 |
| `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 |

↓↓

Expand Down
5 changes: 3 additions & 2 deletions env.example.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@REM 下载代码到本地
@REM 安装node(http://nodejs.cn/download/)

@REM for windows
@REM Windows
@REM 此批处理脚本为本地运行代码前设置环境变量时所需
@REM 使用时先将本文件名改成env.bat
@REM 填入相应的值
@REM 需注意 % 要转义为 %%
@REM npm install 安装依赖
@REM npm run test_start 启动脚本
@REM npm run test_check 检查是否中奖(只查看两个小时内的奖)
@REM npm run test_clear 清空动态和关注(须set CLEAR=true)
Expand All @@ -25,6 +24,8 @@ set BARK_PUSH=
set BARK_SOUND=
set TG_BOT_TOKEN=
set TG_USER_ID=
set TG_PROXY_HOST=
set TG_PROXY_PORT=
set DD_BOT_TOKEN=
set DD_BOT_SECRET=
set QYWX_KEY=
Expand Down
34 changes: 17 additions & 17 deletions lib/lottery-in-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ const { sendNotify } = require('./sendNotify');
function start() {
return new Promise(resolve => {
function createRandomDynamic() {
Public.prototype.checkAllDynamic(GlobalVar.myUID, 1).then(Dynamic => {
if (Dynamic.allModifyDynamicResArray[0].type === 1) {
Base.getPictures().then(
(pic) => {
BiliAPI.createDynamic('', pic);
},
(con) => {
BiliAPI.createDynamic(con);
}
)
}
})
if (GlobalVar.create_dy === '1') {
Public.prototype.checkAllDynamic(GlobalVar.myUID, 1).then(Dynamic => {
if (Dynamic.allModifyDynamicResArray[0].type === 1) {
Base.getPictures().then(
(pic) => {
BiliAPI.createDynamic('', pic);
},
(con) => {
BiliAPI.createDynamic(con);
}
)
}
})
}
}
let times = Base.counter();
/* 注册事件 */
Expand All @@ -35,9 +37,7 @@ function start() {
console.log('所有动态转发完毕');
console.log('[运行结束]目前无抽奖信息,过一会儿再来看看吧');
times.clear();
if (GlobalVar.create_dy === '1') {
createRandomDynamic()
}
createRandomDynamic()
resolve()
return
}
Expand Down Expand Up @@ -102,7 +102,7 @@ async function isMe() {
max++
} while (MySession.has_more && max < 6);
}
if (desp !== '') {
if (desp) {
console.log(desp);
sendNotify('可能中奖了!', desp);
} else {
Expand All @@ -121,7 +121,7 @@ async function checkCookie(num) {
return true;
} else {
console.log(`登录失败 COOKIE${num} 已失效 UID:${GlobalVar.myUID}`);
sendNotify('动态抽奖出错', `COOKIE${num} 已失效 UID:${GlobalVar.myUID}`)
sendNotify('动态抽奖出错-登录失败', `COOKIE${num} 已失效 UID:${GlobalVar.myUID}`)
return false;
}
}
Expand Down
45 changes: 31 additions & 14 deletions lib/sendNotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ let TG_BOT_TOKEN = '';
//此处填你接收通知消息的telegram用户的id,例如:129xxx206
//注:此处设置github action用户填写到Settings-Secrets里面(Name输入TG_USER_ID)
let TG_USER_ID = '';

//代理主机
let TG_PROXY_HOST = '';
//代理端口
let TG_PROXY_PORT = '';
// =======================================钉钉机器人通知设置区域===========================================
//此处填你钉钉 bot 的webhook,例如:5a544165465465645d0f31dca676e7bd07415asdasd
//注:此处设置github action用户填写到Settings-Secrets里面(Name输入DD_BOT_TOKEN)
Expand Down Expand Up @@ -90,6 +93,12 @@ if (process.env.TG_BOT_TOKEN) {
if (process.env.TG_USER_ID) {
TG_USER_ID = process.env.TG_USER_ID;
}
if (process.env.TG_PROXY_HOST) {
TG_PROXY_HOST = process.env.TG_PROXY_HOST;
}
if (process.env.TG_PROXY_PORT) {
TG_PROXY_PORT = process.env.TG_PROXY_PORT;
}

if (process.env.DD_BOT_TOKEN) {
DD_BOT_TOKEN = process.env.DD_BOT_TOKEN;
Expand Down Expand Up @@ -118,14 +127,22 @@ if (process.env.PUSH_PLUS_USER) {
async function sendNotify(text, desp, params = {}) {
//提供8种通知方式
await Promise.all([
serverNotify(text, desp),//微信server酱
pushPlusNotify(text, desp),//pushplus(推送加)
BarkNotify(text, desp, params),//iOS Bark APP
tgBotNotify(text, desp),//telegram 机器人
ddBotNotify(text, desp),//钉钉机器人
qywxBotNotify(text, desp), //企业微信机器人
iGotNotify(text, desp, params),//iGot
CoolPush(text, desp)//QQ酷推
//微信server酱
serverNotify(text, desp),
//pushplus(推送加)
pushPlusNotify(text, desp),
//iOS Bark APP
barkNotify(text, desp, params),
//telegram 机器人
tgBotNotify(text, desp),
//钉钉机器人
ddBotNotify(text, desp),
//企业微信机器人
qywxBotNotify(text, desp),
//iGot
iGotNotify(text, desp, params),
//QQ酷推
coolPush(text, desp)
])
}

Expand Down Expand Up @@ -174,7 +191,7 @@ function serverNotify(text, desp) {
})
}

function CoolPush(text, desp) {
function coolPush(text, desp) {
return new Promise(resolve => {
if (QQ_SKEY) {
let pushMode = function (t) {
Expand Down Expand Up @@ -233,7 +250,7 @@ function CoolPush(text, desp) {
})
}

function BarkNotify(text, desp, params = {}) {
function barkNotify(text, desp, params = {}) {
return new Promise(resolve => {
if (BARK_PUSH) {
HttpRequest({
Expand Down Expand Up @@ -317,10 +334,10 @@ function tgBotNotify(text, desp) {
throw new Error(err)
}
}
if (process.env.TG_PROXY_HOST && process.env.TG_PROXY_PORT) {
if (TG_PROXY_HOST && TG_PROXY_PORT) {
options.proxy = {
hostname: process.env.TG_PROXY_HOST,
port: process.env.TG_PROXY_PORT * 1
hostname: TG_PROXY_HOST,
port: TG_PROXY_PORT * 1
}
}
HttpRequest(options)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "lottery-in-bilibili",
"version": "2.1.0",
"version": "2.2.0",
"description": "自动抽奖",
"main": "main.js",
"scripts": {
"start": "node main.js start",
"clear": "node main.js clear",
"check": "node main.js check",
"test_start": "env.bat && node main.js start",
"test_clear": "env.bat && node main.js clear",
"test_check": "env.bat && node main.js check"
"test_start": "npm install && env.bat && node main.js start",
"test_clear": "npm install && env.bat && node main.js clear",
"test_check": "npm install && env.bat && node main.js check"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 2d67e0b

Please sign in to comment.