Last active
September 26, 2020 21:38
-
-
Save bclinkinbeard/f6980051aaf1de42b2779cd7798dc8b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const muteStorage = new Keyv(MONGODB_URI, { namespace: `${env}mute` }) | |
const unmute = async () => { | |
client.guilds.cache.forEach((g) => { | |
const muted = g.members.cache.filter((m) => { | |
const roleNames = Array.from( | |
m.roles.cache.mapValues((r) => r.name).values(), | |
) | |
return roleNames.includes(ROLES.MUTED) | |
}) | |
if (muted.size) { | |
const guildRoles = g.roles.cache | |
muted.forEach(async (m) => { | |
const muteRecord = await muteStorage.get(m.id) | |
if (!muteRecord) { | |
m.roles.remove(findRoleByName(guildRoles, ROLES.MUTED)) | |
} | |
}) | |
} | |
console.log(`${g.name}: ${muted.size} muted`) | |
}) | |
} | |
client.once('ready', async () => { | |
setInterval(unmute, 1000 * 10) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (command === COMMANDS.UNMUTE) { | |
await muteStorage.delete(mutee.id) | |
mutee.roles.remove(mutedRole) | |
} else { | |
const mention = `<@!${mutee.id}>` | |
const msg = request.substr(mention.length).trim() | |
duration = msg.substr(0, msg.indexOf(' ')) | |
if (!duration.length) { | |
return message.channel.send('You must provide a duration and reason') | |
} | |
const unit = duration.substr(-1) | |
const num = parseInt(duration.substr(0, duration.indexOf(unit))) | |
if (!['m', 'h', 'd'].includes(unit)) { | |
return message.channel.send('Duration must end in "m", "h", or "d"') | |
} | |
if (isNaN(num)) { | |
return message.channel.send('Could not parse number from duration') | |
} | |
reason = msg.substr(duration.length + 1) | |
if (!reason.length) { | |
return message.channel.send('You must provide a reason') | |
} | |
let ms | |
switch (unit) { | |
case 'm': | |
ms = 1e3 * 60 | |
break | |
case 'h': | |
ms = 1e3 * 60 * 60 | |
break | |
case 'd': | |
ms = 1e3 * 60 * 60 * 24 | |
break | |
} | |
await muteStorage.set(mutee.id, reason, ms * num) | |
mutee.roles.add(mutedRole) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment