From 3fc7fd94b3f787ca57033ffdaf619918e1acbfcf Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 6 Aug 2020 18:50:46 +0100 Subject: [PATCH 1/2] moved harmful to ajds core --- src/ajds-core.js | 26 ++++++++++++++++++++++++++ src/discord-events.js | 32 +++++++++++++++++--------------- src/harmful.js | 25 ------------------------- 3 files changed, 43 insertions(+), 40 deletions(-) delete mode 100644 src/harmful.js 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; -} From 1502e9709200cb73130d2b6def4136b38a3e776d Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 6 Aug 2020 18:56:47 +0100 Subject: [PATCH 2/2] Unpingable nickname --- src/discord-commands.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/discord-commands.js b/src/discord-commands.js index b4f4cd7..c150c2c 100644 --- a/src/discord-commands.js +++ b/src/discord-commands.js @@ -5,7 +5,7 @@ const Discord = require('./discord.js'); const DiscordHelpers = require('./discord-helpers.js'); const DiscordEmbed = require('./discord-embedbuilder.js'); -const CATV = require('./harmful.js'); +const AJDSCore = require('./ajds-core.js'); let Commands = []; @@ -16,7 +16,7 @@ module.exports.registerCommands = async function() Logger.info('Registering commands'); Commands['initserv'] = { command: 'initserv', alias: 'nil', name: 'Initialize Server', desc: 'Initialises a new Guild', callback: InitializeGuild, adminOnly: true }; - Commands['bedecent'] = { command: 'bedecent', alias: 'nil', name: 'Be decent', desc: 'Makes someone\'s nickname decent', callback: NeutralizeBadNickname, adminOnly: true}; + Commands['fixbadnick'] = { command: 'fixbadnick', alias: 'fixnick', name: 'Fix User Nickname', desc: 'Makes someone\'s nickname decent & pingable', callback: NeutralizeBadNickname, adminOnly: true}; Commands['setprefix'] = { command: 'setprefix', alias: 'prefix', name: 'Set Prefix', desc: 'Sets the servers prefix for the guild', callback: SetPrefix, adminOnly: true }; Commands['setfallbackchannel'] = { command: 'setlogchannel', alias: 'setlogchannel', name: 'Set Log Channel', desc: 'Sets the guild log channel to the current channel', callback: SetLogChannel, adminOnly: true }; Commands['me'] = { command: 'me', alias: 'nil', name: 'Me', desc: 'Returns the users profile on the logori site', callback: MeCommand, adminOnly: false}; @@ -163,7 +163,7 @@ async function SetLogChannel(message, args) } Database.UpdateGuildLogChannel(guild.id, message.channel.id); } - + DiscordHelpers.SendMessageSafe(message.channel.id, 'Logging fallback channel set to this channel'); } @@ -176,7 +176,7 @@ async function NeutralizeBadNickname(message) { if (message.mentions.length < 1) { - Discord.bot.createMessage(message.channel.id, 'You must provide a user'); + DiscordHelpers.SendMessageSafe(message.channel.id, 'You must provide a user'); return; } @@ -185,8 +185,10 @@ async function NeutralizeBadNickname(message) try { await member.edit({ - nick: CATV.neutralizeHarmfulIdentifier(ident) - }); + nick: AJDSCore.NeutralizeHarmfulIdentifier(ident) + }); + + DiscordHelpers.SendMessageSafe(message.channel.id, '`1` Nickname successfully updated'); } - catch (e) {} + catch (e) {} }