feat(Sticker): add support for gif stickers (#9038)

* feat(Sticker): add support for gif stickers

* chore: upgrade discord-api-types

* refactor: requested changes
This commit is contained in:
Almeida
2023-01-13 15:29:35 +00:00
committed by GitHub
parent 8c265b628d
commit 6a9875da05
7 changed files with 33 additions and 15 deletions

View File

@@ -56,7 +56,7 @@
"@discordjs/util": "workspace:^",
"@sapphire/snowflake": "^3.4.0",
"@types/ws": "^8.5.4",
"discord-api-types": "^0.37.27",
"discord-api-types": "^0.37.28",
"fast-deep-equal": "^3.1.3",
"lodash.snakecase": "^4.1.1",
"tslib": "^2.4.1",

View File

@@ -1,9 +1,10 @@
'use strict';
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { Routes, StickerFormatType } = require('discord-api-types/v10');
const { Routes } = require('discord-api-types/v10');
const Base = require('./Base');
const { DiscordjsError, ErrorCodes } = require('../errors');
const { StickerFormatExtensionMap } = require('../util/Constants');
/**
* Represents a Sticker.
@@ -164,7 +165,7 @@ class Sticker extends Base {
* @readonly
*/
get url() {
return this.client.rest.cdn.sticker(this.id, this.format === StickerFormatType.Lottie ? 'json' : 'png');
return this.client.rest.cdn.sticker(this.id, StickerFormatExtensionMap[this.format]);
}
/**

View File

@@ -1,6 +1,6 @@
'use strict';
const { ChannelType, MessageType, ComponentType } = require('discord-api-types/v10');
const { ChannelType, MessageType, ComponentType, ImageFormat, StickerFormatType } = require('discord-api-types/v10');
/**
* Max bulk deletable message age
@@ -138,6 +138,21 @@ exports.SelectMenuTypes = [
ComponentType.ChannelSelect,
];
/**
* A mapping between sticker formats and their respective image formats.
* * {@link StickerFormatType.PNG} -> {@link ImageFormat.PNG}
* * {@link StickerFormatType.APNG} -> {@link ImageFormat.PNG}
* * {@link StickerFormatType.Lottie} -> {@link ImageFormat.Lottie}
* * {@link StickerFormatType.GIF} -> {@link ImageFormat.GIF}
* @typedef {Object} StickerFormatExtensionMap
*/
exports.StickerFormatExtensionMap = {
[StickerFormatType.PNG]: ImageFormat.PNG,
[StickerFormatType.APNG]: ImageFormat.PNG,
[StickerFormatType.Lottie]: ImageFormat.Lottie,
[StickerFormatType.GIF]: ImageFormat.GIF,
};
/**
* @typedef {Object} Constants Constants that can be used in an enum or object-like way.
* @property {number} MaxBulkDeletableMessageAge Max bulk deletable message age
@@ -147,4 +162,5 @@ exports.SelectMenuTypes = [
* @property {ThreadChannelTypes} ThreadChannelTypes The types of channels that are threads
* @property {VoiceBasedChannelTypes} VoiceBasedChannelTypes The types of channels that are voice-based
* @property {SelectMenuTypes} SelectMenuTypes The types of components that are select menus.
* @property {Object} StickerFormatExtensionMap A mapping between sticker formats and their respective image formats.
*/

View File

@@ -153,6 +153,7 @@ import {
ForumLayoutType,
ApplicationRoleConnectionMetadataType,
APIApplicationRoleConnectionMetadata,
ImageFormat,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
@@ -3445,6 +3446,7 @@ export const Constants: {
ThreadChannelTypes: ThreadChannelType[];
VoiceBasedChannelTypes: VoiceBasedChannelTypes[];
SelectMenuTypes: SelectMenuType[];
StickerFormatExtensionMap: Record<StickerFormatType, ImageFormat>;
};
export const version: string;