Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed Aug 28, 2022
2 parents ee2dc62 + cac1c0d commit 1fbfbb4
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
config.json
database
node_modules
db.json
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ typings/
# custom
config.json
database
db.json
db.json
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion src/commands/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/commands/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const editableOptions = [
'channels.nsfw-punished',
'channels.nsfw-logs',
'channels.event-logs',
'channels.event-logs.blacklist',
];

async function verifyInputtedKey(interaction) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 26 additions & 1 deletion src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
6 changes: 3 additions & 3 deletions src/events/guildMemberRemove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ async function guildMemberRemoveHandler(member) {
}
);

await util.sendEventLogMessage(guild, eventLogEmbed);
await util.sendEventLogMessage(guild, null, eventLogEmbed);
}

module.exports = guildMemberRemoveHandler;
4 changes: 2 additions & 2 deletions src/events/guildMemberUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -96,7 +96,7 @@ async function guildMemberUpdateHandler(oldMember, newMember) {
}
);

await util.sendEventLogMessage(guild, eventLogEmbed);
await util.sendEventLogMessage(guild, null, eventLogEmbed);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/events/messageDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function messageDeleteHandler(message) {
iconURL: guild.iconURL()
});

await util.sendEventLogMessage(guild, eventLogEmbed);
await util.sendEventLogMessage(guild, message.channelId, eventLogEmbed);

}

Expand Down
2 changes: 1 addition & 1 deletion src/events/messageUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function messageUpdateHandler(oldMessage, newMessage) {
iconURL: guild.iconURL()
});

await util.sendEventLogMessage(guild, eventLogEmbed);
await util.sendEventLogMessage(guild, newMessage.channelId, eventLogEmbed);
}

}
Expand Down
8 changes: 7 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down

0 comments on commit 1fbfbb4

Please sign in to comment.