mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
feat: move internal regular expressions to static properties (#5384)
This commit is contained in:
@@ -222,4 +222,10 @@ class GuildTemplate extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular expression that globally matches guild template links
|
||||||
|
* @type {RegExp}
|
||||||
|
*/
|
||||||
|
GuildTemplate.GUILD_TEMPLATES_PATTERN = /discord(?:app)?\.(?:com\/template|new)\/([\w-]{2,255})/gi;
|
||||||
|
|
||||||
module.exports = GuildTemplate;
|
module.exports = GuildTemplate;
|
||||||
|
|||||||
@@ -191,4 +191,10 @@ class Invite extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular expression that globally matches Discord invite links
|
||||||
|
* @type {RegExp}
|
||||||
|
*/
|
||||||
|
Invite.INVITES_PATTERN = /discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})/gi;
|
||||||
|
|
||||||
module.exports = Invite;
|
module.exports = Invite;
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ const path = require('path');
|
|||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { Error: DiscordError, TypeError } = require('../errors');
|
const { Error: DiscordError, TypeError } = require('../errors');
|
||||||
|
const GuildTemplate = require('../structures/GuildTemplate');
|
||||||
|
const Invite = require('../structures/Invite');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them.
|
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them.
|
||||||
@@ -36,8 +38,7 @@ class DataResolver {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static resolveCode(data, regex) {
|
static resolveCode(data, regex) {
|
||||||
const match = regex.exec(data);
|
return data.matchAll(regex).next().value?.[1] ?? data;
|
||||||
return match ? match[1] || data : data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +47,7 @@ class DataResolver {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static resolveInviteCode(data) {
|
static resolveInviteCode(data) {
|
||||||
return this.resolveCode(data, /discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})/i);
|
return this.resolveCode(data, Invite.INVITES_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +56,7 @@ class DataResolver {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static resolveGuildTemplateCode(data) {
|
static resolveGuildTemplateCode(data) {
|
||||||
return this.resolveCode(data, /discord(?:app)?\.(?:com\/template|new)\/([\w-]{2,255})/i);
|
return this.resolveCode(data, GuildTemplate.GUILD_TEMPLATES_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -906,6 +906,7 @@ declare module 'discord.js' {
|
|||||||
public delete(): Promise<GuildTemplate>;
|
public delete(): Promise<GuildTemplate>;
|
||||||
public edit(options?: { name?: string; description?: string }): Promise<GuildTemplate>;
|
public edit(options?: { name?: string; description?: string }): Promise<GuildTemplate>;
|
||||||
public sync(): Promise<GuildTemplate>;
|
public sync(): Promise<GuildTemplate>;
|
||||||
|
public static GUILD_TEMPLATES_PATTERN: RegExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildPreviewEmoji extends BaseGuildEmoji {
|
export class GuildPreviewEmoji extends BaseGuildEmoji {
|
||||||
@@ -978,6 +979,7 @@ declare module 'discord.js' {
|
|||||||
public delete(reason?: string): Promise<Invite>;
|
public delete(reason?: string): Promise<Invite>;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
|
public static INVITES_PATTERN: RegExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Message extends Base {
|
export class Message extends Base {
|
||||||
|
|||||||
Reference in New Issue
Block a user