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

refactor: Remove nickname parsing #7736

Merged
merged 6 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/builders/__tests__/messages/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
hyperlink,
inlineCode,
italic,
memberNicknameMention,
quote,
roleMention,
spoiler,
Expand Down Expand Up @@ -122,12 +121,6 @@ describe('Message formatters', () => {
});
});

describe('memberNicknameMention', () => {
test('GIVEN memberId THEN returns "<@![memberId]>"', () => {
expect(memberNicknameMention('139836912335716352')).toBe('<@!139836912335716352>');
});
});

describe('channelMention', () => {
test('GIVEN channelId THEN returns "<#[channelId]>"', () => {
expect(channelMention('829924760309334087')).toBe('<#829924760309334087>');
Expand Down
9 changes: 0 additions & 9 deletions packages/builders/src/messages/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,6 @@ export function userMention<C extends Snowflake>(userId: C): `<@${C}>` {
return `<@${userId}>`;
}

/**
* Formats a user ID into a member-nickname mention
*
* @param memberId The user ID to format
*/
export function memberNicknameMention<C extends Snowflake>(memberId: C): `<@!${C}>` {
return `<@!${memberId}>`;
}

/**
* Formats a channel ID into a channel mention
*
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/MessageMentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MessageMentions {
* @type {RegExp}
* @memberof MessageMentions
*/
static UsersPattern = /<@!?(\d{17,19})>/g;
static UsersPattern = /<@(\d{17,19})>/g;
Jiralite marked this conversation as resolved.
Show resolved Hide resolved

/**
* Regular expression that globally matches role mentions like `<@&297577916114403338>`
Expand Down
10 changes: 0 additions & 10 deletions packages/discord.js/src/util/Formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
hyperlink,
inlineCode,
italic,
memberNicknameMention,
quote,
roleMention,
spoiler,
Expand Down Expand Up @@ -111,15 +110,6 @@ class Formatters extends null {
*/
static italic = italic;

/**
* Formats a user id into a member-nickname mention.
* @method memberNicknameMention
* @memberof Formatters
* @param {string} memberId The user id to format.
* @returns {string}
*/
static memberNicknameMention = memberNicknameMention;

/**
* Formats the content into a quote. This needs to be at the start of the line for Discord to format it.
* @method quote
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/util/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class Util extends null {
*/
static cleanContent(str, channel) {
str = str
.replace(/<@!?[0-9]+>/g, input => {
.replace(/<@[0-9]+>/g, input => {
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
const id = input.replace(/<|!|>|@/g, '');
if (channel.type === ChannelType.DM) {
const user = channel.client.users.cache.get(id);
Expand Down
5 changes: 1 addition & 4 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
public permissionsIn(channel: GuildChannelResolvable): Readonly<PermissionsBitField>;
public setNickname(nickname: string | null, reason?: string): Promise<GuildMember>;
public toJSON(): unknown;
public toString(): MemberMention;
public toString(): UserMention;
public valueOf(): string;
}

Expand Down Expand Up @@ -2551,7 +2551,6 @@ export class Formatters extends null {
public static hyperlink: typeof hyperlink;
public static inlineCode: typeof inlineCode;
public static italic: typeof italic;
public static memberNicknameMention: typeof memberNicknameMention;
public static quote: typeof quote;
public static roleMention: typeof roleMention;
public static spoiler: typeof spoiler;
Expand Down Expand Up @@ -4664,8 +4663,6 @@ export interface MakeErrorOptions {
stack: string;
}

export type MemberMention = UserMention | `<@!${Snowflake}>`;

export type ActionRowComponentOptions =
| (Required<BaseComponentData> & ButtonComponentData)
| (Required<BaseComponentData> & SelectMenuComponentData);
Expand Down