diff --git a/common/index.ts b/common/index.ts index 45d65981..b5aef78e 100644 --- a/common/index.ts +++ b/common/index.ts @@ -164,3 +164,63 @@ export type Snowflake = `${bigint}`; * @internal */ export type Permissions = `${bigint}`; + +/** + * https://discord.com/developers/docs/reference#message-formatting-formats + */ +export const FormattingPatterns = { + /** + * Regular expression for matching a user mention, strictly without a nickname + * + * The `userID` group property is present on the `exec` result of this expression + */ + User: /<@(?\d{17,20})>/, + /** + * Regular expression for matching a user mention, strictly with a nickname + * + * The `userID` group property is present on the `exec` result of this expression + */ + UserWithNickname: /<@!(?\d{17,20})>/, + /** + * Regular expression for matching a user mention, with or without a nickname + * + * The `userID` group property is present on the `exec` result of this expression + */ + UserWithOptionalNickname: /<@!?(?\d{17,20})>/, + /** + * Regular expression for matching a channel mention + * + * The `channelID` group property is present on the `exec` result of this expression + */ + Channel: /<#(?\d{17,20})>/, + /** + * Regular expression for matching a role mention + * + * The `roleID` group property is present on the `exec` result of this expression + */ + Role: /<@&(?\d{17,20})>/, + /** + * Regular expression for matching a custom emoji, either static or animated + * + * The `emojiAnimated`, `emojiName` and `emojiID` group properties are present on the `exec` result of this expression + */ + Emoji: /<(?a)?:(?\w{2,32}):(?\d{17,20})>/, + /** + * Regular expression for matching strictly an animated custom emoji + * + * The `emojiAnimated`, `emojiName` and `emojiID` group properties are present on the `exec` result of this expression + */ + AnimatedEmoji: /<(?a):(?\w{2,32}):(?\d{17,20})>/, + /** + * Regular expression for matching strictly a static custom emoji + * + * The `emojiName` and `emojiID` group properties are present on the `exec` result of this expression + */ + StaticEmoji: /<:(?\w{2,32}):(?\d{17,20})>/, +} as const; + +/** + * Freezes the formatting patterns + * @internal + */ +Object.freeze(FormattingPatterns);