Skip to content

Commit

Permalink
Trim dat text!
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoder committed Jul 10, 2022
1 parent e1d243e commit 1ef0e11
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/interactions/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
});
}
});
Expand Down

0 comments on commit 1ef0e11

Please sign in to comment.