Skip to content

Commit

Permalink
feat: option for optional deleteMessage and deleteOnUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed Jul 1, 2020
1 parent bba6f9c commit ef970d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/events/onMessageUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { deconstructMention } = require('../enhancedMention');
const { triggerWH, setInMap, MESSAGE_LIMIT } = require('../utils');

exports.onMessageUpdate = async(botClient, network, channelsCache, msg, oldMsg) => {
exports.onMessageUpdate = async(botClient, network, channelsCache, deleteOnUpdate, msg, oldMsg) => {
// !oldMsg = message not cached = don't log the update
if (!msg.author || msg.author.bot || !msg.channel.guild || !oldMsg) {
return;
Expand Down Expand Up @@ -39,10 +39,11 @@ exports.onMessageUpdate = async(botClient, network, channelsCache, msg, oldMsg)
}
messages.push(await triggerWH(botClient, network, channelConfig, cur, msg.author, fullMsg) );
}
const toDelete = channelsCache[msg.channel.id].get(msg.id);
for (const m of toDelete) {
m.delete().catch();
if (deleteOnUpdate) {
const toDelete = channelsCache[msg.channel.id].get(msg.id);
for (const m of toDelete) {
m.delete().catch();
}
}

setInMap(channelsCache[msg.channel.id], msg.id, messages);
};
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ exports.setup = function (bot, config) {
} );

bot.on('messageCreate', (msg) => onMessageCreate(bot, network, channelsCache, msg) );
bot.on('messageUpdate', (msg, oldMsg) => onMessageUpdate(bot, network, channelsCache, msg, oldMsg) );
bot.on('messageDelete', (msg) => onMessageDelete(bot, network, channelsCache, msg) );
bot.on('messageUpdate', (msg, oldMsg) => onMessageUpdate(bot, network, channelsCache, config.deleteOnUpdate, msg, oldMsg) );

if (config.messageDelete) {
bot.on('messageDelete', (msg) => onMessageDelete(bot, network, channelsCache, msg) );
}
};

0 comments on commit ef970d5

Please sign in to comment.