diff --git a/package-lock.json b/package-lock.json index ce2b741..b242001 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "bottleneck": "^2.19.5", "cheerio": "^1.0.0-rc.3", "chrono-node": "^2.2.4", + "css-validator": "^0.11.0", "dotenv": "^10.0.0", "form-data": "^3.0.0", "haiku-detect": "^1.1.0", @@ -3759,6 +3760,72 @@ "nth-check": "~1.0.1" } }, + "node_modules/css-validator": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/css-validator/-/css-validator-0.11.0.tgz", + "integrity": "sha512-7mKO07Lu8zU5uE2KFtDvHENGu/K0LbkDRTx93ijdXGmhxyyBmYAEQs7/7ttefysOVnicQiCkZzEOu/SQaH/sDA==", + "dependencies": { + "async": "~3.2.0", + "commander": "~7.1.0", + "form-data": "~4.0.0", + "obj-extend": "~0.1.0", + "readable-stream": "~3.6.0", + "sax": "~1.2.4" + }, + "bin": { + "css-validator": "bin/css-validator" + }, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/css-validator/node_modules/async": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" + }, + "node_modules/css-validator/node_modules/commander": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-7.1.0.tgz", + "integrity": "sha512-pRxBna3MJe6HKnBGsDyMv8ETbptw3axEdYHoqNh7gu5oDcew8fs0xnivZGm06Ogk8zGAJ9VX+OPEr2GXEQK4dg==", + "engines": { + "node": ">= 10" + } + }, + "node_modules/css-validator/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/css-validator/node_modules/readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/css-validator/node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, "node_modules/css-what": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.3.tgz", @@ -6326,6 +6393,14 @@ "node": "*" } }, + "node_modules/obj-extend": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/obj-extend/-/obj-extend-0.1.0.tgz", + "integrity": "sha512-or9c7Ue2wWCun41DuLP3+LKEUjSZcDSxfCM4HZQSX9tcjLL/yuzTW7MmtVNs+MmN16uDRpDrFmFK/WVSm4vklg==", + "engines": { + "node": "*" + } + }, "node_modules/object-copy": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz", @@ -7583,6 +7658,11 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "node_modules/sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, "node_modules/scmp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/scmp/-/scmp-2.0.0.tgz", @@ -12285,6 +12365,59 @@ "nth-check": "~1.0.1" } }, + "css-validator": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/css-validator/-/css-validator-0.11.0.tgz", + "integrity": "sha512-7mKO07Lu8zU5uE2KFtDvHENGu/K0LbkDRTx93ijdXGmhxyyBmYAEQs7/7ttefysOVnicQiCkZzEOu/SQaH/sDA==", + "requires": { + "async": "~3.2.0", + "commander": "~7.1.0", + "form-data": "~4.0.0", + "obj-extend": "~0.1.0", + "readable-stream": "~3.6.0", + "sax": "~1.2.4" + }, + "dependencies": { + "async": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" + }, + "commander": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-7.1.0.tgz", + "integrity": "sha512-pRxBna3MJe6HKnBGsDyMv8ETbptw3axEdYHoqNh7gu5oDcew8fs0xnivZGm06Ogk8zGAJ9VX+OPEr2GXEQK4dg==" + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "requires": { + "safe-buffer": "~5.2.0" + } + } + } + }, "css-what": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.3.tgz", @@ -14448,6 +14581,11 @@ "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" }, + "obj-extend": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/obj-extend/-/obj-extend-0.1.0.tgz", + "integrity": "sha512-or9c7Ue2wWCun41DuLP3+LKEUjSZcDSxfCM4HZQSX9tcjLL/yuzTW7MmtVNs+MmN16uDRpDrFmFK/WVSm4vklg==" + }, "object-copy": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz", @@ -15488,6 +15626,11 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, "scmp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/scmp/-/scmp-2.0.0.tgz", diff --git a/package.json b/package.json index a329cb1..06cc1fc 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "bottleneck": "^2.19.5", "cheerio": "^1.0.0-rc.3", "chrono-node": "^2.2.4", + "css-validator": "^0.11.0", "dotenv": "^10.0.0", "form-data": "^3.0.0", "haiku-detect": "^1.1.0", diff --git a/src/index.js b/src/index.js index d8e832c..b02f0d8 100644 --- a/src/index.js +++ b/src/index.js @@ -56,6 +56,7 @@ import interactionReportForm from "./interactions/reportForm"; import interactionReportFormSubmit from "./interactions/reportFormSubmit"; import interactionEmail from "./interactions/email"; import interactionHaiku from "./interactions/haiku"; +import interactionCSS from "./interactions/css"; export const bugsnagClient = bugsnag(process.env.BUGSNAG_API_KEY); @@ -183,7 +184,10 @@ controller.hears( controller.hears(".*", "direct_message,indirect_mention,direct_mention", interactionCatchall); // catch-all for any message in slack -controller.hears(".*", "ambient", interactionHaiku); +controller.hears(".*", "ambient", (bot, message) =>{ + interactionHaiku(bot, message) + interactionCSS(bot, message) +}); // controller.hears(".*", "mention,direct_message,indirect_mention,direct_mention", interactionGamelab) diff --git a/src/interactions/css.js b/src/interactions/css.js new file mode 100644 index 0000000..eb21655 --- /dev/null +++ b/src/interactions/css.js @@ -0,0 +1,13 @@ +import { reaction } from "../utils" +let validateCss = require('css-validator'); + +const interactionHaiku = async (bot, message) => { + const { text, ts } = message + validateCss({text}, async function (_, data) { + if(data.validity){ + await reaction(bot, 'add', channel, ts, 'art') + } + }); +} + +export default interactionHaiku \ No newline at end of file