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.

61 lines
2.3 KiB

  1. /**
  2. * Module for interacting with a Szurubooru instance
  3. */
  4. let { AbstractModule } = require('../abstract');
  5. let { logger } = require('../../logging');
  6. let szurubooruClient = require('./client');
  7. class SzurubooruModule extends AbstractModule {
  8. constructor() {
  9. super(
  10. "Szurubooru",
  11. "Interact with a Szurubooru instance",
  12. "szurubooru"
  13. );
  14. this.helpAndUsage = `Usage:
  15. '!szurubooru <tag> [<tag>...]' display a random post that matches tags
  16. '!szurubooru config' prints config information for the room
  17. '!szurubooru config upload' toggles uploading images from room messages
  18. '!szurubooru iqdb' get an IQDB link for the last displayed post
  19. '!szurubooru need [<max tag count (5)>]' show a random post that needs additional tags
  20. '!szurubooru post <post_id>' retrieve a post and publish the image to the room
  21. '!szurubooru random [<tag>...]' display a random image from szurubooru that matches tags if preset
  22. '!szurubooru random update' update the random counts
  23. '!szurubooru recent [<days> (1)]' display a recent random image within the last <days>
  24. '!szurubooru related' display related posts to the last displayed post
  25. '!szurubooru tag <tag> [<tag>...]' add tags to the last displayed post
  26. '!szurubooru tag clone <post_id>' clone tags from <post_id> to the last displayed post
  27. '!szurubooru tag remove <tag> [<tag>...]' remove tags from the last displayed post
  28. '!szurubooru tags' list of all tags by popularity
  29. '!szurubooru tags <tag_stub> [<tag_stub>...]' list tags similar to each <tag_stub>
  30. '!szurubooru upload <url>' upload a remote file to szurubooru`;
  31. this.needConfig = true;
  32. this.defaultCommand = 'random';
  33. }
  34. postInit() {
  35. super.postInit();
  36. this.client = new szurubooruClient.Client(
  37. this.get("url"),
  38. this.get("username"),
  39. this.get("token")
  40. )
  41. }
  42. getConfigSensitiveFields() {
  43. return ["token"];
  44. }
  45. /* Commands
  46. * All methods starting with cmd_ will be parsed at initialization to expose those methods as commdands to the user
  47. */
  48. cmd_random(event, ...args) {
  49. return this.client.getRandomPost().then((data) => {
  50. logger.info("Random post: %o", data);
  51. return data;
  52. });
  53. }
  54. }
  55. exports.module = new SzurubooruModule();