2021-01-07 01:08:52 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-01-07 01:40:57 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-01-07 01:08:52 +00:00
|
|
|
|
|
|
|
client.on('guildBanAdd', (guild, user) => {
|
|
|
|
if (user.id != uID) return;
|
2021-01-07 01:40:57 +00:00
|
|
|
stats.set('bans', Number(stats.get('bans')) + 1);
|
2021-01-07 01:08:52 +00:00
|
|
|
updateRole();
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on('guildMemberUpdate', (oldMember, newMember) => {
|
|
|
|
if (newMember.id != uID) return;
|
|
|
|
if (!oldMember.roles.cache.get(muteRoleID) && newMember.roles.cache.get(muteRoleID)) {
|
2021-01-07 01:40:57 +00:00
|
|
|
stats.set('mutes', Number(stats.get('mutes')) + 1);
|
2021-01-07 01:08:52 +00:00
|
|
|
updateRole();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on('guildMemberAdd', (member) => {
|
2021-01-07 01:40:57 +00:00
|
|
|
if (member.id == uID) member.roles.add(statusRoleID).catch(e => logger.warn(`Failed to assign role ${muteRoleID}: ${e}`));
|
2021-01-07 01:08:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|