59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
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', 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', 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', Number(stats.get('mutes')) + 1);
|
|
updateRole();
|
|
}
|
|
});
|
|
|
|
client.on('guildMemberAdd', (member) => {
|
|
if (member.id == uID) member.roles.add(statusRoleID).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);
|
|
} |