forked from Supositware/Haha-Yes
unsafe regex
This commit is contained in:
parent
7d934bb6f8
commit
408c24e0b8
4 changed files with 25 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
const { Command } = require('discord-akairo');
|
const { Command } = require('discord-akairo');
|
||||||
|
const safe = require('safe-regex');
|
||||||
const BannedWords = require('../../models').bannedWords;
|
const BannedWords = require('../../models').bannedWords;
|
||||||
|
|
||||||
class BannedWordsCommand extends Command {
|
class BannedWordsCommand extends Command {
|
||||||
|
@ -35,8 +36,7 @@ class BannedWordsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(message, args) {
|
async exec(message, args) {
|
||||||
// eslint-disable-next-line no-useless-escape
|
if (!safe(message.content)) return;
|
||||||
if (message.content.includes('(?:\s|/\*.*\*/|//.*|#.*)*\(.*\)')) return; // This make bot crash
|
|
||||||
|
|
||||||
if (!args.word) args.word = '';
|
if (!args.word) args.word = '';
|
||||||
args.word = args.word.replace(/[\u0250-\ue007]/g, '');
|
args.word = args.word.replace(/[\u0250-\ue007]/g, '');
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
const { Listener } = require('discord-akairo');
|
const { Listener } = require('discord-akairo');
|
||||||
const rand = require('../../rand.js');
|
const rand = require('../../rand.js');
|
||||||
const Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
|
const safe = require('safe-regex');
|
||||||
|
// Database
|
||||||
const Tag = require('../../models').Tag;
|
const Tag = require('../../models').Tag;
|
||||||
const autoResponse = require('../../models').autoresponse;
|
const autoResponse = require('../../models').autoresponse;
|
||||||
const autoResponseStat = require('../../models').autoresponseStat;
|
const autoResponseStat = require('../../models').autoresponseStat;
|
||||||
const BannedWords = require('../../models').bannedWords;
|
const BannedWords = require('../../models').bannedWords;
|
||||||
const WhitelistWord = require('../../models').whitelistWord;
|
const WhitelistWord = require('../../models').whitelistWord;
|
||||||
const quotationStat = require('../../models').quotationStat;
|
const quotationStat = require('../../models').quotationStat;
|
||||||
|
const userBlacklist = require('../../models').userBlacklist;
|
||||||
|
|
||||||
|
|
||||||
class messageListener extends Listener {
|
class messageListener extends Listener {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -17,6 +21,10 @@ class messageListener extends Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec(message) {
|
async exec(message) {
|
||||||
|
const blacklist = await userBlacklist.findOne({where: {userID:message.author.id}});
|
||||||
|
|
||||||
|
if (blacklist) return;
|
||||||
|
|
||||||
if (message.partial) {
|
if (message.partial) {
|
||||||
await message.fetch()
|
await message.fetch()
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
@ -49,6 +57,7 @@ class messageListener extends Listener {
|
||||||
censoredMessage = censoredMessage.replace(/[\u0250-\ue007]/g, '');
|
censoredMessage = censoredMessage.replace(/[\u0250-\ue007]/g, '');
|
||||||
|
|
||||||
for (let i = 0; i < bannedWords.length; i++) {
|
for (let i = 0; i < bannedWords.length; i++) {
|
||||||
|
if (!safe(bannedWords[i].get('word'))) return;
|
||||||
let regex = new RegExp(bannedWords[i].get('word'), 'g');
|
let regex = new RegExp(bannedWords[i].get('word'), 'g');
|
||||||
censoredMessage = censoredMessage.replace(regex, '█'.repeat(bannedWords[i].get('word').length));
|
censoredMessage = censoredMessage.replace(regex, '█'.repeat(bannedWords[i].get('word').length));
|
||||||
}
|
}
|
||||||
|
|
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -6121,6 +6121,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
|
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
|
||||||
"integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw=="
|
"integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw=="
|
||||||
},
|
},
|
||||||
|
"regexp-tree": {
|
||||||
|
"version": "0.1.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.21.tgz",
|
||||||
|
"integrity": "sha512-kUUXjX4AnqnR8KRTCrayAo9PzYMRKmVoGgaz2tBuz0MF3g1ZbGebmtW0yFHfFK9CmBjQKeYIgoL22pFLBJY7sw=="
|
||||||
|
},
|
||||||
"regexpp": {
|
"regexpp": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
|
||||||
|
@ -6296,6 +6301,14 @@
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
},
|
},
|
||||||
|
"safe-regex": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==",
|
||||||
|
"requires": {
|
||||||
|
"regexp-tree": "~0.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"safer-buffer": {
|
"safer-buffer": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
"mysql2": "^1.7.0",
|
"mysql2": "^1.7.0",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"node-opus": "^0.3.3",
|
"node-opus": "^0.3.3",
|
||||||
|
"safe-regex": "^2.1.1",
|
||||||
"sequelize": "^5.21.5",
|
"sequelize": "^5.21.5",
|
||||||
"sqlite3": "^4.1.0",
|
"sqlite3": "^4.1.0",
|
||||||
"superagent": "^4.1.0",
|
"superagent": "^4.1.0",
|
||||||
|
|
Loading…
Reference in a new issue