Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Sticker): added Sticker #4909

Merged
merged 91 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
65c9ef2
Merge pull request #2 from discordjs/master
wonderlandpark Oct 16, 2020
afae3fa
feat(Sticker): add sticker
wonderlandpark Oct 16, 2020
1302c40
Merge branch 'sticker' of https://github.com/wonderlandpark/discord.j…
wonderlandpark Oct 16, 2020
3064e9d
types(Sticker): added sticker class
wonderlandpark Oct 16, 2020
b812434
fix(Sticker): fixed Sticker url for LOTTIE format
wonderlandpark Oct 16, 2020
8549512
types(Sticker): fixed type number
wonderlandpark Oct 16, 2020
3f798ad
feat(Stickers): removed debugging code
wonderlandpark Oct 16, 2020
bc2f51f
fix(Stickers): Added name tag
wonderlandpark Oct 16, 2020
1e27b34
fix(Stickers): Added name tag
wonderlandpark Oct 16, 2020
900dd5a
fix(Stickers): Added name tag
wonderlandpark Oct 16, 2020
3fcf80d
fix(Stickers): Added name tag
wonderlandpark Oct 16, 2020
1d45a5f
fix(Stickers): Added name tag
wonderlandpark Oct 16, 2020
6e51b44
fix(Stickers): Added name tag
wonderlandpark Oct 16, 2020
194fa61
Update typings/index.d.ts
wonderlandpark Oct 16, 2020
4c8aa42
fix(Stickers): Added name tag
wonderlandpark Oct 16, 2020
b313f46
style(Sticker): fixed createAt -> createdAt
wonderlandpark Oct 16, 2020
ee255ef
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
462e96f
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
85f0d28
Update typings/index.d.ts
wonderlandpark Oct 16, 2020
9a60d0f
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
ef61773
type(Sticker): Fixed typo issue
wonderlandpark Oct 16, 2020
4772101
type(Sticker): Fixed typo issue
wonderlandpark Oct 16, 2020
3dcc0be
Merge branch 'sticker' of https://github.com/wonderlandpark/discord.j…
wonderlandpark Oct 16, 2020
f60f28a
types: fixed mistake
wonderlandpark Oct 16, 2020
b7e1706
feat(Sticker): added type for Sticker#name
wonderlandpark Oct 16, 2020
630e78b
types(Sticker:URLOptions): fixed type error
wonderlandpark Oct 16, 2020
8136858
feat(Sticker): added Sticker in index.js and esm/discord.mjs
wonderlandpark Oct 16, 2020
691f0ba
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
d6463ff
Update typings/index.d.ts
wonderlandpark Oct 16, 2020
4225f77
Update typings/index.d.ts
wonderlandpark Oct 16, 2020
7643b44
Merge branch 'sticker' of https://github.com/wonderlandpark/discord.j…
wonderlandpark Oct 16, 2020
c580985
style(Sticker): add docstring
wonderlandpark Oct 16, 2020
f984117
typo(Sticker): sentance improve
wonderlandpark Oct 16, 2020
21e04b5
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
86252b8
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
e5f0abf
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
123e3b4
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
919b10d
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
9acd175
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
ce1e64a
Update src/structures/Sticker.js
wonderlandpark Oct 16, 2020
4b9a22d
style(Sticker): changed warn block to info block
wonderlandpark Oct 16, 2020
b81353a
Merge branch 'sticker' of https://github.com/wonderlandpark/discord.j…
wonderlandpark Oct 16, 2020
ef60c92
fix: makeStickerUrl function
wonderlandpark Oct 16, 2020
4dfeb21
Update src/util/Constants.js
wonderlandpark Oct 19, 2020
e463763
fix(Sticker): eslint error fix
wonderlandpark Oct 19, 2020
6315ac7
Update src/util/Constants.js
wonderlandpark Oct 20, 2020
3dd5f67
types(Sticker): fixed type error
wonderlandpark Oct 20, 2020
cef8ae9
style(Sticker): fixed grammer
wonderlandpark Oct 21, 2020
0c25ed3
feat(Sticker): removed stickerPreviewURL
wonderlandpark Oct 21, 2020
62eb04a
Merge branch 'sticker' of https://github.com/wonderlandpark/discord.j…
wonderlandpark Oct 21, 2020
74e42b2
Update typings/index.d.ts
wonderlandpark Oct 23, 2020
e734b1b
Update src/util/Constants.js
wonderlandpark Oct 23, 2020
d985fca
Update src/util/Constants.js
wonderlandpark Oct 23, 2020
1e1a33e
style(Sticker): renamed option passthrough to animated
wonderlandpark Oct 23, 2020
e215c91
types(Sticker): added INVALID_STICKER_SENT error code
wonderlandpark Nov 14, 2020
b7cca00
feat(Sticker): added INVALID_STICKER_SENT error code
wonderlandpark Nov 14, 2020
eb613d6
Update src/structures/Sticker.js
wonderlandpark Nov 15, 2020
d81c264
Update src/structures/Sticker.js
wonderlandpark Nov 15, 2020
3b4627e
feat(Sticker): array of tags
wonderlandpark Nov 15, 2020
ce65042
docs(Sticker): typo change
wonderlandpark Nov 15, 2020
ff6d50e
Update src/structures/Sticker.js
wonderlandpark Nov 15, 2020
6bfca6a
Update src/structures/Sticker.js
wonderlandpark Nov 15, 2020
5fe411e
Update typings/index.d.ts
wonderlandpark Nov 15, 2020
7aa13b7
Update src/structures/Sticker.js
wonderlandpark Nov 15, 2020
c48ae1a
Update typings/index.d.ts
wonderlandpark Nov 16, 2020
599f3a2
Update typings/index.d.ts
wonderlandpark Nov 16, 2020
6c4746e
Update src/util/Constants.js
wonderlandpark Nov 21, 2020
2359ba6
Merge branch 'master' into sticker
wonderlandpark Nov 21, 2020
4c1b977
types(Sticker): removed sticker preview url typing
wonderlandpark Nov 21, 2020
df88127
Merge branch 'sticker' of https://github.com/wonderlandpark/discord.j…
wonderlandpark Nov 21, 2020
a211c05
type(Sticker): removed trailing whitespace
wonderlandpark Nov 21, 2020
c8211bc
Update src/util/Constants.js
wonderlandpark Nov 29, 2020
7a59572
feat: not using passthrough, size params
wonderlandpark Nov 29, 2020
bacb71b
Update src/structures/Sticker.js
wonderlandpark Nov 30, 2020
f33d1d5
Update src/structures/Sticker.js
wonderlandpark Nov 30, 2020
e77fe3a
feat: removed makeStickerUrl function
wonderlandpark Nov 30, 2020
53fcec8
Update src/structures/Sticker.js
wonderlandpark Dec 29, 2020
bb69f63
fix: added missing StickerFormatTypes Constatns
wonderlandpark Jan 26, 2021
477595a
chore: defaulting the value of tags as an array
wonderlandpark Feb 1, 2021
b449871
types: sticker tags are always string[]
wonderlandpark Feb 6, 2021
9e2cc15
Update src/structures/Sticker.js
wonderlandpark Feb 6, 2021
53c741f
Merge branch 'master' into sticker
wonderlandpark Feb 14, 2021
567009d
chore: using getter for url
wonderlandpark Feb 15, 2021
f1204f4
types: added missing type
wonderlandpark Feb 15, 2021
91e5e2f
feat: using createEnum function
wonderlandpark Feb 15, 2021
9bf7f1b
Update typings/index.d.ts
wonderlandpark Feb 16, 2021
de7b1d7
Update src/structures/Sticker.js
wonderlandpark Apr 15, 2021
0e3d721
Update typings/index.d.ts
wonderlandpark Apr 15, 2021
7e1061d
types: added stickers at message class
wonderlandpark Apr 28, 2021
ec3d99e
style: missing semi
wonderlandpark Apr 28, 2021
46db4c7
Update typings/index.d.ts
wonderlandpark Apr 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esm/discord.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const {
ReactionEmoji,
RichPresenceAssets,
Role,
Sticker,
StoreChannel,
Team,
TeamMember,
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ module.exports = {
ReactionEmoji: require('./structures/ReactionEmoji'),
RichPresenceAssets: require('./structures/Presence').RichPresenceAssets,
Role: require('./structures/Role'),
Sticker: require('./structures/Sticker'),
StoreChannel: require('./structures/StoreChannel'),
Team: require('./structures/Team'),
TeamMember: require('./structures/TeamMember'),
Expand Down
12 changes: 12 additions & 0 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const MessageAttachment = require('./MessageAttachment');
const Embed = require('./MessageEmbed');
const Mentions = require('./MessageMentions');
const ReactionCollector = require('./ReactionCollector');
const Sticker = require('./Sticker');
const { Error, TypeError } = require('../errors');
const ReactionManager = require('../managers/ReactionManager');
const Collection = require('../util/Collection');
Expand Down Expand Up @@ -133,6 +134,17 @@ class Message extends Base {
}
}

/**
* A collection of stickers in the message
* @type {Collection<Snowflake, Sticker>}
*/
this.stickers = new Collection();
wonderlandpark marked this conversation as resolved.
Show resolved Hide resolved
if (data.stickers) {
wonderlandpark marked this conversation as resolved.
Show resolved Hide resolved
for (const sticker of data.stickers) {
this.stickers.set(sticker.id, new Sticker(this.client, sticker));
}
}
SpaceEEC marked this conversation as resolved.
Show resolved Hide resolved

/**
* The timestamp the message was sent at
* @type {number}
Expand Down
88 changes: 88 additions & 0 deletions src/structures/Sticker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use strict';

const Base = require('./Base');
const { StickerFormatTypes } = require('../util/Constants');
wonderlandpark marked this conversation as resolved.
Show resolved Hide resolved
const Snowflake = require('../util/Snowflake');

/**
* Represents a Sticker.
* @extends {Base}
*/
class Sticker extends Base {
wonderlandpark marked this conversation as resolved.
Show resolved Hide resolved
constructor(client, sticker) {
super(client);
/**
* The ID of the sticker
* @type {Snowflake}
*/
this.id = sticker.id;

/**
* The ID of the sticker's image
* @type {string}
*/
this.asset = sticker.asset;

/**
* The description of the sticker
* @type {string}
*/
this.description = sticker.description;

/**
* The format of the sticker
* @type {StickerFormatTypes}
*/
this.format = StickerFormatTypes[sticker.format_type];
wonderlandpark marked this conversation as resolved.
Show resolved Hide resolved

/**
* The name of the sticker
* @type {string}
*/
this.name = sticker.name;

/**
* The ID of the pack the sticker is from
* @type {Snowflake}
*/
this.packID = sticker.pack_id;

/**
* An array of tags for the sticker, if any
* @type {string[]}
*/
this.tags = sticker.tags?.split(', ') ?? [];
}

/**
* The timestamp the sticker was created at
wonderlandpark marked this conversation as resolved.
Show resolved Hide resolved
* @type {number}
* @readonly
*/
get createdTimestamp() {
return Snowflake.deconstruct(this.id).timestamp;
}

/**
* The time the sticker was created at
* @type {Date}
* @readonly
*/
get createdAt() {
return new Date(this.createdTimestamp);
}

/**
* A link to the sticker
* <info>If the sticker's format is LOTTIE, it returns the URL of the Lottie json file.
* Lottie json files must be converted in order to be displayed in Discord.</info>
* @type {string}
*/
get url() {
wonderlandpark marked this conversation as resolved.
Show resolved Hide resolved
return `${this.client.options.http.cdn}/stickers/${this.id}/${this.asset}.${
this.format === 'LOTTIE' ? 'json' : 'png'
}`;
}
}

module.exports = Sticker;
11 changes: 11 additions & 0 deletions src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function makeImageUrl(root, { format = 'webp', size } = {}) {
if (size && !AllowedImageSizes.includes(size)) throw new RangeError('IMAGE_SIZE', size);
return `${root}.${format}${size ? `?size=${size}` : ''}`;
}

/**
* Options for Image URLs.
* @typedef {Object} ImageURLOptions
Expand Down Expand Up @@ -671,6 +672,7 @@ exports.APIErrors = {
INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT: 50036,
INVALID_API_VERSION: 50041,
CANNOT_DELETE_COMMUNITY_REQUIRED_CHANNEL: 50074,
INVALID_STICKER_SENT: 50081,
REACTION_BLOCKED: 90001,
RESOURCE_OVERLOADED: 130000,
};
Expand Down Expand Up @@ -709,6 +711,15 @@ exports.WebhookTypes = [
'Channel Follower',
];

/**
* The value set for a sticker's type:
* * PNG
* * APNG
* * LOTTIE
* @typedef {string} StickerFormatTypes
*/
exports.StickerFormatTypes = createEnum([null, 'PNG', 'APNG', 'LOTTIE']);

/**
* An overwrite type:
* * role
Expand Down
25 changes: 24 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ declare enum ChannelType {
unknown = 7,
}

declare enum StickerFormatTypes {
PNG = 1,
APNG = 2,
LOTTIE = 3,
}

declare enum OverwriteTypes {
role = 0,
member = 1,
Expand Down Expand Up @@ -524,7 +530,8 @@ declare module 'discord.js' {
MessageTypes: MessageType[];
SystemMessageTypes: SystemMessageType[];
ActivityTypes: ActivityType[];
OverwriteTypes: OverwriteTypes;
StickerFormatTypes: typeof StickerFormatTypes;
OverwriteTypes: typeof OverwriteTypes;
ExplicitContentFilterLevels: ExplicitContentFilterLevel[];
DefaultMessageNotifications: DefaultMessageNotifications[];
VerificationLevels: VerificationLevel[];
Expand Down Expand Up @@ -979,6 +986,7 @@ declare module 'discord.js' {
public readonly pinnable: boolean;
public pinned: boolean;
public reactions: ReactionManager;
public stickers: Collection<Snowflake, Sticker>;
public system: boolean;
public tts: boolean;
public type: MessageType;
Expand Down Expand Up @@ -2204,6 +2212,7 @@ declare module 'discord.js' {
INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT: 50036;
INVALID_API_VERSION: 50041;
CANNOT_DELETE_COMMUNITY_REQUIRED_CHANNEL: 50074;
INVALID_STICKER_SENT: 50081;
REACTION_BLOCKED: 90001;
RESOURCE_OVERLOADED: 130000;
}
Expand Down Expand Up @@ -3251,6 +3260,20 @@ declare module 'discord.js' {

type Status = number;

export class Sticker extends Base {
constructor(client: Client, data: object);
public asset: string;
public readonly createdTimestamp: number;
public readonly createdAt: Date;
public description: string;
public format: StickerFormatTypes;
public id: Snowflake;
public name: string;
public packID: Snowflake;
public tags: string[];
public readonly url: string;
}

interface StreamOptions {
type?: StreamType;
seek?: number;
Expand Down