Skip to content

Commit ec11f50

Browse files
committed
fixed giffy search query. sometimes times out tho??
1 parent 8988317 commit ec11f50

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

discord_bot.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,31 @@ function get_gif(tags, func) {
441441
"rating": config.rating,
442442
"format": "json"
443443
};
444+
var query = qs.stringify(params);
445+
444446
if (tags !== null) {
445-
params.tag = tags;
447+
query += "&q=" + tags.join('+')
446448
}
447449

448-
var query = qs.stringify(params);
449-
//wouldnt see request lib if defined at the top for some reason:\
450-
var request = require("request");
450+
//wouldnt see request lib if defined at the top for some reason:\
451+
var request = require("request");
452+
//console.log(query)
451453

452454
request(config.url + "?" + query, function (error, response, body) {
455+
//console.log(arguments)
453456
if (error || response.statusCode !== 200) {
454457
console.error("giphy: Got error: " + body);
458+
console.log(error);
459+
//console.log(response)
455460
}
456461
else {
457-
func(JSON.parse(body).data[0].id);
462+
var responseObj = JSON.parse(body)
463+
console.log(responseObj.data[0])
464+
if(responseObj.data.length){
465+
func(responseObj.data[0].id);
466+
} else {
467+
func(undefined);
468+
}
458469
}
459470
}.bind(this));
460471
}

0 commit comments

Comments
 (0)