Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project #117

Open
wants to merge 6 commits into
base: upgrade-dependencies
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:9.4
FROM node:12.10

# Create app directory
WORKDIR /usr/src/app
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The docker-compose setup is configured to reboot the bot when any local file cha
Leonel uses MongoDB to store specific information about users, you can create the user accounts by running:

```bash
$ docker-compose run bot yarn db:seed
$ docker-compose run bot npm run db:seed
```

This will execute the script [db:seed][db-seed] in a container to create all the users from Slack's API.
Expand All @@ -52,19 +52,19 @@ This will execute the script [db:seed][db-seed] in a container to create all the
You can run `ava` tests in a container, by running:

```bash
$ docker-compose run bot yarn test
$ docker-compose run bot npm test
```

If you want for tests to watch your files, you can run:

```bash
$ docker-compose run bot yarn test -- -w
$ docker-compose run bot npm test -- -w
```

If you want to modify the `DEBUG` env var, you can run:

```bash
$ docker-compose run -e DEBUG="" bot yarn test -- -w
$ docker-compose run -e DEBUG="" bot npm test -- -w
```

#### Shutting Down
Expand All @@ -82,20 +82,20 @@ $ docker-compose down
All environment variables in [example env file][env] should be set before running Leonel.

Other requirements:
- Yarn
- NodeJS 7.7.x
- Npm
- NodeJS 12.10.x
- MongoDB

Install dependencies:

```bash
$ yarn
$ npm install
```

Start leonel:

```bash
$ yarn start
$ npm start
```

Things are looking good if the console prints something like:
Expand All @@ -107,14 +107,14 @@ Things are looking good if the console prints something like:
bot:main Estamos coneptados al Eslá
```

We have added `yarn start:watch` script which uses Nodemon for convenience during development. This restarts the bot after any change done to source files.
We have added `npm run start:watch` script which uses Nodemon for convenience during development. This restarts the bot after any change done to source files.

#### Seed users

Leonel uses MongoDB to store specific information about users, you can create the user accounts by running:

```bash
$ yarn db:seed
$ npm run db:seed
```

This will execute the script [db:seed][db-seed] to create all the users from Slack's API.
Expand All @@ -125,13 +125,13 @@ This will execute the script [db:seed][db-seed] to create all the users from Sla
We use ava for unit and integration testing, you can run tests by typing:

```bash
$ yarn test
$ npm test
```

You can watch files and run tests when any changes are detected by using:

```bash
$ yarn test -- -w
$ npm test -- -w
```

### JavaScript Style
Expand All @@ -141,7 +141,7 @@ In order to minimize code style differences, we have adopted the [StandardJS][st
**note: you can check compatibility by running tests**

```bash
$ yarn test
$ npm test
```

**note: you may also be able to automatically fix any style issues with the `standard` tool**
Expand Down
17 changes: 17 additions & 0 deletions constants/coinsSymbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const coins = Object.freeze({
BTC: 'bitcoin',
BCH: 'bitcoin-cash',
ETH: 'ethereum',
ETC: 'ethereum-classic',
LTC: 'litecoin',
XRP: 'ripple',
ADA: 'cardano',
IOT: 'iota',
XEM: 'nem',
XLM: 'stellar',
DASH: 'dash'
})

module.exports = coins
12 changes: 7 additions & 5 deletions lib/coinPrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
const rp = require('request-promise')
const logError = require('debug')('bot:error')

const coinsSymbols = require('./../constants/coinsSymbols')

function coinPrice (bot, message) {
const re = /(BTC|BCH|ETH|LTC|XRP|ADA|IOT|XEM|XLM|DASH)/gi
const coin = message.text.match(re) ? message.text.match(re)[0].toUpperCase() : null
const coinSymbol = message.text.match(re) ? message.text.match(re)[0].toUpperCase() : null

if (coin) {
return rp(`http://www.coincap.io/page/${coin}`)
if (coinSymbol) {
return rp(`https://api.coincap.io/v2/rates/${coinsSymbols[coinSymbol]}`)
.then((coin) => {
const coinInfo = JSON.parse(coin)
return bot.reply(message, `*${coinInfo.id} = ${coinInfo.price}* _Price from coincap.io API_`)
const { data: coinInfo } = JSON.parse(coin)
return bot.reply(message, `*${coinInfo.id} = ${parseFloat(coinInfo.rateUsd, 10).toFixed(2)} USD* _Price from coincap.io API_`)
})
.catch(err => {
logError('caught', err)
Expand Down
Loading