mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
refactor: Remove nickname parsing (#7736)
* refactor: remove nickname parsing * types: remove nickname import * chore: update guildmember * refactor: keep parsing * refactor: string from user instead
This commit is contained in:
@@ -9,7 +9,6 @@ import {
|
|||||||
hyperlink,
|
hyperlink,
|
||||||
inlineCode,
|
inlineCode,
|
||||||
italic,
|
italic,
|
||||||
memberNicknameMention,
|
|
||||||
quote,
|
quote,
|
||||||
roleMention,
|
roleMention,
|
||||||
spoiler,
|
spoiler,
|
||||||
@@ -122,12 +121,6 @@ describe('Message formatters', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('memberNicknameMention', () => {
|
|
||||||
test('GIVEN memberId THEN returns "<@![memberId]>"', () => {
|
|
||||||
expect(memberNicknameMention('139836912335716352')).toBe('<@!139836912335716352>');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('channelMention', () => {
|
describe('channelMention', () => {
|
||||||
test('GIVEN channelId THEN returns "<#[channelId]>"', () => {
|
test('GIVEN channelId THEN returns "<#[channelId]>"', () => {
|
||||||
expect(channelMention('829924760309334087')).toBe('<#829924760309334087>');
|
expect(channelMention('829924760309334087')).toBe('<#829924760309334087>');
|
||||||
|
|||||||
@@ -164,15 +164,6 @@ export function userMention<C extends Snowflake>(userId: C): `<@${C}>` {
|
|||||||
return `<@${userId}>`;
|
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
|
* Formats a channel ID into a channel mention
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ class GuildMember extends Base {
|
|||||||
* console.log(`Hello from ${member}!`);
|
* console.log(`Hello from ${member}!`);
|
||||||
*/
|
*/
|
||||||
toString() {
|
toString() {
|
||||||
return `<@${this.nickname ? '!' : ''}${this.user.id}>`;
|
return this.user.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { userMention } = require('@discordjs/builders');
|
||||||
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
const { DiscordSnowflake } = require('@sapphire/snowflake');
|
||||||
const Base = require('./Base');
|
const Base = require('./Base');
|
||||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||||
@@ -286,7 +287,7 @@ class User extends Base {
|
|||||||
* console.log(`Hello from ${user}!`);
|
* console.log(`Hello from ${user}!`);
|
||||||
*/
|
*/
|
||||||
toString() {
|
toString() {
|
||||||
return `<@${this.id}>`;
|
return userMention(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON(...props) {
|
toJSON(...props) {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ const {
|
|||||||
hyperlink,
|
hyperlink,
|
||||||
inlineCode,
|
inlineCode,
|
||||||
italic,
|
italic,
|
||||||
memberNicknameMention,
|
|
||||||
quote,
|
quote,
|
||||||
roleMention,
|
roleMention,
|
||||||
spoiler,
|
spoiler,
|
||||||
@@ -111,15 +110,6 @@ class Formatters extends null {
|
|||||||
*/
|
*/
|
||||||
static italic = italic;
|
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.
|
* Formats the content into a quote. This needs to be at the start of the line for Discord to format it.
|
||||||
* @method quote
|
* @method quote
|
||||||
|
|||||||
6
packages/discord.js/typings/index.d.ts
vendored
6
packages/discord.js/typings/index.d.ts
vendored
@@ -14,7 +14,6 @@ import {
|
|||||||
italic,
|
italic,
|
||||||
JSONEncodable,
|
JSONEncodable,
|
||||||
MappedComponentTypes,
|
MappedComponentTypes,
|
||||||
memberNicknameMention,
|
|
||||||
quote,
|
quote,
|
||||||
roleMention,
|
roleMention,
|
||||||
SelectMenuBuilder as BuilderSelectMenuComponent,
|
SelectMenuBuilder as BuilderSelectMenuComponent,
|
||||||
@@ -1281,7 +1280,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
|
|||||||
public permissionsIn(channel: GuildChannelResolvable): Readonly<PermissionsBitField>;
|
public permissionsIn(channel: GuildChannelResolvable): Readonly<PermissionsBitField>;
|
||||||
public setNickname(nickname: string | null, reason?: string): Promise<GuildMember>;
|
public setNickname(nickname: string | null, reason?: string): Promise<GuildMember>;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
public toString(): MemberMention;
|
public toString(): UserMention;
|
||||||
public valueOf(): string;
|
public valueOf(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2554,7 +2553,6 @@ export class Formatters extends null {
|
|||||||
public static hyperlink: typeof hyperlink;
|
public static hyperlink: typeof hyperlink;
|
||||||
public static inlineCode: typeof inlineCode;
|
public static inlineCode: typeof inlineCode;
|
||||||
public static italic: typeof italic;
|
public static italic: typeof italic;
|
||||||
public static memberNicknameMention: typeof memberNicknameMention;
|
|
||||||
public static quote: typeof quote;
|
public static quote: typeof quote;
|
||||||
public static roleMention: typeof roleMention;
|
public static roleMention: typeof roleMention;
|
||||||
public static spoiler: typeof spoiler;
|
public static spoiler: typeof spoiler;
|
||||||
@@ -4668,8 +4666,6 @@ export interface MakeErrorOptions {
|
|||||||
stack: string;
|
stack: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MemberMention = UserMention | `<@!${Snowflake}>`;
|
|
||||||
|
|
||||||
export type ActionRowComponentOptions =
|
export type ActionRowComponentOptions =
|
||||||
| (Required<BaseComponentData> & ButtonComponentData)
|
| (Required<BaseComponentData> & ButtonComponentData)
|
||||||
| (Required<BaseComponentData> & SelectMenuComponentData);
|
| (Required<BaseComponentData> & SelectMenuComponentData);
|
||||||
|
|||||||
Reference in New Issue
Block a user