This commit is contained in:
tungdo0602
2025-06-30 22:19:34 +07:00
parent da07ddabee
commit 2e4542c069
6 changed files with 182 additions and 184 deletions

View File

@@ -41,7 +41,7 @@
"singleQuote": true, "singleQuote": true,
"quoteProps": "as-needed", "quoteProps": "as-needed",
"trailingComma": "all", "trailingComma": "all",
"endOfLine": "auto", "endOfLine": "lf",
"arrowParens": "avoid" "arrowParens": "avoid"
} }
], ],
@@ -153,7 +153,7 @@
"error", "error",
"$this" "$this"
], ],
"eol-last": "warn", "eol-last": "error",
"func-names": "error", "func-names": "error",
"func-name-matching": "error", "func-name-matching": "error",
"func-style": [ "func-style": [
@@ -203,7 +203,7 @@
], ],
"no-new-object": "error", "no-new-object": "error",
"no-spaced-func": "error", "no-spaced-func": "error",
"no-trailing-spaces": "warn", "no-trailing-spaces": "error",
"no-unneeded-ternary": "error", "no-unneeded-ternary": "error",
"no-whitespace-before-property": "error", "no-whitespace-before-property": "error",
"nonblock-statement-body-position": "error", "nonblock-statement-body-position": "error",

View File

@@ -2,6 +2,6 @@
"singleQuote": true, "singleQuote": true,
"printWidth": 120, "printWidth": 120,
"trailingComma": "all", "trailingComma": "all",
"endOfLine": "auto", "endOfLine": "lf",
"arrowParens": "avoid" "arrowParens": "avoid"
} }

View File

@@ -1,51 +1,51 @@
'use strict'; 'use strict';
const BaseMessageComponent = require('./BaseMessageComponent'); const BaseMessageComponent = require('./BaseMessageComponent');
const { MessageComponentTypes } = require('../util/Constants'); const { MessageComponentTypes } = require('../util/Constants');
class ContainerComponent extends BaseMessageComponent { class ContainerComponent extends BaseMessageComponent {
/** /**
* @typedef {MessageActionRow|TextDisplayComponent|SectionComponent|MediaGalleryComponent|SeparatorComponent|FileComponent} ContainerComponents * @typedef {MessageActionRow|TextDisplayComponent|SectionComponent|MediaGalleryComponent|SeparatorComponent|FileComponent} ContainerComponents
* @property {ContainerComponents[]} [components] Components of the type action row, text display, section, media gallery, separator, or file * @property {ContainerComponents[]} [components] Components of the type action row, text display, section, media gallery, separator, or file
* @property {Number} [accent_color] Color for the accent on the container as RGB from 0x000000 to 0xFFFFFF * @property {Number} [accent_color] Color for the accent on the container as RGB from 0x000000 to 0xFFFFFF
* @property {Boolean} [spoiler] Whether the container should be a spoiler (or blurred out). Defaults to false. * @property {Boolean} [spoiler] Whether the container should be a spoiler (or blurred out). Defaults to false.
*/ */
/** /**
* @param {ContainerComponent | APIContainerComponent} [data={}] The data * @param {ContainerComponent | APIContainerComponent} [data={}] The data
*/ */
constructor(data = {}) { constructor(data = {}) {
super({ type: 'CONTAINER' }, data); super({ type: 'CONTAINER' }, data);
/** /**
* Components of the type action row, text display, section, media gallery, separator, or file * Components of the type action row, text display, section, media gallery, separator, or file
* @type {ContainerComponents[]} * @type {ContainerComponents[]}
*/ */
this.components = data.components?.map(c => BaseMessageComponent.create(c)) ?? []; this.components = data.components?.map(c => BaseMessageComponent.create(c)) ?? [];
/** /**
* Color for the accent on the container as RGB from 0x000000 to 0xFFFFFF * Color for the accent on the container as RGB from 0x000000 to 0xFFFFFF
* @type {Number} * @type {Number}
*/ */
this.accent_color = data.accent_color ?? null; this.accent_color = data.accent_color ?? null;
/** /**
* Whether the container should be a spoiler (or blurred out). Defaults to false. * Whether the container should be a spoiler (or blurred out). Defaults to false.
* @type {Boolean} * @type {Boolean}
*/ */
this.spoiler = data.spoiler ?? false; this.spoiler = data.spoiler ?? false;
} }
/** /**
* @returns {APIContainerComponent} * @returns {APIContainerComponent}
*/ */
toJSON() { toJSON() {
return { return {
type: MessageComponentTypes[this.type], type: MessageComponentTypes[this.type],
components: this.components.map(c => c.toJSON()), components: this.components.map(c => c.toJSON()),
accent_color: this.accent_color, accent_color: this.accent_color,
spoiler: this.spoiler, spoiler: this.spoiler,
}; };
} }
} }
module.exports = ContainerComponent; module.exports = ContainerComponent;

View File

@@ -1,46 +1,44 @@
'use strict'; 'use strict';
const BaseMessageComponent = require('./BaseMessageComponent'); const BaseMessageComponent = require('./BaseMessageComponent');
const UnfurledMediaItem = require('./UnfurledMediaItem'); const UnfurledMediaItem = require('./UnfurledMediaItem');
const { MessageComponentTypes } = require('../util/Constants'); const { MessageComponentTypes } = require('../util/Constants');
class FileComponent extends BaseMessageComponent {
class FileComponent extends BaseMessageComponent { /**
/** * @property {UnfurledMediaItem} [file] This unfurled media item is unique in that it only supports attachment references using the attachment://<filename> syntax
* @property {UnfurledMediaItem} [file] This unfurled media item is unique in that it only supports attachment references using the attachment://<filename> syntax * @property {Boolean} [spoiler] Whether the container should be a spoiler (or blurred out). Defaults to false.
* @property {Boolean} [spoiler] Whether the container should be a spoiler (or blurred out). Defaults to false. */
*/
/**
/** * @param {FileComponent | APIFileComponent} [data={}] The data
* @param {FileComponent | APIFileComponent} [data={}] The data */
*/ constructor(data = {}) {
constructor(data = {}) { super({ type: 'FILE' }, data);
super({ type: 'FILE' }, data);
/**
/** * This unfurled media item is unique in that it only supports attachment references using the attachment://<filename> syntax
* This unfurled media item is unique in that it only supports attachment references using the attachment://<filename> syntax * @type {UnfurledMediaItem}
* @type {UnfurledMediaItem} */
*/ this.file = new UnfurledMediaItem(data.file);
this.file = new UnfurledMediaItem(data.file);
/**
/** * Whether the container should be a spoiler (or blurred out). Defaults to false.
* Whether the container should be a spoiler (or blurred out). Defaults to false. * @type {Boolean}
* @type {Boolean} */
*/ this.spoiler = data.spoiler ?? false;
this.spoiler = data.spoiler ?? false; }
}
/**
* @returns {APIFileComponent}
/** */
* @returns {APIFileComponent} toJSON() {
*/ return {
toJSON() { type: MessageComponentTypes[this.type],
return { file: this.content,
type: MessageComponentTypes[this.type], spoiler: this.spoiler,
file: this.content, };
spoiler: this.spoiler, }
}; }
}
} module.exports = FileComponent;
module.exports = FileComponent;

View File

@@ -1,36 +1,36 @@
'use strict'; 'use strict';
const BaseMessageComponent = require('./BaseMessageComponent'); const BaseMessageComponent = require('./BaseMessageComponent');
const MediaGalleryItem = require('./MediaGalleryItem'); const MediaGalleryItem = require('./MediaGalleryItem');
const { MessageComponentTypes } = require('../util/Constants'); const { MessageComponentTypes } = require('../util/Constants');
class MediaGalleryComponent extends BaseMessageComponent { class MediaGalleryComponent extends BaseMessageComponent {
/** /**
* @property {MediaGalleryItem[]} [items] 1 to 10 media gallery items * @property {MediaGalleryItem[]} [items] 1 to 10 media gallery items
*/ */
/** /**
* @param {MediaGalleryComponent | APIMediaGalleryComponent} [data={}] The data * @param {MediaGalleryComponent | APIMediaGalleryComponent} [data={}] The data
*/ */
constructor(data = {}) { constructor(data = {}) {
super({ type: 'MEDIA_GALLERY' }, data); super({ type: 'MEDIA_GALLERY' }, data);
/** /**
* 1 to 10 media gallery items * 1 to 10 media gallery items
* @type {MediaGalleryItem[]} * @type {MediaGalleryItem[]}
*/ */
this.items = data.items?.map(item => new MediaGalleryItem(item)) ?? []; this.items = data.items?.map(item => new MediaGalleryItem(item)) ?? [];
} }
/** /**
* @returns {APIMediaGalleryComponent} * @returns {APIMediaGalleryComponent}
*/ */
toJSON() { toJSON() {
return { return {
type: MessageComponentTypes[this.type], type: MessageComponentTypes[this.type],
items: this.items.map(c => c.toJSON()), items: this.items.map(c => c.toJSON()),
}; };
} }
} }
module.exports = MediaGalleryComponent; module.exports = MediaGalleryComponent;

View File

@@ -1,47 +1,47 @@
'use strict'; 'use strict';
const UnfurledMediaItem = require('./UnfurledMediaItem'); const UnfurledMediaItem = require('./UnfurledMediaItem');
class MediaGalleryItem { class MediaGalleryItem {
/** /**
* @property {UnfurledMediaItem} [media] A url or attachment * @property {UnfurledMediaItem} [media] A url or attachment
* @property {String} [description] Alt text for the media, max 1024 characters * @property {String} [description] Alt text for the media, max 1024 characters
* @property {Boolean} [spoiler] Whether the media should be a spoiler (or blurred out). Defaults to false * @property {Boolean} [spoiler] Whether the media should be a spoiler (or blurred out). Defaults to false
*/ */
/** /**
* @param {MediaGalleryItem | APIMediaGalleryItem} [data={}] The data * @param {MediaGalleryItem | APIMediaGalleryItem} [data={}] The data
*/ */
constructor(data = {}) { constructor(data = {}) {
/** /**
* A url or attachment * A url or attachment
* @type {UnfurledMediaItem} * @type {UnfurledMediaItem}
*/ */
this.media = new UnfurledMediaItem(data.media); this.media = new UnfurledMediaItem(data.media);
/** /**
* Alt text for the media, max 1024 characters * Alt text for the media, max 1024 characters
* @type {String} * @type {String}
*/ */
this.description = data.description ?? null; this.description = data.description ?? null;
/** /**
* Whether the media should be a spoiler (or blurred out). Defaults to false * Whether the media should be a spoiler (or blurred out). Defaults to false
* @type {Boolean} * @type {Boolean}
*/ */
this.spoiler = data.spoiler ?? false; this.spoiler = data.spoiler ?? false;
} }
/** /**
* @returns {APIMediaGalleryItem} * @returns {APIMediaGalleryItem}
*/ */
toJSON() { toJSON() {
return { return {
media: this.media.toJSON(), media: this.media.toJSON(),
description: this.description, description: this.description,
spoiler: this.spoiler, spoiler: this.spoiler,
}; };
} }
} }
module.exports = MediaGalleryItem; module.exports = MediaGalleryItem;