UNPKG

is-discord-invite

Version:

Verifies the presence of a Discord server invitation in a given string or message, with additional features for validating and confirming the authenticity and validity of the invitation link.

30 lines (26 loc) 1.01 kB
const discordPatterns = [ /discord(?:app\.com\/invite|\.(?:com\/invite|gg))\//gi, /(?:watchanimeattheoffice|discordsays)\.com\/invite\//gi, /disboard\.org\/(?:(?:en\/)?|pl\/)server\/join/gi, /discordhome\.com\/join\//gi, /discord\.me\/server\/join\//gi, ]; module.exports = (message, options = {}) => { const { defaultDiscordUrls = true, otherDiscordUrls = true, disboard = true, discordMe = true, discordhome = true, everything = false, } = options; // Determine which patterns to use based on the options const shouldUseAll = everything || !Object.keys(options).length; const activePatterns = discordPatterns.filter((_, index) => shouldUseAll || [defaultDiscordUrls, otherDiscordUrls, disboard, discordMe, discordhome][index] ); // Combine active patterns into a single regex. const regex = new RegExp(activePatterns.map(pattern => pattern.source).join('|'), 'gi'); // Test the message against the combined regex. return regex.test(message); };