Merge pull request #2 from aosync/harmful
Secured population from harmful (user|nick)names.
This commit is contained in:
@@ -5,6 +5,8 @@ const Discord = require('./discord.js');
|
||||
const DiscordHelpers = require('./discord-helpers.js');
|
||||
const DiscordEmbed = require('./discord-embedbuilder.js');
|
||||
|
||||
const CATV = require('./harmful.js');
|
||||
|
||||
let Commands = [];
|
||||
|
||||
let GuildsAndPrefixs = [];
|
||||
@@ -14,6 +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['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};
|
||||
@@ -157,3 +160,22 @@ async function MeCommand(message, args)
|
||||
{
|
||||
DiscordHelpers.SendMessageSafe(message.channel.id, `All of your data can be accessed here: https://logori.xyz/api/v1/user/${message.author.id}`);
|
||||
}
|
||||
|
||||
async function NeutralizeBadNickname(message)
|
||||
{
|
||||
if (message.mentions.length < 1)
|
||||
{
|
||||
Discord.bot.createMessage(message.channel.id, 'You must provide a user');
|
||||
return;
|
||||
}
|
||||
|
||||
let member = message.channel.guild.members.find(m => m.user.id === message.mentions[0].id);
|
||||
let ident = member.nick && member.nick !== '' ? member.nick : member.username;
|
||||
try
|
||||
{
|
||||
await member.edit({
|
||||
nick: CATV.neutralizeHarmfulIdentifier(ident)
|
||||
});
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ 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');
|
||||
|
||||
@@ -27,7 +28,7 @@ module.exports.setup = async function()
|
||||
Discord.bot.on('guildEmojisUpdate', async (guild, emojis, oldemojis) => {GuildEmojisUpdate(guild, emojis, oldemojis)});
|
||||
Discord.bot.on('guildMemberAdd', async (guild, member) => {GuildMemberAdd(guild, member)});
|
||||
Discord.bot.on('guildMemberRemove', async (guild, member) => {GuildMemberRemove(guild, member)});
|
||||
Discord.bot.on('guildMemberUpdate', async (guild, member, oldmember) => {});
|
||||
Discord.bot.on('guildMemberUpdate', async (guild, member, oldmember) => {}); // TODO(aosync): Check if new nickname is harmful.
|
||||
Discord.bot.on('guildRoleCreate', async (guild, role) => {});
|
||||
Discord.bot.on('guildRoleDelete', async (guild, role) => {});
|
||||
Discord.bot.on('guildRoleUpdate', async (guild, role, oldrole) => {});
|
||||
@@ -43,7 +44,7 @@ module.exports.setup = async function()
|
||||
Discord.bot.on('messageReactionRemoveEmoji', async (message, emoji) => {});
|
||||
Discord.bot.on('messageUpdate', async (message, oldmessage) => {MessageUpdate(message, oldmessage)});
|
||||
Discord.bot.on('presenceUpdate', async (member, oldprescence) => {});
|
||||
Discord.bot.on('userUpdate', async (user, olduser) => {});
|
||||
Discord.bot.on('userUpdate', async (user, olduser) => {}); // TODO(aosync): Check if new username is harmful. Set nickname if yes.
|
||||
Discord.bot.on('voiceChannelJoin', async (member, newchannel) => {});
|
||||
Discord.bot.on('voiceChannelLeave', async (member, oldchannel) => {});
|
||||
Discord.bot.on('voiceChannelSwitch', async (member, newchannel, oldchannel) => {});
|
||||
@@ -562,6 +563,20 @@ async function GuildMemberAdd(guild, member)
|
||||
**AJDS Results:**
|
||||
*${AJDSScore.literalscore}*
|
||||
${WarningString ? WarningString : ''}`);
|
||||
|
||||
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`);
|
||||
|
||||
|
||||
25
src/harmful.js
Normal file
25
src/harmful.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user