community-relations/src/commands/whois.ts

106 lines
4.8 KiB
TypeScript
Raw Normal View History

2020-04-14 19:02:12 -04:00
/* eslint-disable no-bitwise */
import moment from 'moment';
import { Message, Member, PrivateChannel, GroupChannel } from 'eris';
2020-04-14 19:02:12 -04:00
import { Client, Command, RichEmbed } from '../class';
import acknowledgements from '../configs/acknowledgements.json';
import { whois as emotes } from '../configs/emotes.json';
2020-04-14 19:02:12 -04:00
export default class Whois extends Command {
constructor(client: Client) {
super(client);
this.name = 'whois';
this.description = 'Provides information on a member.';
2020-04-15 15:33:46 -04:00
this.usage = 'whois [member]';
2020-04-14 19:02:12 -04:00
this.permissions = 0;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
2020-04-14 21:33:47 -04:00
try {
let member: Member;
if (!args[0]) member = message.member;
else {
member = this.client.util.resolveMember(args.join(' '), message.member.guild);
}
if (!member) {
return this.error(message.channel, 'Member not found.');
2020-04-14 21:33:47 -04:00
}
const embed = new RichEmbed();
embed.setAuthor(`${member.user.username}#${member.user.discriminator}`, member.user.avatarURL);
2020-04-16 09:58:06 -04:00
/* if (member.roles.includes('453689940140883988')) {
2020-04-14 21:33:47 -04:00
embed.setThumbnail('https://static.libraryofcode.org/library_of_code_associate-badge.png');
} else if (member.roles.includes('455972169449734144')) {
embed.setThumbnail('https://static.libraryofcode.org/library_of_code_sheriff-badge.png');
} else if (member.roles.includes('662163685439045632')) {
embed.setThumbnail('https://static.libraryofcode.org/library_of_code_marshal-badge.png');
} else {
embed.setThumbnail(member.avatarURL);
2020-04-16 09:58:06 -04:00
} */
2020-04-16 09:59:14 -04:00
embed.setThumbnail(member.avatarURL);
2020-04-14 21:33:47 -04:00
const ackResolve = this.resolveStaffInformation(member.id);
let description = '';
if (ackResolve) {
if (ackResolve.title && ackResolve.dept) {
description += `${emotes.titleAndDepartment} __**${ackResolve.title}**__, ${ackResolve.dept}\n\n`;
}
if (ackResolve.emailAddress) {
description += `${emotes.email} ${ackResolve.emailAddress}\n`;
}
if (ackResolve.gitlab) {
description += `${emotes.gitlab} ${ackResolve.gitlab}\n`;
}
if (ackResolve.github) {
description += `${emotes.github} ${ackResolve.github}\n`;
}
if (ackResolve.bio) {
description += `${emotes.bio} *${ackResolve.bio}*\n`;
}
2020-04-14 21:33:47 -04:00
}
description += `\n<@${member.id}>`;
embed.setDescription(description);
const roles = member.roles.map((r) => message.member.guild.roles.get(r)).sort((a, b) => b.position - a.position);
const { color } = roles.find((r) => r.color);
embed.setColor(color);
2020-04-14 21:33:47 -04:00
embed.addField('Status', `${member.status[0].toUpperCase()}${member.status.slice(1)}`, true);
embed.addField('Joined At', `${moment(new Date(message.member.joinedAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true);
embed.addField('Created At', `${moment(new Date(message.author.createdAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true);
embed.addField(`Roles [${roles.length}]`, roles.map((r) => `<@&${r.id}>`).join(', '));
2020-04-14 21:33:47 -04:00
const permissions: string[] = [];
2020-04-16 09:53:33 -04:00
const serverAcknowledgements: string[] = [];
2020-04-14 21:33:47 -04:00
const bit = member.permission.allow;
2020-04-16 09:53:33 -04:00
if (this.client.guilds.get(this.client.config.guildID).ownerID === member.id) serverAcknowledgements.push('Server Owner');
if ((bit | 8) === bit) { permissions.push('Administrator'); serverAcknowledgements.push('Server Admin'); }
if ((bit | 20) === bit) { permissions.push('Manage Server'); serverAcknowledgements.push('Server Manager'); }
2020-04-14 21:33:47 -04:00
if ((bit | 10) === bit) permissions.push('Manage Channels');
if ((bit | 268435456) === bit) permissions.push('Manage Roles');
2020-04-16 09:53:33 -04:00
if ((bit | 8192) === bit) { permissions.push('Manage Messages'); serverAcknowledgements.push('Server Moderator'); }
2020-04-14 21:33:47 -04:00
if ((bit | 134217728) === bit) permissions.push('Manage Nicknames');
if ((bit | 1073741824) === bit) permissions.push('Manage Emojis');
if ((bit | 4) === bit) permissions.push('Ban Members');
if ((bit | 2) === bit) permissions.push('Kick Members');
if (permissions.length > 0) {
embed.addField('Permissions', permissions.join(', '));
2020-04-14 19:02:12 -04:00
}
2020-04-16 09:53:33 -04:00
if (serverAcknowledgements.length > 0) {
embed.addField('Acknowledgements', serverAcknowledgements[0]);
}
if (ackResolve && ackResolve.acknowledgements) {
2020-04-14 21:33:47 -04:00
embed.addField('Bot Acknowledgements', ackResolve.acknowledgements.join(', '));
}
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
return message.channel.createMessage({ embed });
} catch (err) {
return this.client.util.handleError(err, message, this);
2020-04-14 19:02:12 -04:00
}
}
public resolveStaffInformation(id: string) {
return acknowledgements.find((m) => m.id === id);
2020-04-14 19:02:12 -04:00
}
}