diff --git a/util/karma.js b/util/karma.js index 8051575..5fc1265 100644 --- a/util/karma.js +++ b/util/karma.js @@ -45,6 +45,8 @@ const awards = { } } +let timeouts = {} + module.exports.run = () => { client.on('messageReactionAdd', async function(reaction, user) { // Fetch reaction and user if they are partial @@ -70,15 +72,21 @@ module.exports.run = () => { return; } else if (awards[reaction.emoji.id]) { let award = awards[reaction.emoji.id]; + + let perms = message.channel.permissionsFor(user.id); + if (!perms.has('SEND_MESSAGES') || !perms.has('ADD_REACTIONS')) return reaction.users.remove(user.id); + if (coins.get(user.id) < award.cost) { - message.channel.send(`${user}, you don't have sufficient coins to use this award.`); + if (timeouts[user.id] < Date.now()) message.channel.send(`${user}, you don't have sufficient coins to use this award.`); reaction.users.remove(user.id); + timeouts[user.id] = Date.now() + 5000; return; } if (message.author.id == user.id) { - //reaction.remove(); reaction.users.remove(user.id); - return message.channel.send(`${user}, why would you give an award to yourself? smh my head`); + if (timeouts[user.id] < Date.now()) message.channel.send(`${user}, why would you give an award to yourself? smh my head`); + timeouts[user.id] = Date.now() + 5000; + return; } coins.set(user.id, (coins.get(user.id) - award.cost)); coins.set(message.author.id, (coins.get(message.author.id) + award.give));