From adbdff5369533bfe09c1970a7bfea093d9cd551a Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 8 May 2020 09:59:40 -0400 Subject: [PATCH] Strip Invites in portal send, strip bot invites --- commands/other/portal-send.js | 5 +++-- package.json | 2 +- structures/phone/PhoneCall.js | 5 ++--- util/Util.js | 8 ++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/commands/other/portal-send.js b/commands/other/portal-send.js index 7fb4cc32..5474de62 100644 --- a/commands/other/portal-send.js +++ b/commands/other/portal-send.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { stripInvites } = require('../../util/Util'); const { PORTAL_EMOJI_ID, PORTAL_EMOJI_NAME } = process.env; module.exports = class PortalSendCommand extends Command { @@ -18,14 +19,14 @@ module.exports = class PortalSendCommand extends Command { key: 'message', prompt: 'What message would you like to send?', type: 'string', - max: 1000 + max: 1000, + parse: message => stripInvites(message) } ] }); } async run(msg, { message }) { - if (/discord(\.gg|app\.com\/invite|\.me)\//gi.test(message)) return msg.reply('Please do not send invites.'); let channels = this.client.channels.cache.filter( channel => channel.guild && channel.topic && channel.topic.includes('') ); diff --git a/package.json b/package.json index fe865046..07b745d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "114.8.2", + "version": "114.8.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/phone/PhoneCall.js b/structures/phone/PhoneCall.js index 6f4a3fd5..9a25703a 100644 --- a/structures/phone/PhoneCall.js +++ b/structures/phone/PhoneCall.js @@ -1,5 +1,4 @@ -const { shorten, verify } = require('../../util/Util'); -const inviteRegex = /(https?:\/\/)?(www\.|canary\.|ptb\.)?discord(\.gg|app\.com\/invite|\.me)\/([^ ]+)\/?/gi; +const { shorten, stripInvites, verify } = require('../../util/Util'); module.exports = class PhoneCall { constructor(client, origin, recipient) { @@ -58,7 +57,7 @@ module.exports = class PhoneCall { const attachments = hasImage ? msg.attachments.map(a => a.url).join('\n') : null; if (!hasText && hasImage) return channel.send(`☎️ **${msg.author.tag}:**\n${attachments}`); if (!hasText && hasEmbed) return channel.send(`☎️ **${msg.author.tag}** sent an embed.`); - let content = msg.content.replace(inviteRegex, '[redacted invite]'); + let content = stripInvites(msg.content); content = content.length > 1000 ? `${shorten(content, 1000)} (Message too long)` : content; return channel.send(`☎️ **${msg.author.tag}:** ${content}\n${attachments || ''}`.trim()); } diff --git a/util/Util.js b/util/Util.js index c90e74f5..7c6d50c4 100644 --- a/util/Util.js +++ b/util/Util.js @@ -1,6 +1,8 @@ const crypto = require('crypto'); const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea', 'ya', 'hai', 'si', 'sí', 'oui', 'はい', 'correct']; const no = ['no', 'n', 'nah', 'nope', 'nop', 'iie', 'いいえ', 'non', 'fuck off']; +const inviteRegex = /(https?:\/\/)?(www\.|canary\.|ptb\.)?discord(\.gg|(app)?\.com\/invite|\.me)\/([^ ]+)\/?/gi; +const botInvRegex = /(https?:\/\/)?(www\.|canary\.|ptb\.)?discord(app)\.com\/oauth2\/authorize\?([^ ]+)\/?/gi; module.exports = class Util { static delay(ms) { @@ -150,6 +152,12 @@ module.exports = class Util { return `[${title}](${url.replace(/\)/g, '%27')}${display ? ` "${display}"` : ''})`; } + static stripInvites(str, { guild = true, bot = true, text = '[redacted invite]' }) { + if (guild) str = str.replace(inviteRegex, text); + if (bot) str = str.replace(botInvRegex, text); + return str; + } + static async verify(channel, user, { time = 30000, extraYes = [], extraNo = [] } = {}) { const filter = res => { const value = res.content.toLowerCase();