community-relations/src/commands/whois.ts

199 lines
8.4 KiB
TypeScript

/* eslint-disable no-bitwise */
import moment from 'moment';
import { Message, Member } from 'eris';
import { Client, Command, RichEmbed } from '../class';
import acknowledgements from '../configs/acknowledgements.json';
import { whois as emotes } from '../configs/emotes.json';
export default class Whois extends Command {
constructor(client: Client) {
super(client);
this.name = 'whois';
this.description = 'Provides information on a member.';
this.usage = 'whois [member]';
this.permissions = 0;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
let member: Member;
if (!args[0]) member = message.member;
else {
member = this.client.util.resolveMember(args.join(' '), message.guild);
}
if (!member) {
return this.error(message.channel, 'Member not found.');
}
const embed = new RichEmbed();
embed.setAuthor(`${member.user.username}#${member.user.discriminator}`, member.user.avatarURL);
/* if (member.roles.includes('453689940140883988')) {
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);
} */
embed.setThumbnail(member.avatarURL);
const ackResolve = this.resolveStaffInformation(member.id);
let description = '';
if (ackResolve?.title) {
description += `${emotes.titleAndDepartment} __**${ackResolve.title}**__\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`;
}
description += `\n<@${member.id}>`;
embed.setDescription(description);
for (const role of member.roles.map((r) => message.guild.roles.get(r)).sort((a, b) => b.position - a.position)) {
if (role?.color !== 0) {
embed.setColor(role.color);
break;
}
}
embed.addField('Status', member.status === 'dnd' ? 'Do Not Disturb' : this.capsFirstLetter(member.status) || 'Unknown', true);
const platform = member.bot && member.status !== 'offline' ? 'API/WebSocket' : Object.entries(message.member.clientStatus).filter((a) => a[1] !== 'offline').map((a) => this.capsFirstLetter(a[0])).join(', ');
if (platform) embed.addField('Platform', platform, true);
embed.addField('Joined At', `${moment(new Date(member.joinedAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true);
embed.addField('Created At', `${moment(new Date(member.user.createdAt)).format('dddd, MMMM Do YYYY, h:mm:ss A')} ET`, true);
if (member.roles.length > 0) {
embed.addField(`Roles [${member.roles.length}]`, member.roles.map((r) => message.guild.roles.get(r)).sort((a, b) => b.position - a.position).map((r) => `<@&${r.id}>`).join(', '));
}
const permissions: string[] = [];
const serverAcknowledgements: string[] = [];
const bit = member.permission.allow;
if (message.guild.ownerID === member.id) serverAcknowledgements.push('Server Owner');
if (bit & 8) { permissions.push('Administrator'); serverAcknowledgements.push('Server Admin'); }
if (bit & 32) { permissions.push('Manage Server'); serverAcknowledgements.push('Server Manager'); }
if (bit & 16) permissions.push('Manage Channels');
if (bit & 268435456) permissions.push('Manage Roles');
if (bit & 8192) { permissions.push('Manage Messages'); serverAcknowledgements.push('Server Moderator'); }
if (bit & 134217728) permissions.push('Manage Nicknames');
if (bit & 1073741824) permissions.push('Manage Emojis');
if (bit & 4) permissions.push('Ban Members');
if (bit & 2) permissions.push('Kick Members');
const account = await this.client.db.Member.findOne({ userID: member.id });
if (account?.additional?.langs.length > 0) {
const langs: string[] = [];
for (const lang of account.additional.langs.sort((a, b) => a.localeCompare(b))) {
switch (lang) {
case 'asm':
langs.push('<:AssemblyLanguage:703448714248716442> Assembly Language');
break;
case 'cfam':
langs.push('<:clang:553684262193332278> C/C++');
break;
case 'csharp':
langs.push('<:csharp:553684277280112660> C#');
break;
case 'go':
langs.push('<:Go:703449475405971466> Go');
break;
case 'java':
langs.push('<:Java:703449725181100135> Java');
break;
case 'js':
langs.push('<:JavaScriptECMA:703449987916496946> JavaScript');
break;
case 'kt':
langs.push('<:Kotlin:703450201838321684> Kotlin');
break;
case 'py':
langs.push('<:python:553682965482176513> Python');
break;
case 'rb':
langs.push('<:ruby:604812470451699712> Ruby');
break;
case 'rs':
langs.push('<:Rust:703450901960196206> Rust');
break;
case 'swift':
langs.push('<:Swift:703451096093294672> Swift');
break;
case 'ts':
langs.push('<:TypeScript:703451285789343774> TypeScript');
break;
default:
break;
}
}
embed.addField('Known Languages', langs.join(', '));
}
if (account?.additional?.operatingSystems.length > 0) {
const operatingSystems: string[] = [];
for (const os of account.additional.operatingSystems.sort((a, b) => a.localeCompare(b))) {
switch (os) {
case 'arch':
operatingSystems.push('<:arch:707694976523304960> Arch');
break;
case 'deb':
operatingSystems.push('<:debian:707695042617147589> Debian');
break;
case 'cent':
operatingSystems.push('<:centos:707702165816213525> CentOS');
break;
case 'fedora':
operatingSystems.push('<:fedora:707695073151680543> Fedora');
break;
case 'manjaro':
operatingSystems.push('<:manjaro:707701473680556062> Manjaro');
break;
case 'mdarwin':
operatingSystems.push('<:mac:707695427754917919> macOS');
break;
case 'redhat':
operatingSystems.push('<:redhat:707695102159749271> RedHat Enterprise Linux');
break;
case 'ubuntu':
operatingSystems.push('<:ubuntu:707695136888586300> Ubuntu');
break;
case 'win':
operatingSystems.push('<:windows10:707695160259248208> Windows');
break;
default:
break;
}
}
embed.addField('Used Operating Systems', operatingSystems.join(', '));
}
if (permissions.length > 0) {
embed.addField('Permissions', permissions.join(', '));
}
if (serverAcknowledgements.length > 0) {
embed.addField('Acknowledgements', serverAcknowledgements[0]);
}
if (ackResolve?.acknowledgements) {
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);
}
}
public resolveStaffInformation(id: string) {
return acknowledgements.find((m) => m.id === id);
}
public capsFirstLetter(string?: string): string | void {
if (typeof string !== 'string') return undefined;
return string.substring(0, 1).toUpperCase() + string.substring(1);
}
}