Skip to content

Commit

Permalink
feat(Utils): add additional formatters (#6388)
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Aug 11, 2021
1 parent 75b48d8 commit cd40292
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 19 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
67 changes: 59 additions & 8 deletions src/util/Formatters.js
Expand Up @@ -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');

/**
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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 changes: 13 additions & 3 deletions typings/index.d.ts
@@ -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';
Expand Down Expand Up @@ -125,7 +130,7 @@ import {
RawWelcomeChannelData,
RawWelcomeScreenData,
RawWidgetData,
RawWidgetMemberData,
RawWidgetMemberData
} from './rawDataTypes';

//#region Classes
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cd40292

Please sign in to comment.