Created
June 6, 2023 20:19
-
-
Save TheUltDev/3b8954fb8efc88b0e30d6af8a458efe7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const path = require('path'); | |
const iconv = require('iconv-lite'); | |
const EOL = require('os').EOL; | |
const namePrefixList = [ | |
'gm', | |
'god', | |
'cm', | |
'tutor', | |
'admin', | |
'aulos', | |
'gamemaster', | |
'community', | |
'balance', | |
'deposit', | |
'transfer', | |
'withdraw', | |
'support' | |
]; | |
const censorList = [ | |
'shadowcore', | |
'underwar', | |
'noxiousot', | |
'thronx', | |
'hexana', | |
'gamemaster', | |
'tutor', | |
'cm', | |
'aulos', | |
'community manager', | |
'admin', | |
'manager', | |
'croupier', | |
'dicer', | |
'casino', | |
'dice', | |
'deposit all', | |
'transfer all', | |
'withdraw all', | |
'all', | |
'sorcerer', | |
'druid', | |
'knight', | |
'paladin', | |
'magebot', | |
'windbot', | |
'magebomb', | |
'ddos', | |
'isis', | |
'game master', | |
'activity', | |
'online', | |
'casts', | |
'highscores', | |
'deaths', | |
'stats', | |
'support', | |
'yes', | |
'no' | |
]; | |
function loadBadWordFile(name) { | |
const contents = fs.readFileSync(path.resolve(__dirname, '../badwords', name)); | |
const words = contents.toString().split(EOL); | |
const validWords = []; | |
words.forEach(word => { | |
const buf = iconv.encode(word, 'ascii'); | |
const ascii = buf && buf.toString(); | |
if (ascii && ascii.length > 0) | |
validWords.push(ascii.toLowerCase()); | |
}); | |
return validWords; | |
} | |
function loadBadWordFiles() { | |
let words = []; | |
fs.readdirSync(path.resolve(__dirname, '../badwords')) | |
.filter(name => path.extname(name) === '' | |
&& name !== '.git' | |
&& name !== 'LICENSE') | |
.forEach(filepath => { | |
words = words.concat(loadBadWordFile(filepath)); | |
}); | |
// Remove duplicates and return word list | |
return words; | |
} | |
const badwordList = loadBadWordFiles(); | |
const wordList = Array.from(new Set(censorList.concat(badwordList))); | |
const namePrefixRegex = new RegExp(`(.)\\1{2,}|^(${namePrefixList.join('|')})`, 'i'); | |
const nameRegex = /(^[A-Z][a-z]+$)|(^[A-Z][a-z]+(\s[A-Z][a-z]+)+$)|(^[A-Z][a-z]+'[A-Z]?[a-z]+$)/; | |
function isValidCharacterName(name) { | |
if (name.length < 2 || name.length > 20) { | |
return false; | |
} | |
if (!name.match(nameRegex)) { | |
return false; | |
} | |
if (name.match(namePrefixRegex)) { | |
return false; | |
} | |
// Check every word in the name | |
const words = name.toLowerCase().split(' '); | |
for (let i = 0; i < words.length; i++) { | |
let compare = words[i]; | |
let j = i; | |
// Add to the current word | |
while (j < words.length) { | |
if (wordList.indexOf(compare) !== -1) { | |
return false; | |
} | |
compare += ` ${words[++j]}`; | |
} | |
} | |
return true; | |
} | |
module.exports = { | |
censorList, | |
wordList, | |
namePrefixList, | |
namePrefixRegex, | |
isValidCharacterName | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment