From 1182a4bdcc87736299c1375386782429e5e73e51 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Sun, 5 Jun 2022 15:01:42 +0200 Subject: [PATCH 1/2] update simple-db repo config --- .dockerignore | 1 + .gitignore | 2 +- Dockerfile | 2 +- src/db.js | 27 ++++++++++++++++++++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index b8b3bd8..decd58b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,4 @@ config.json database node_modules +db.json diff --git a/.gitignore b/.gitignore index d1eb629..b2f239a 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,4 @@ typings/ # custom config.json database -db.json \ No newline at end of file +db.json diff --git a/Dockerfile b/Dockerfile index 6b0054d..86200f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,6 @@ RUN npm install COPY . ./ -VOLUME [ "/app/config.json", "/app/database" ] +VOLUME [ "/app/config.json", "/app/database", "/app/db.json" ] CMD ["sh", "entrypoint.sh"] diff --git a/src/db.js b/src/db.js index acf3e6b..28c805e 100644 --- a/src/db.js +++ b/src/db.js @@ -6,6 +6,31 @@ function getDB() { return db; } +/** + * Get db item as list + * @param key key to get value from + * @returns array of strings, if value doesnt exist its an empty array + */ +function getDBList(key) { + const data = db.get(key); + if (!data) return []; + return data.split(","); +} + +/** + * store array in db + * WARNING: may not contain ANY comma's in the strings + * @param key key to get value from + * @param array array of strings to store + */ +function setDBList(key, array) { + if (array.find(v=>v.contains(","))) + throw new Error("List items cannot contain any commas") + db.set(key, array.join(",")); +} + module.exports = { - getDB + getDB, + getDBList, + setDBList }; From 2066ff31d4589ff37d717085ce0a6f8e3ae83700 Mon Sep 17 00:00:00 2001 From: Jelle van Snik Date: Sun, 5 Jun 2022 15:01:47 +0200 Subject: [PATCH 2/2] implement blacklist --- src/commands/ban.js | 2 +- src/commands/kick.js | 2 +- src/commands/settings.js | 1 + src/commands/warn.js | 2 +- src/events/guildMemberRemove.js | 6 +++--- src/events/guildMemberUpdate.js | 4 ++-- src/events/messageDelete.js | 2 +- src/events/messageUpdate.js | 2 +- src/util.js | 8 +++++++- 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/commands/ban.js b/src/commands/ban.js index b25dcb2..bf08518 100644 --- a/src/commands/ban.js +++ b/src/commands/ban.js @@ -65,7 +65,7 @@ async function banHandler(interaction) { iconURL: guild.iconURL() }); - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); const { count, rows } = await Bans.findAndCountAll({ where: { diff --git a/src/commands/kick.js b/src/commands/kick.js index b1b700d..209dd13 100644 --- a/src/commands/kick.js +++ b/src/commands/kick.js @@ -135,7 +135,7 @@ async function kickHandler(interaction) { sendMemberEmbeds.push(kickEmbed); } - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); if (count > 0) { const pastKicksEmbed = new Discord.MessageEmbed(); diff --git a/src/commands/settings.js b/src/commands/settings.js index 8756e7f..fa8e3f5 100644 --- a/src/commands/settings.js +++ b/src/commands/settings.js @@ -8,6 +8,7 @@ const editableOptions = [ 'channels.nsfw-punished', 'channels.nsfw-logs', 'channels.event-logs', + 'channels.event-logs.blacklist', ]; async function verifyInputtedKey(interaction) { diff --git a/src/commands/warn.js b/src/commands/warn.js index 8c292dc..67e58b0 100644 --- a/src/commands/warn.js +++ b/src/commands/warn.js @@ -142,7 +142,7 @@ async function warnHandler(interaction) { isBan = true; } - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); if (punishmentEmbed) { const pastWarningsEmbed = new Discord.MessageEmbed(); diff --git a/src/events/guildMemberRemove.js b/src/events/guildMemberRemove.js index 1feddba..2dbdbed 100644 --- a/src/events/guildMemberRemove.js +++ b/src/events/guildMemberRemove.js @@ -43,7 +43,7 @@ async function guildMemberRemoveHandler(member) { ((Date.now() - latestLog.createdTimestamp) > 2000) // log is too old, older than a couple seconds ago ) { // User probably just left on their own - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); return; } @@ -58,7 +58,7 @@ async function guildMemberRemoveHandler(member) { if (target.id !== member.id) { // Log target does not match current user // Probably just left on their own - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); return; } @@ -97,7 +97,7 @@ async function guildMemberRemoveHandler(member) { } ); - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); } module.exports = guildMemberRemoveHandler; \ No newline at end of file diff --git a/src/events/guildMemberUpdate.js b/src/events/guildMemberUpdate.js index ef2765f..f524d00 100644 --- a/src/events/guildMemberUpdate.js +++ b/src/events/guildMemberUpdate.js @@ -61,7 +61,7 @@ async function guildMemberUpdateHandler(oldMember, newMember) { } ); - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); } if (oldMember.nickname !== newMember.nickname) { @@ -96,7 +96,7 @@ async function guildMemberUpdateHandler(oldMember, newMember) { } ); - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, null, eventLogEmbed); } } diff --git a/src/events/messageDelete.js b/src/events/messageDelete.js index 7879769..bb4ccf5 100644 --- a/src/events/messageDelete.js +++ b/src/events/messageDelete.js @@ -56,7 +56,7 @@ async function messageDeleteHandler(message) { iconURL: guild.iconURL() }); - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, message.channelId, eventLogEmbed); } diff --git a/src/events/messageUpdate.js b/src/events/messageUpdate.js index d25c07c..20f9fcf 100644 --- a/src/events/messageUpdate.js +++ b/src/events/messageUpdate.js @@ -55,7 +55,7 @@ async function messageUpdateHandler(oldMessage, newMessage) { iconURL: guild.iconURL() }); - await util.sendEventLogMessage(guild, eventLogEmbed); + await util.sendEventLogMessage(guild, newMessage.channelId, eventLogEmbed); } } diff --git a/src/util.js b/src/util.js index edd85ea..7783735 100644 --- a/src/util.js +++ b/src/util.js @@ -21,11 +21,17 @@ function ordinal(number) { /** * * @param {Discord.Guild} guild + * @param {string|null} originId origin channel id * @param {Discord.MessageEmbed} embed */ -async function sendEventLogMessage(guild, embed) { +async function sendEventLogMessage(guild, originId, embed) { const logChannelId = db.getDB().get('channels.event-logs'); const logChannel = logChannelId && await guild.channels.fetch(logChannelId); + + const blacklistedIds = db.getDBList('channels.event-logs.blacklist'); + if (blacklistedIds.includes(originId)) { + return; + } if (!logChannel) { console.log('Missing log channel!');