moved harmful to ajds core

This commit is contained in:
Ben
2020-08-06 18:50:46 +01:00
parent c7c709d516
commit 3fc7fd94b3
3 changed files with 43 additions and 40 deletions

View File

@@ -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;
}

View File

@@ -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`);

View File

@@ -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;
}