From 45a90218327ef762a76b92ab9c29698e1b8f3cd7 Mon Sep 17 00:00:00 2001 From: janderedev Date: Sun, 10 Apr 2022 15:44:54 +0200 Subject: [PATCH] add global blacklist reasons --- api/src/routes/stats.ts | 2 +- bot/src/bot/commands/botadm.ts | 17 +++++++++++++++++ bot/src/bot/commands/warns.ts | 7 ++++--- bot/src/struct/DbUser.ts | 3 +++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/api/src/routes/stats.ts b/api/src/routes/stats.ts index db9de35..427378e 100644 --- a/api/src/routes/stats.ts +++ b/api/src/routes/stats.ts @@ -29,7 +29,7 @@ app.get('/stats/global_blacklist', async (req: Request, res: Response) => { res.send({ total: users.length, - blacklist: users.map(u => ({ id: u.id?.toUpperCase() })), + blacklist: users.map(u => ({ id: u.id?.toUpperCase(), reason: u.blacklistReason || null })), }); } catch(e) { console.error(''+e); diff --git a/bot/src/bot/commands/botadm.ts b/bot/src/bot/commands/botadm.ts index cbead95..0acfae4 100644 --- a/bot/src/bot/commands/botadm.ts +++ b/bot/src/bot/commands/botadm.ts @@ -38,6 +38,7 @@ const SUBCOMMANDS: string[] = [ 'userinfo', 'blacklist', 'unblacklist', + 'blacklistreason', 'ignore', 'unignore', ]; @@ -221,6 +222,22 @@ export default { break; } + case 'blacklistreason': { + const target = await parseUserOrId(args.shift() || ''); + if (!target) return message.reply('Specified user could not be found.'); + + await dbs.USERS.update({ + id: target._id, + }, { + $setOnInsert: { id: target._id }, + $set: { blacklistReason: args.join(' ') || undefined } + }, { upsert: true }); + + await message.reply(`User update stored.`); + + break; + } + case 'ignore': { const target = await parseUserOrId(args.shift() || ''); if (!target) return message.reply('Specified user could not be found.'); diff --git a/bot/src/bot/commands/warns.ts b/bot/src/bot/commands/warns.ts index 5c9dc73..3c47207 100644 --- a/bot/src/bot/commands/warns.ts +++ b/bot/src/bot/commands/warns.ts @@ -12,7 +12,8 @@ import CommandCategory from "../../struct/commands/CommandCategory"; Day.extend(RelativeTime); -const GLOBAL_BLACKLIST_TEXT = `> :warning: This user has been flagged and is globally blacklisted. [Learn more.](https://github.com/janderedev/automod/wiki/Global-Blacklist)\n\n`; +const GLOBAL_BLACKLIST_TEXT = (reason?: string) => `> :warning: This user has been flagged and is globally blacklisted. [Learn more.](https://github.com/janderedev/automod/wiki/Global-Blacklist)` + + `${reason ? `\nReason: "${reason}"` : ''}\n\n`; export default { name: 'warns', @@ -72,12 +73,12 @@ export default { const userConfig = await dbs.USERS.findOne({ id: user._id }); if (!infs) return message.reply(`There are no infractions stored for \`${await fetchUsername(user._id)}\`.` - + (userConfig?.globalBlacklist ? '\n' + GLOBAL_BLACKLIST_TEXT : ''), false); + + (userConfig?.globalBlacklist ? '\n' + GLOBAL_BLACKLIST_TEXT(userConfig.blacklistReason) : ''), false); else { let msg = `## ${infs.length} infractions stored for ${await fetchUsername(user._id)}\n`; if (userConfig?.globalBlacklist) { - msg += GLOBAL_BLACKLIST_TEXT; + msg += GLOBAL_BLACKLIST_TEXT(userConfig.blacklistReason); } else msg += '\u200b\n'; let attachSpreadsheet = false; diff --git a/bot/src/struct/DbUser.ts b/bot/src/struct/DbUser.ts index 5b869a3..13a5f4b 100644 --- a/bot/src/struct/DbUser.ts +++ b/bot/src/struct/DbUser.ts @@ -8,4 +8,7 @@ export default class DbUser { // Whether the user is globally marked as bad actor globalBlacklist?: boolean; + + // Optional reason why the user is blacklisted + blacklistReason?: string; }