1
0
Fork 0

Error handler

refactor/models
Bsian 2019-11-21 14:42:05 +00:00
parent 3156fe58e9
commit 5a3520aa4b
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 33 additions and 29 deletions

View File

@ -16,34 +16,38 @@ export default class Whois_User extends Command {
} }
public async run(message: Message, args: string[]) { public async run(message: Message, args: string[]) {
let account: AccountInterface; try {
if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id }); let account: AccountInterface;
else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] }); if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id });
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`); else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] });
const embed = new RichEmbed(); if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`);
embed.setTitle('Account Information'); const embed = new RichEmbed();
if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL); embed.setTitle('Account Information');
embed.setColor(0x36393f); if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL);
embed.addField('Username', `${account.username} | <@${account.userID}>`, true); embed.setColor(0x36393f);
embed.addField('ID', account.userID, true); embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true); embed.addField('ID', account.userID, true);
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
const cpuUsage = await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`); embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
embed.addField('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true); const cpuUsage = await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`);
embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), true); embed.addField('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true);
const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(await this.client.redis.get(`storage-${account.username}`))) : 'N/A'; embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), true);
embed.addField('Storage', data, true); const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(await this.client.redis.get(`storage-${account.username}`))) : 'N/A';
let details = ''; embed.addField('Storage', data, true);
if (account.locked) details += 'This account is currently locked.\n'; let details = '';
if (account.permissions.engineer) details += 'This account belongs to an Engineer.\n'; if (account.locked) details += 'This account is currently locked.\n';
else if (account.permissions.communityManager) details += 'This account belongs to a Community Manager.\n'; if (account.permissions.engineer) details += 'This account belongs to an Engineer.\n';
else if (account.permissions.supervisor) details += 'This account belongs to a Supervisor.\n'; else if (account.permissions.communityManager) details += 'This account belongs to a Community Manager.\n';
else if (account.permissions.staff) details += 'This account belongs to a Staff member.\n'; else if (account.permissions.supervisor) details += 'This account belongs to a Supervisor.\n';
if (account.root) details += 'This account has root/administrative privileges.\n'; else if (account.permissions.staff) details += 'This account belongs to a Staff member.\n';
if (details) embed.addField('Additional Details', details, true); if (account.root) details += 'This account has root/administrative privileges.\n';
embed.setFooter(this.client.user.username, this.client.user.avatarURL); if (details) embed.addField('Additional Details', details, true);
embed.setTimestamp(); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
// @ts-ignore embed.setTimestamp();
message.channel.createMessage({ embed }); // @ts-ignore
message.channel.createMessage({ embed });
} catch (error) {
this.client.util.handleError(error, message, this);
}
} }
} }