Skip to content

Commit

Permalink
refactor: use formatters (#9956)
Browse files Browse the repository at this point in the history
* refactor: use formatters

* fix: imports

* fix: imports pt.2

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
almeidx and kodiakhq[bot] authored Nov 12, 2023
1 parent 1e4ef35 commit 40726db
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/discord.js/src/structures/BaseChannel.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -89,7 +89,7 @@ class BaseChannel extends Base {
* console.log(`Hello from ${channel}!`);
*/
toString() {
return `<#${this.id}>`;
return channelMention(this.id);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/DMChannel.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/src/structures/Emoji.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Message.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/src/structures/Role.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/User.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/util/Formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 18 additions & 16 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
import {
ActionRowBuilder as BuilderActionRow,
MessageActionRowComponentBuilder,
ButtonBuilder as BuilderButtonComponent,
EmbedBuilder as BuildersEmbed,
ChannelSelectMenuBuilder as BuilderChannelSelectMenuComponent,
MentionableSelectMenuBuilder as BuilderMentionableSelectMenuComponent,
RoleSelectMenuBuilder as BuilderRoleSelectMenuComponent,
StringSelectMenuBuilder as BuilderStringSelectMenuComponent,
UserSelectMenuBuilder as BuilderUserSelectMenuComponent,
TextInputBuilder as BuilderTextInputComponent,
SelectMenuOptionBuilder as BuildersSelectMenuOption,
ModalActionRowComponentBuilder,
ModalBuilder as BuildersModal,
AnyComponentBuilder,
ComponentBuilder,
type RestOrArray,
ApplicationCommandOptionAllowedChannelTypes,
} from '@discordjs/builders';
import {
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,
StringSelectMenuBuilder as BuilderStringSelectMenuComponent,
UserSelectMenuBuilder as BuilderUserSelectMenuComponent,
TextInputBuilder as BuilderTextInputComponent,
SelectMenuOptionBuilder as BuildersSelectMenuOption,
spoiler,
strikethrough,
time,
TimestampStyles,
underscore,
userMention,
ModalActionRowComponentBuilder,
ModalBuilder as BuildersModal,
AnyComponentBuilder,
ComponentBuilder,
type RestOrArray,
ApplicationCommandOptionAllowedChannelTypes,
} from '@discordjs/builders';
} from '@discordjs/formatters';
import { Awaitable, JSONEncodable } from '@discordjs/util';
import { Collection, ReadonlyCollection } from '@discordjs/collection';
import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
Expand Down

0 comments on commit 40726db

Please sign in to comment.