From c9d19e77ffa7f1a528adb6b226717b1f18415af8 Mon Sep 17 00:00:00 2001 From: Jan <26145882+imverum@users.noreply.github.com> Date: Thu, 7 Jan 2021 02:40:57 +0100 Subject: [PATCH] magic --- util/carloscounter.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/util/carloscounter.js b/util/carloscounter.js index 60c8e9e..0d2ec3f 100644 --- a/util/carloscounter.js +++ b/util/carloscounter.js @@ -16,25 +16,39 @@ module.exports.run = () => { * This counts how often a specific user got banned/muted. */ -if (stats.get('bans') == undefined) stats.set('bans', process.env.CARLOS_BANS || 0); -if (stats.get('mutes') == undefined) stats.set('mutes', process.env.CARLOS_MUTES || 0); +if (stats.get('bans') == undefined) stats.set('bans', 0); +if (stats.get('mutes') == undefined) stats.set('mutes', 0); + +try { + let role = client.guilds.cache.get(guildID).roles.cache.get(statusRoleID), roleName = role.name; + let [bans, mutes] = roleName.split(' bans, '); + mutes = Number(mutes.split(' mutes')[0]); + bans = Number(bans); + if (mutes != undefined && bans != undefined) { + stats.set('bans', bans); + stats.set('mutes', mutes); + } +} catch(e) { + logger.warn('Failed to parse role name: ' + e); +} + client.on('guildBanAdd', (guild, user) => { if (user.id != uID) return; - stats.set('bans', stats.get('bans') + 1); + stats.set('bans', Number(stats.get('bans')) + 1); updateRole(); }); client.on('guildMemberUpdate', (oldMember, newMember) => { if (newMember.id != uID) return; if (!oldMember.roles.cache.get(muteRoleID) && newMember.roles.cache.get(muteRoleID)) { - stats.set('mutes', stats.get('mutes') + 1); + stats.set('mutes', Number(stats.get('mutes')) + 1); updateRole(); } }); client.on('guildMemberAdd', (member) => { - if (member.id == uID) member.roles.add(muteRoleID).catch(e => logger.warn(`Failed to assign role ${muteRoleID}: ${e}`)); + if (member.id == uID) member.roles.add(statusRoleID).catch(e => logger.warn(`Failed to assign role ${muteRoleID}: ${e}`)); }); let updateRole = () => {