forked from engineering/cloudservices
75 lines
3.5 KiB
TypeScript
75 lines
3.5 KiB
TypeScript
/* eslint-disable no-await-in-loop */
|
|
import { Message } from 'eris';
|
|
import { createPaginationEmbed } from 'eris-pagination';
|
|
import { Client, Command, RichEmbed } from '../class';
|
|
|
|
export default class Users extends Command {
|
|
constructor(client: Client) {
|
|
super(client);
|
|
this.name = 'users';
|
|
this.description = 'Pulls up users.';
|
|
this.usage = `${this.client.config.prefix}users <filter: t1 | t2 | t3`;
|
|
this.enabled = true;
|
|
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
|
|
}
|
|
|
|
public async run(message: Message, args: string[]) {
|
|
try {
|
|
const msg: Message = await this.loading(message.channel, 'Locating users...');
|
|
const embedFields: [ { name: string, value: string }? ] = [];
|
|
const accounts = await this.client.db.Account.find().lean().exec();
|
|
if (!args[0]) {
|
|
for (const account of accounts) {
|
|
const fingerInformation = await this.client.util.exec(`finger ${account.username}`);
|
|
embedFields.push({ name: `${account.username}`, value: `<@${account.userID}>\n${fingerInformation}\nTier: ${account.tier} | Email Address: ${account.emailAddress}${account.locked ? ' | Locked: true' : ''}` });
|
|
}
|
|
} else {
|
|
switch (args[0]) {
|
|
default:
|
|
return msg.edit(`***${this.client.stores.emojis.error} Invalid filter option.***`);
|
|
case 't1':
|
|
for (const account of accounts.filter((a) => a.tier === 1)) {
|
|
const fingerInformation = await this.client.util.exec(`finger ${account.username}`);
|
|
embedFields.push({ name: `${account.username}`, value: `<@${account.userID}>\n${fingerInformation}\nTier: ${account.tier} | Email Address: ${account.emailAddress}${account.locked ? ' | Locked: true' : ''}` });
|
|
}
|
|
break;
|
|
case 't2':
|
|
for (const account of accounts.filter((a) => a.tier === 2)) {
|
|
const fingerInformation = await this.client.util.exec(`finger ${account.username}`);
|
|
embedFields.push({ name: `${account.username}`, value: `<@${account.userID}>\n${fingerInformation}\nTier: ${account.tier} | Email Address: ${account.emailAddress}${account.locked ? ' | Locked: true' : ''}` });
|
|
}
|
|
break;
|
|
case 't3':
|
|
for (const account of accounts.filter((a) => a.tier === 3)) {
|
|
const fingerInformation = await this.client.util.exec(`finger ${account.username}`);
|
|
embedFields.push({ name: `${account.username}`, value: `<@${account.userID}>\n${fingerInformation}\nTier: ${account.tier} | Email Address: ${account.emailAddress}${account.locked ? ' | Locked: true' : ''}` });
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
const data = this.client.util.splitFields(embedFields);
|
|
|
|
const embeds = data.map((l) => {
|
|
const embed = new RichEmbed();
|
|
embed.setAuthor('Library of Code | Cloud Services', this.client.user.avatarURL, 'https://libraryofcode.org/');
|
|
embed.setTitle('Cloud Accounts');
|
|
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
|
|
l.forEach((f) => embed.addField(f.name, f.value, true));
|
|
embed.setTimestamp();
|
|
embed.setColor(3447003);
|
|
return embed;
|
|
});
|
|
|
|
if (embeds.length === 1) {
|
|
msg.edit({ content: '', embed: embeds[0] });
|
|
} else {
|
|
createPaginationEmbed(message, embeds, {});
|
|
}
|
|
return msg;
|
|
} catch (error) {
|
|
return this.client.util.handleError(error, message, this);
|
|
}
|
|
}
|
|
}
|