diff --git a/src/ajds-core.js b/src/ajds-core.js index 6e699b5..6414fae 100644 --- a/src/ajds-core.js +++ b/src/ajds-core.js @@ -108,3 +108,29 @@ module.exports.NickCheck = function(name) return ret; } + +/* + To all of which I do solemnly and sincerely promise and swear, without + any hesitation, mental reservation, or secret evasion of mind in me + whatsoever; binding myself under no less a penalty than that of having + my throat cut across, my tongue torn out, and with my body buried in + the sands of the sea at low-water mark, where the tide ebbs and flows + twice in twenty-four hours, should I ever knowingly or willfully + violate this, my solemn Obligation of a Javascript user. So help + me God and make me steadfast to keep and perform the same. +*/ + +module.exports.IsIdentifierHarmful = function(ident) +{ + return !(/^[a-zA-Z0-9_][a-zA-Z0-9_!?-]{3,20}$/.test(ident)); +} + +module.exports.NeutralizeHarmfulIdentifier = function(ident) +{ + let base = ident.replace(/[^a-zA-Z0-9_]/g, ''); + if (base.length > 20) base = base.slice(0, 20); + while (base.length < 3) { + base += `UnPingableNick${Math.floor(Math.random()*10 + 0.5)}`; + } + return base; +} diff --git a/src/discord-events.js b/src/discord-events.js index 72e48e5..ac087de 100644 --- a/src/discord-events.js +++ b/src/discord-events.js @@ -7,7 +7,6 @@ const DiscordHelpers = require('./discord-helpers.js'); const DiscordEmbed = require('./discord-embedbuilder.js'); const ADJSCore = require('./ajds-core.js'); -const CATV = require('./harmful.js'); const Eris = require('eris'); @@ -559,24 +558,27 @@ async function GuildMemberAdd(guild, member) } } + let HarmfulName = ADJSCore.IsIdentifierHarmful(member.username); + let HarmfulStr; + if (HarmfulName) + { + HarmfulStr = '**Username warning: ** This member\'s username is un-pingable\n' + + try { + await member.edit({ + nick: ADJSCore.NeutralizeHarmfulIdentifier(member.username) + }); + HarmfulStr += '**Action Taken:** This member\'s username was changed. This will soon be a configurable option, but for now you if you would not like this feature, you can turn it off by removing the manage nicknames permission from logori.' + } catch (e) + { } + } + embed.field('​', `**Member:** ${member.mention} **AJDS Results:** *${AJDSScore.literalscore}* - ${WarningString ? WarningString : ''}`); + ${WarningString ? WarningString : ''}\n + ${HarmfulStr ? HarmfulStr : ''}`); - if (CATV.isIdentifierHarmful(member.username)) - { - embed.field('Username harmfulness', `This member's username is considered harmful.`); - - // How to disable this? Just remove nick management permission haha. - try - { - await member.edit({ - nick: CATV.neutralizeHarmfulIdentifier(member.username) - }); - } - catch (e) {} - } // embed.field('​', `${member.mention} is ${AddOrdinalSuffix(DiscordHelpers.GetMemberJoinPos(member.id, guild))} to join`); diff --git a/src/harmful.js b/src/harmful.js deleted file mode 100644 index 46b2e40..0000000 --- a/src/harmful.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - To all of which I do solemnly and sincerely promise and swear, without - any hesitation, mental reservation, or secret evasion of mind in me - whatsoever; binding myself under no less a penalty than that of having - my throat cut across, my tongue torn out, and with my body buried in - the sands of the sea at low-water mark, where the tide ebbs and flows - twice in twenty-four hours, should I ever knowingly or willfully - violate this, my solemn Obligation of a Javascript user. So help - me God and make me steadfast to keep and perform the same. -*/ - -module.exports.isIdentifierHarmful = function(ident) -{ - return !(/^[a-zA-Z0-9_][a-zA-Z0-9_!?-]{3,20}$/.test(ident)); -} - -module.exports.neutralizeHarmfulIdentifier = function(ident) -{ - let base = ident.replace(/[^a-zA-Z0-9_]/g, ''); - if (base.length > 20) base = base.slice(0, 20); - while (base.length < 3) { - base += `${Math.floor(Math.random()*10 + 0.5)}`; - } - return base; -}