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

View File

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

View File

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

View File

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

View File

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

View File

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