You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
/**
|
|
* Giphy module
|
|
*/
|
|
|
|
let { AbstractModule } = require('./abstract');
|
|
let axios = require('axios');
|
|
let { logger } = require('../logging');
|
|
|
|
class GiphyModule extends AbstractModule {
|
|
constructor() {
|
|
super(
|
|
"Giphy",
|
|
"Insert Giphy Links/Media",
|
|
"giphy"
|
|
);
|
|
this.helpAndUsage = `Usage: !giphy itsworking
|
|
...`;
|
|
this.needConfig = true;
|
|
this.defaultCommand = 'search';
|
|
}
|
|
|
|
getConfigSensitiveFields() {
|
|
return ["apiKey"];
|
|
}
|
|
|
|
getGiphySearch(term) {
|
|
let url = this.get("endpoint") + '/gifs/search?api_key=' + this.get("apiKey") + '&q=' + term + '&limit=1';
|
|
logger.debug("Requesting: %s", url.replace(this.get("apiKey"), '******'));
|
|
return axios.get(url);
|
|
}
|
|
|
|
/* Commands
|
|
* All methods starting with cmd_ will be parsed at initialization to expose those methods as commdands to the user
|
|
*/
|
|
|
|
/**
|
|
* Return the top item for the search terms.
|
|
*
|
|
* @param {...any} args
|
|
*/
|
|
cmd_search(...args) {
|
|
return this.getGiphySearch(args[0])
|
|
.then((response) => {
|
|
// logger.debug("Giphy response: %o", response.data.data[0].url);
|
|
return response.data.data[0].embed_url;
|
|
})
|
|
}
|
|
}
|
|
|
|
exports.module = new GiphyModule();
|