Merge pull request #4 from benkyd/dev

Merge Dev to master
This commit is contained in:
Benjamin Kyd
2020-08-06 18:59:02 +01:00
committed by GitHub
4 changed files with 52 additions and 47 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

@@ -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) {}
}

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