/** * 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(event, ...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();