From 40726db722c7851f4096cda29667ea4ee89da98b Mon Sep 17 00:00:00 2001 From: Almeida Date: Sun, 12 Nov 2023 21:56:10 +0000 Subject: [PATCH] refactor: use formatters (#9956) * refactor: use formatters * fix: imports * fix: imports pt.2 --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../discord.js/src/structures/BaseChannel.js | 4 +-- .../discord.js/src/structures/DMChannel.js | 2 +- packages/discord.js/src/structures/Emoji.js | 3 +- packages/discord.js/src/structures/Message.js | 2 +- packages/discord.js/src/structures/Role.js | 3 +- packages/discord.js/src/structures/User.js | 2 +- packages/discord.js/src/util/Formatters.js | 2 +- packages/discord.js/typings/index.d.ts | 36 ++++++++++--------- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/packages/discord.js/src/structures/BaseChannel.js b/packages/discord.js/src/structures/BaseChannel.js index 473a5133e..2b179d357 100644 --- a/packages/discord.js/src/structures/BaseChannel.js +++ b/packages/discord.js/src/structures/BaseChannel.js @@ -1,6 +1,6 @@ 'use strict'; -const { channelLink } = require('@discordjs/builders'); +const { channelLink, channelMention } = require('@discordjs/formatters'); const { DiscordSnowflake } = require('@sapphire/snowflake'); const { ChannelType, Routes } = require('discord-api-types/v10'); const Base = require('./Base'); @@ -89,7 +89,7 @@ class BaseChannel extends Base { * console.log(`Hello from ${channel}!`); */ toString() { - return `<#${this.id}>`; + return channelMention(this.id); } /** diff --git a/packages/discord.js/src/structures/DMChannel.js b/packages/discord.js/src/structures/DMChannel.js index 2c917c454..ee466442a 100644 --- a/packages/discord.js/src/structures/DMChannel.js +++ b/packages/discord.js/src/structures/DMChannel.js @@ -1,6 +1,6 @@ 'use strict'; -const { userMention } = require('@discordjs/builders'); +const { userMention } = require('@discordjs/formatters'); const { ChannelType } = require('discord-api-types/v10'); const { BaseChannel } = require('./BaseChannel'); const TextBasedChannel = require('./interfaces/TextBasedChannel'); diff --git a/packages/discord.js/src/structures/Emoji.js b/packages/discord.js/src/structures/Emoji.js index ad5378f3e..92232f9dc 100644 --- a/packages/discord.js/src/structures/Emoji.js +++ b/packages/discord.js/src/structures/Emoji.js @@ -1,6 +1,7 @@ 'use strict'; const process = require('node:process'); +const { formatEmoji } = require('@discordjs/formatters'); const { DiscordSnowflake } = require('@sapphire/snowflake'); const Base = require('./Base'); @@ -97,7 +98,7 @@ class Emoji extends Base { * reaction.message.channel.send(`The emoji used was: ${reaction.emoji}`); */ toString() { - return this.id ? `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>` : this.name; + return this.id ? formatEmoji(this.id, this.animated) : this.name; } toJSON() { diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index 679b34a8d..adb5ed541 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -1,7 +1,7 @@ 'use strict'; -const { messageLink } = require('@discordjs/builders'); const { Collection } = require('@discordjs/collection'); +const { messageLink } = require('@discordjs/formatters'); const { DiscordSnowflake } = require('@sapphire/snowflake'); const { InteractionType, diff --git a/packages/discord.js/src/structures/Role.js b/packages/discord.js/src/structures/Role.js index 03b0d6f41..06cbac60b 100644 --- a/packages/discord.js/src/structures/Role.js +++ b/packages/discord.js/src/structures/Role.js @@ -1,5 +1,6 @@ 'use strict'; +const { roleMention } = require('@discordjs/formatters'); const { DiscordSnowflake } = require('@sapphire/snowflake'); const { PermissionFlagsBits } = require('discord-api-types/v10'); const Base = require('./Base'); @@ -452,7 +453,7 @@ class Role extends Base { */ toString() { if (this.id === this.guild.id) return '@everyone'; - return `<@&${this.id}>`; + return roleMention(this.id); } toJSON() { diff --git a/packages/discord.js/src/structures/User.js b/packages/discord.js/src/structures/User.js index 3cf0c57f0..748224ac7 100644 --- a/packages/discord.js/src/structures/User.js +++ b/packages/discord.js/src/structures/User.js @@ -1,6 +1,6 @@ 'use strict'; -const { userMention } = require('@discordjs/builders'); +const { userMention } = require('@discordjs/formatters'); const { calculateUserDefaultAvatarIndex } = require('@discordjs/rest'); const { DiscordSnowflake } = require('@sapphire/snowflake'); const Base = require('./Base'); diff --git a/packages/discord.js/src/util/Formatters.js b/packages/discord.js/src/util/Formatters.js index bd93a36a3..2dd0d6245 100644 --- a/packages/discord.js/src/util/Formatters.js +++ b/packages/discord.js/src/util/Formatters.js @@ -19,7 +19,7 @@ const { TimestampStyles, underscore, userMention, -} = require('@discordjs/builders'); +} = require('@discordjs/formatters'); /** * Formats an application command name and id into an application command mention. diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 8614f2cea..ed748734d 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1,19 +1,8 @@ import { ActionRowBuilder as BuilderActionRow, MessageActionRowComponentBuilder, - blockQuote, - bold, ButtonBuilder as BuilderButtonComponent, - channelMention, - codeBlock, EmbedBuilder as BuildersEmbed, - formatEmoji, - hideLinkEmbed, - hyperlink, - inlineCode, - italic, - quote, - roleMention, ChannelSelectMenuBuilder as BuilderChannelSelectMenuComponent, MentionableSelectMenuBuilder as BuilderMentionableSelectMenuComponent, RoleSelectMenuBuilder as BuilderRoleSelectMenuComponent, @@ -21,12 +10,6 @@ import { UserSelectMenuBuilder as BuilderUserSelectMenuComponent, TextInputBuilder as BuilderTextInputComponent, SelectMenuOptionBuilder as BuildersSelectMenuOption, - spoiler, - strikethrough, - time, - TimestampStyles, - underscore, - userMention, ModalActionRowComponentBuilder, ModalBuilder as BuildersModal, AnyComponentBuilder, @@ -34,6 +17,25 @@ import { type RestOrArray, ApplicationCommandOptionAllowedChannelTypes, } from '@discordjs/builders'; +import { + blockQuote, + bold, + channelMention, + codeBlock, + formatEmoji, + hideLinkEmbed, + hyperlink, + inlineCode, + italic, + quote, + roleMention, + spoiler, + strikethrough, + time, + TimestampStyles, + underscore, + userMention, +} from '@discordjs/formatters'; import { Awaitable, JSONEncodable } from '@discordjs/util'; import { Collection, ReadonlyCollection } from '@discordjs/collection'; import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';