Custom self-roles stats sorting

This commit is contained in:
KaKi87 2019-02-26 17:06:39 +01:00
parent 94be14a3cf
commit d1b1135ba3
3 changed files with 22 additions and 2 deletions

View File

@ -108,6 +108,10 @@ the `topics` array with the following properties :
- `leaveCommand` : command to remove a role (without the prefix)
- `joinMessage` : *(optional)* announcement when user join
- `leaveMessage` : *(optional)* announcement when user leaves
- `sort` : *(optional)* stats sorting mode
- `position` : *(default)* channel position in Discord's list
- `name` : channel name
- `members` : members count
#### Misc

View File

@ -41,7 +41,8 @@
"joinCommand": "",
"leaveCommand": "",
"joinMessage": "%m",
"leaveMessage": "%m"
"leaveMessage": "%m",
"sort": ""
}
],
"embedColor": null,

View File

@ -421,8 +421,23 @@ Client.on('message', message => {
roles.push(role);
users = new Set([...users, ...role.members.filter(member => !member.bot).map(u => u.id)]);
});
for(let i = 0; i < roles.length; i++){
roles[i].members = roles[i].memberCount = roles[i].members.filter(member => !member.bot).array().length
}
switch(topic['sort']){
case 'name':
roles = roles.sort((a, b) => a.name < b.name ? -1 : 1);
break;
case 'members':
roles = roles.sort((a, b) => b.memberCount - a.memberCount);
break;
case 'position':
default:
roles = roles.sort((a, b) => a.position - b.position);
break;
}
message.channel.send(`Stats for **${args[0]}** :\n${utils.codeBlock(table([ ['ROLE', 'MEMBER COUNT'] ]
.concat(roles.map(role => [`${role.name}`, `${role.members.filter(member => !member.bot).array().length}`]))
.concat(roles.map(role => [`${role.name}`, `${role.memberCount}`]))
.concat([ [ 'TOTAL', `${users.size} (${(users.size / Guild.memberCount * 100).toFixed(2)}%)` ] ])))}`);
});
break;