Skip to content

Commit

Permalink
Missing some cleanup of msg sends
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Mutt committed Mar 12, 2021
1 parent 62c690c commit bc530f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hubot-plusplus-expanded",
"version": "1.2.1",
"version": "1.2.2",
"description": "A hubot script for micro praise",
"main": "index.js",
"engines": {
Expand Down
35 changes: 15 additions & 20 deletions src/plusplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,38 +194,33 @@ module.exports = function plusPlus(robot) {
}

function tellHowMuchPointsAreWorth(msg) {
msg.send("getting the quote");
const promises = [];
promises.push(
axios({
url: 'https://www.marketwatch.com/investing/stock/okta',
transformResponse: [data => {
transformResponse: [(data) => {
const startIndex = data.indexOf('<meta name="price" content="');
const oktaStockQuota = data.substring(startIndex + 28, startIndex + 35);
return oktaStockQuota;
}]
}).then(response => {
return response.data;
})
}],
}).then((response) => response.data),
);
promises.push(
axios({
url: 'https://api.coindesk.com/v1/bpi/currentprice/ARS.json'
}).then(resp => {
const bitcoin = resp.data.bpi.USD.rate_float;
const ars = resp.data.bpi.ARS.rate_float;
const satoshi = bitcoin / 1e8;
return { bitcoin, ars, satoshi };
})
}).then((resp) => {
const bitcoin = resp.data.bpi.USD.rate_float;
const ars = resp.data.bpi.ARS.rate_float;
const satoshi = bitcoin / 1e8;
return { bitcoin, ars, satoshi };
}),
);

Promise.all(promises).then(promise => {
// eslint-disable-next-line
return msg.send(`A bitcoin is worth ${promise[1].bitcoin} USD right now (${promise[1].ars} ARS), a satoshi is about ${promise[1].satoshi}, Okta is worth ${promise[0]}, and ${msg.message._robot_name} points are worth nothing!`);
}).catch(err => {
msg.send(err);
return msg.send(`Seems like we are having trouble getting some data... Don\'t worry, though, your ${msg.message._robot_name} points are still worth nothing!`);
});

Promise.all(promises).then((promise) => msg.send(
// eslint-disable-next-line no-underscore-dangle
`A bitcoin is worth ${promise[1].bitcoin} USD right now (${promise[1].ars} ARS), a satoshi is about ${promise[1].satoshi}, Okta is worth ${promise[0]}, and ${msg.message._robot_name} points are worth nothing!`
// eslint-disable-next-line no-underscore-dangle
)).catch(() => msg.send(`Seems like we are having trouble getting some data... Don't worry, though, your ${msg.message._robot_name} points are still worth nothing!`));
}

async function respondWithLeaderLoserBoard(msg) {
Expand Down

0 comments on commit bc530f9

Please sign in to comment.