From 0af48d3f0b185ff5db5ddf90b37295857b7ed484 Mon Sep 17 00:00:00 2001 From: Jan <26145882+imverum@users.noreply.github.com> Date: Thu, 7 Jan 2021 02:08:52 +0100 Subject: [PATCH] bruh --- index.js | 2 +- util/carloscounter.js | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 util/carloscounter.js diff --git a/index.js b/index.js index 8dae9fe..4eda268 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ module.exports = { // Execute modules in util folder in order async function runModules() { - for (const file of ['commandLoader', 'login', 'eventHandler', 'karma']) { + for (const file of ['commandLoader', 'login', 'eventHandler', 'karma', 'carloscounter']) { logger.debug(`Running module ${file}`); await require(`./util/${file}`).run(); } diff --git a/util/carloscounter.js b/util/carloscounter.js new file mode 100644 index 0000000..60c8e9e --- /dev/null +++ b/util/carloscounter.js @@ -0,0 +1,45 @@ +const Discord = require('discord.js'); +const { client, logger } = require('../index'); +const Enmap = require('enmap'); +const { updateRoles } = require('./karma'); +const stats = new Enmap({name: 'carlos_stats'}); +let uID = '566239971309256704'; +let guildID = '653568812578373643'; +let muteRoleID = '751522580300693608'; +let statusRoleID = '795371115513249862'; + +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); + +client.on('guildBanAdd', (guild, user) => { + if (user.id != uID) return; + stats.set('bans', 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); + updateRole(); + } +}); + +client.on('guildMemberAdd', (member) => { + if (member.id == uID) member.roles.add(muteRoleID).catch(e => logger.warn(`Failed to assign role ${muteRoleID}: ${e}`)); +}); + +let updateRole = () => { + let role = client.guilds.cache.get(guildID).roles.cache.get(statusRoleID); + if (!role) return; + if (role.editable) role.setName(`${stats.get('bans')} bans, ${stats.get('mutes')} mutes`, 'Carlos is a dipfuck'); + else logger.warn('Can\'t manage role ' + statusRoleID); +} \ No newline at end of file