Baphomet is the dedicated bot for nulloctet matrix
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.

45 lines
1.2 KiB

  1. /**
  2. * Giphy module
  3. */
  4. let { AbstractModule } = require('./abstract');
  5. let axios = require('axios');
  6. let { logger } = require('../logging');
  7. class GiphyModule extends AbstractModule {
  8. constructor() {
  9. super(
  10. "Giphy",
  11. "Insert Giphy Links/Media",
  12. "giphy"
  13. );
  14. this.helpAndUsage = `Usage: !giphy itsworking
  15. ...`;
  16. this.needConfig = true;
  17. this.defaultCommand = 'search';
  18. }
  19. getConfigSensitiveFields() {
  20. return ["apiKey"];
  21. }
  22. getGiphySearch(term) {
  23. let url = this._config.endpoint + '/gifs/search?api_key=' + this._config.apiKey + '&q=' + term + '&limit=1';
  24. logger.debug("Requesting: %s", url.replace(this._config.apiKey, '******'));
  25. return axios.get(url);
  26. }
  27. /**
  28. * Return the top item for the search terms.
  29. *
  30. * @param {...any} args
  31. */
  32. cmd_search(...args) {
  33. return this.getGiphySearch(args[0])
  34. .then((response) => {
  35. // logger.debug("Giphy response: %o", response.data.data[0].url);
  36. return response.data.data[0].embed_url;
  37. })
  38. }
  39. }
  40. exports.module = new GiphyModule();