From 1ef0e11f88c62e2ff7379a2eeb0c1ef83e282280 Mon Sep 17 00:00:00 2001 From: Sam Poder <39828164+sampoder@users.noreply.github.com> Date: Sun, 10 Jul 2022 16:12:49 -0400 Subject: [PATCH] Trim dat text! --- src/interactions/css.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/interactions/css.js b/src/interactions/css.js index 05d8c0a..ff99cfa 100644 --- a/src/interactions/css.js +++ b/src/interactions/css.js @@ -2,6 +2,14 @@ import { reaction } from "../utils" let validateCss = require('css-validator'); let Pusher = require("pusher"); +function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} + +function replaceAll(str, find, replace) { + return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); +} + const pusher = new Pusher({ appId: "1435548", key: "de6cd13556d73c05beed", @@ -12,11 +20,12 @@ const pusher = new Pusher({ const interactionCSS = async (bot, message) => { const { text, channel, ts } = message - validateCss({text}, async function (_, data) { + let trimmedText = replaceAll(text, '```', '') + validateCss({trimmedText}, async function (_, data) { if(data.validity){ await reaction(bot, 'add', channel, ts, 'art') pusher.trigger("css", "new", { - message: text + message: trimmedText }); } });