Skip to content

Commit

Permalink
Expand readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ABSLord committed Nov 7, 2018
1 parent 30e27ae commit 91e1176
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
Hubot script for showing random pictures with pugs.
Hubot script for showing random pictures with cuties.

The main goal of the project is to resurrect the original [pugme](https://github.com/hubot-scripts/hubot-pugme) which is written in CoffeScript. Thus, the first version of the script was based on the original code of pugme converted into JavaScript (with slight changes) using [decaffeinate](https://github.com/decaffeinate/decaffeinate). Then, a couple of enhancements were added to the script:
* the `PUGS_LIMIT` environment variable to limit the number of pugs when invoking `hubot pug bomb N`;
* a possibility to request pugs asynchronously.
The main goal of the project is to resurrect the original [pugme](https://github.com/hubot-scripts/hubot-pugme) which is written in CoffeScript. Thus, the first version of the script was based on the original code of pugme converted into JavaScript (with slight changes) using [decaffeinate](https://github.com/decaffeinate/decaffeinate) and has been expanded for other cuties. Then, a couple of enhancements were added to the script:
* the `CUTES_LIMIT`(`PUGS_LIMIT` in old version) environment variable to limit the number of cuties when invoking `hubot {cute_name} bomb N`;
* `cat me`(and similar `cat bomb`) commands for showing random picture with cats;
* a possibility to request cuties asynchronously.

## Installation

In hubot project repo, run:

`npm install git+https://github.com/tolstoyevsky/hubot-pugme --save`
`npm install git+https://github.com/tolstoyevsky/hubot-cuteme --save`

Then add **hubot-pugme** to your `external-scripts.json`:
Then add **hubot-cuteme** to your `external-scripts.json`:

```json
[
"hubot-pugme"
"hubot-cuteme"
]
```

## Configuration

The script supports the only configuration parameter which is `PUGS_LIMIT`. It allows the administrators to limit the maximum number of pugs. By default, the parameter is equal to **5**.
The script supports the only configuration parameter which is `CUTES_LIMIT`. It allows the administrators to limit the maximum number of cuties. By default, the parameter is equal to **5**.

## Sample Interaction

Expand All @@ -33,6 +34,14 @@ hubot>> http://25.media.tumblr.com/tumblr_lk7v8zCcIn1qaa50yo1_500.jpg
hubot>> http://26.media.tumblr.com/tumblr_ltee8lg9wd1qb08qmo1_500.jpg
hubot>> http://26.media.tumblr.com/tumblr_ll7aoxHGfW1qb08qmo1_500.jpg
hubot>> http://28.media.tumblr.com/tumblr_lk8iieigtQ1qzj3syo1_500.jpg
user>> hubot cat me
hubot>> https://purr.objects-us-west-1.dream.io/i/4o0mT.jpg
user>> hubot cat bomb
hubot>> https://purr.objects-us-west-1.dream.io/i/OIlLAN4.jpg
hubot>> https://purr.objects-us-west-1.dream.io/i/20160826_180141.jpg
hubot>> https://purr.objects-us-west-1.dream.io/i/Bh0nZ.jpg
hubot>> https://purr.objects-us-west-1.dream.io/i/WbaUU.jpg
hubot>> https://purr.objects-us-west-1.dream.io/i/065_-_AhrGPRl.gif
```

## Authors
Expand Down
19 changes: 10 additions & 9 deletions src/cuteme.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function (robot) {
const PUGME_SERVICE = 'https://dog.ceo/api'
const CATME_SERVICE = 'https://aws.random.cat/meow'

const CUTIES_LIMIT = parseInt(process.env.CUTIES_LIMIT, 10) || 5
const CUTES_LIMIT = parseInt(process.env.CUTES_LIMIT, 10) || 5

robot.respond(/pug me/i, async (msg) => {
await nFetch(`${PUGME_SERVICE}/breed/pug/images/random`)
Expand All @@ -34,8 +34,8 @@ module.exports = function (robot) {
robot.respond(/pug bomb( (\d+))?/i, async (msg) => {
const count = msg.match[2] || 5

if (count > CUTIES_LIMIT) {
msg.send(`The maximum number of pugs is limited to ${CUTIES_LIMIT}`)
if (count > CUTES_LIMIT) {
msg.send(`The maximum number of pugs is limited to ${CUTES_LIMIT}`)
return
}

Expand All @@ -48,15 +48,16 @@ module.exports = function (robot) {
robot.respond(/cat bomb( (\d+))?/i, async (msg) => {
const count = msg.match[2] || 5

if (count > CUTIES_LIMIT) {
msg.send(`The maximum number of cats is limited to ${CUTIES_LIMIT}`)
if (count > CUTES_LIMIT) {
msg.send(`The maximum number of cats is limited to ${CUTES_LIMIT}`)
return
}

for(let i = 0; i < count; i++){
for (let i = 0; i < count; i++) {
await nFetch(`${CATME_SERVICE}`)
.then(res => res.json())
.then(json => msg.send(json.file))
.catch(err => robot.logger.error(`Failed to request a cat: ${err}`))}
.then(res => res.json())
.then(json => msg.send(json.file))
.catch(err => robot.logger.error(`Failed to request a cat: ${err}`))
}
})
}

0 comments on commit 91e1176

Please sign in to comment.