feat(Utils): add additional formatters (#6388)

This commit is contained in:
Jeroen Claassens
2021-08-11 22:06:10 +02:00
committed by GitHub
parent 75b48d8d0f
commit cd4029218f
4 changed files with 80 additions and 19 deletions

14
package-lock.json generated
View File

@@ -8,7 +8,7 @@
"version": "13.1.0-dev",
"license": "Apache-2.0",
"dependencies": {
"@discordjs/builders": "^0.4.0",
"@discordjs/builders": "^0.5.0",
"@discordjs/collection": "^0.2.1",
"@discordjs/form-data": "^3.0.1",
"@sapphire/async-queue": "^1.1.4",
@@ -1006,9 +1006,9 @@
}
},
"node_modules/@discordjs/builders": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.4.0.tgz",
"integrity": "sha512-EiwLltKph6TSaPJIzJYdzNc1PnA2ZNaaE0t0ODg3ghnpVHqfgd0YX9/srsleYHW2cw1sfIq+kbM+h0etf7GWLA==",
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.5.0.tgz",
"integrity": "sha512-HP5y4Rqw68o61Qv4qM5tVmDbWi4mdTFftqIOGRo33SNPpLJ1Ga3KEIR2ibKofkmsoQhEpLmopD1AZDs3cKpHuw==",
"dependencies": {
"@sindresorhus/is": "^4.0.1",
"discord-api-types": "^0.22.0",
@@ -12322,9 +12322,9 @@
}
},
"@discordjs/builders": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.4.0.tgz",
"integrity": "sha512-EiwLltKph6TSaPJIzJYdzNc1PnA2ZNaaE0t0ODg3ghnpVHqfgd0YX9/srsleYHW2cw1sfIq+kbM+h0etf7GWLA==",
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.5.0.tgz",
"integrity": "sha512-HP5y4Rqw68o61Qv4qM5tVmDbWi4mdTFftqIOGRo33SNPpLJ1Ga3KEIR2ibKofkmsoQhEpLmopD1AZDs3cKpHuw==",
"requires": {
"@sindresorhus/is": "^4.0.1",
"discord-api-types": "^0.22.0",

View File

@@ -45,7 +45,7 @@
},
"homepage": "https://github.com/discordjs/discord.js#readme",
"dependencies": {
"@discordjs/builders": "^0.4.0",
"@discordjs/builders": "^0.5.0",
"@discordjs/collection": "^0.2.1",
"@discordjs/form-data": "^3.0.1",
"@sapphire/async-queue": "^1.1.4",

View File

@@ -3,17 +3,22 @@
const {
blockQuote,
bold,
channelMention,
codeBlock,
formatEmoji,
hideLinkEmbed,
hyperlink,
inlineCode,
italic,
memberNicknameMention,
quote,
roleMention,
spoiler,
strikethrough,
time,
TimestampStyles,
underscore,
spoiler,
userMention,
} = require('@discordjs/builders');
/**
@@ -39,6 +44,15 @@ Formatters.blockQuote = blockQuote;
*/
Formatters.bold = bold;
/**
* Formats a channel ID into a channel mention.
* @method channelMention
* @memberof Formatters
* @param {string} channelId The channel ID to format.
* @returns {string}
*/
Formatters.channelMention = channelMention;
/**
* Wraps the content inside a codeblock with an optional language.
* @method codeBlock
@@ -50,7 +64,17 @@ Formatters.bold = bold;
Formatters.codeBlock = codeBlock;
/**
* Formats the URL into <>, which stops it from embedding.
* Formats an emoji ID into a fully qualified emoji identifier
* @method formatEmoji
* @memberof Formatters
* @param {string} emojiId The emoji ID to format.
* @param {boolean} [animated] Whether the emoji is animated or not. Defaults to `false`
* @returns {string}
*/
Formatters.formatEmoji = formatEmoji;
/**
* Wraps the URL into `<>`, which stops it from embedding.
* @method hideLinkEmbed
* @memberof Formatters
* @param {string} content The content to wrap.
@@ -70,7 +94,7 @@ Formatters.hideLinkEmbed = hideLinkEmbed;
Formatters.hyperlink = hyperlink;
/**
* Wraps the content inside an inline code.
* Wraps the content inside \`backticks\`, which formats it as inline code.
* @method inlineCode
* @memberof Formatters
* @param {string} content The content to wrap.
@@ -87,6 +111,15 @@ Formatters.inlineCode = inlineCode;
*/
Formatters.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}
*/
Formatters.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
@@ -97,7 +130,25 @@ Formatters.italic = italic;
Formatters.quote = quote;
/**
* Formats the content into strikethrough text.
* Formats a role ID into a role mention.
* @method roleMention
* @memberof Formatters
* @param {string} roleId The role ID to format.
* @returns {string}
*/
Formatters.roleMention = roleMention;
/**
* Formats the content into spoiler text.
* @method spoiler
* @memberof Formatters
* @param {string} content The content to spoiler.
* @returns {string}
*/
Formatters.spoiler = spoiler;
/**
* Formats the content into strike-through text.
* @method strikethrough
* @memberof Formatters
* @param {string} content The content to wrap.
@@ -146,12 +197,12 @@ Formatters.TimestampStyles = TimestampStyles;
Formatters.underscore = underscore;
/**
* Formats the content into spoiler text.
* @method spoiler
* Formats a user ID into a user mention.
* @method userMention
* @memberof Formatters
* @param {string} content The content to spoiler.
* @param {string} userId The user ID to format.
* @returns {string}
*/
Formatters.spoiler = spoiler;
Formatters.userMention = userMention;
module.exports = Formatters;

16
typings/index.d.ts vendored
View File

@@ -1,18 +1,23 @@
import {
blockQuote,
bold,
channelMention,
codeBlock,
formatEmoji,
hideLinkEmbed,
hyperlink,
inlineCode,
italic,
memberNicknameMention,
quote,
roleMention,
spoiler,
strikethrough,
time,
TimestampStyles,
TimestampStylesString,
underscore,
spoiler,
userMention,
} from '@discordjs/builders';
import { Collection } from '@discordjs/collection';
import { ChildProcess } from 'child_process';
@@ -125,7 +130,7 @@ import {
RawWelcomeChannelData,
RawWelcomeScreenData,
RawWidgetData,
RawWidgetMemberData,
RawWidgetMemberData
} from './rawDataTypes';
//#region Classes
@@ -1912,18 +1917,23 @@ export class Util extends null {
export class Formatters extends null {
public static blockQuote: typeof blockQuote;
public static bold: typeof bold;
public static channelMention: typeof channelMention;
public static codeBlock: typeof codeBlock;
public static formatEmoji: typeof formatEmoji;
public static hideLinkEmbed: typeof hideLinkEmbed;
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;
public static strikethrough: typeof strikethrough;
public static time: typeof time;
public static TimestampStyles: typeof TimestampStyles;
public static TimestampStylesString: TimestampStylesString;
public static underscore: typeof underscore;
public static spoiler: typeof spoiler;
public static userMention: typeof userMention;
}
export class VoiceChannel extends BaseGuildVoiceChannel {