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.

49 lines
1.3 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.get("endpoint") + '/gifs/search?api_key=' + this.get("apiKey") + '&q=' + term + '&limit=1';
  24. logger.debug("Requesting: %s", url.replace(this.get("apiKey"), '******'));
  25. return axios.get(url);
  26. }
  27. /* Commands
  28. * All methods starting with cmd_ will be parsed at initialization to expose those methods as commdands to the user
  29. */
  30. /**
  31. * Return the top item for the search terms.
  32. *
  33. * @param {...any} args
  34. */
  35. cmd_search(event, ...args) {
  36. return this.getGiphySearch(args[0])
  37. .then((response) => {
  38. // logger.debug("Giphy response: %o", response.data.data[0].url);
  39. return response.data.data[0].embed_url;
  40. })
  41. }
  42. }
  43. exports.module = new GiphyModule();