-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into normal-server
- Loading branch information
Showing
7 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Ver.bot-notify | ||
|
||
<div align="center"> | ||
<img src="https://rping.github.io/Ver.bot-site/img/vbot.png" width="160"> | ||
</div> | ||
<br /> | ||
|
||
<div align="center"> | ||
|
||
[![node (6.10.x)](https://img.shields.io/badge/node-6.10.x-brightgreen.svg)]() | ||
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SVRBTQKRQ5VGE) | ||
|
||
</div> | ||
|
||
Ver.bot notify part. | ||
|
||
Webhook part in [here][4]. | ||
|
||
## Deploy by yourself | ||
|
||
**NOTE:** You should deploy the same **major version** as [webhook part][4]. | ||
|
||
### AWS Lambda(`master` branch) | ||
1. install dependency | ||
```bash | ||
npm i | ||
``` | ||
|
||
2. before deploy to AWS, [install AWS CLI][1] and [configure it][2]. | ||
|
||
3. create lambda function. | ||
|
||
4. set following environment variables. | ||
``` | ||
CHECK_DAYS | ||
SKYPE_APP_ID | ||
SKYPE_APP_SECRET | ||
SLACK_BOT_TOKEN | ||
TELEGRAM_BOT_TOKEN | ||
``` | ||
|
||
5. If you want to update lambda function: | ||
```bash | ||
sh update-lambda.sh | ||
``` | ||
|
||
6. set a cron job ( e.g. [CloudWatch Events][3]) to match `CHECK_DAYS` in environment variables. | ||
|
||
|
||
### General server(`normal-server` branch) | ||
1. install dependency | ||
```bash | ||
npm i | ||
``` | ||
2. set following environment variables. | ||
``` | ||
AWS_ACCESS_ID | ||
AWS_SECRET_KEY | ||
CHECK_DAYS | ||
SKYPE_APP_ID | ||
SKYPE_APP_SECRET | ||
SLACK_BOT_TOKEN | ||
TELEGRAM_BOT_TOKEN | ||
``` | ||
3. set a cron job to match `CHECK_DAYS` in environment variables. | ||
|
||
|
||
## LICENSE | ||
[AGPL-3.0](LICENSE) | ||
|
||
[1]: http://docs.aws.amazon.com/cli/latest/userguide/installing.html | ||
[2]: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html | ||
[3]: http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html | ||
[4]: https://github.com/RPing/Ver.bot |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ const site = require('./lib/site-utils') | |
const checkTime = new Date() | ||
checkTime.setDate(checkTime.getDate() - process.env.CHECK_DAYS) // current time - CHECK_DAYS | ||
|
||
const postNotifyMsg = | ||
'If you have any question, post an issue in\nhttps://github.com/RPing/Ver.bot-notify/issues\n' + | ||
'Or if you find some security issue, contact me\[email protected]\n' + | ||
'To support AWS Lambda and EC2 running, please donate\nhttps://goo.gl/9czXSn (paypal link)' | ||
|
||
function needToNotify(results) { | ||
const hasNewVer = results.info.length > 0 | ||
const hasSubscriber = results.subscribers.length > 0 | ||
|
@@ -41,12 +46,42 @@ function notify(projectPlatform, projectName, releasePage, results, cb) { | |
) | ||
} | ||
|
||
function postNotify(subscribers, cb) { | ||
const fnList = [] | ||
subscribers.forEach((subscriber) => { | ||
fnList.push((inner_cb) => { | ||
site.siteUtil(subscriber.platform) | ||
.send(subscriber.id, postNotifyMsg, (err) => { | ||
if (err) { | ||
console.error('---- error when post-notify ----') | ||
console.error(subscriber.platform, subscriber.id) | ||
console.error(err) | ||
return inner_cb(err) | ||
} | ||
inner_cb(null) | ||
}) | ||
}) | ||
}) | ||
|
||
async.parallel( | ||
async.reflectAll(fnList), | ||
function parallelCallback(err, parallel_results) { | ||
const hasSomeError = parallel_results.some(result => result.error !== undefined) | ||
|
||
cb(hasSomeError) | ||
} | ||
) | ||
} | ||
|
||
function checkAndNotify(results, projectInfo, projectName, projectPlatform, cb) { | ||
if (needToNotify(results)) { | ||
async.series([ | ||
function (inner_cb) { | ||
const releasePage = site.siteUtil(projectPlatform).getReleasesPage(projectInfo) | ||
notify(projectPlatform, projectName, releasePage, results, inner_cb) | ||
}, | ||
function (inner_cb) { | ||
postNotify(results.subscribers, inner_cb) | ||
} | ||
], function seriesCallback(err) { | ||
if (err) | ||
|
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
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
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
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
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