Skip to content

Commit

Permalink
Fixed a bug in the direct message responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rouffer committed May 17, 2017
1 parent 2cfc277 commit dccc3bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "slack-googlebot",
"version": "1.0.3",
"version": "1.0.4",
"description": "A Slack bot that reminds people to google things before asking their co-workers",
"keywords": [
"Slack",
Expand Down
8 changes: 7 additions & 1 deletion src/googlebot.js
Expand Up @@ -48,7 +48,13 @@ const googlebot = (botToken, options = {}) => {
!isDirectMessage) {
msgOptions.attachments[0].text = 'What do you want?';
} else {
var searchString = event.text.substr(event.text.indexOf(' ') + 1);
var searchString;
if (isDirectMessage) {
searchString = event.text;
} else {
searchString = event.text.substr(event.text.indexOf(' ') + 1);
}

const response = pickRandom(allowedResponses);
msgOptions.attachments[0].pretext = response.text;

Expand Down
26 changes: 1 addition & 25 deletions src/utils.js
Expand Up @@ -44,28 +44,4 @@ export const filterResponsesByCategories = (responses, categories) => responses.
return false;
});

export const pickRandom = arr => arr[Math.floor(Math.random() * arr.length)];

export const googleSearch = (searchString) => {
return new Promise((resolve, reject) => {
var request = require('request');

// Example: https://www.google.ca/search?q=what+is+today%27s+date&oq=what+is+today%27s+date
var queryStringFields = {
q: searchString
};
var requestArgs = {
url: 'https://www.google.com/search',
qs: queryStringFields
};

request(requestArgs,
function(err, response, body) {
if (err) {
reject();
} else {
resolve(body);
}
});
});
};
export const pickRandom = arr => arr[Math.floor(Math.random() * arr.length)];

0 comments on commit dccc3bf

Please sign in to comment.