forked from engineering/cloudservices
Refurbish whois command
parent
52351fd8e4
commit
6f51772033
|
@ -15,7 +15,7 @@
|
||||||
"@ghaiklor/x509": "^1.0.0",
|
"@ghaiklor/x509": "^1.0.0",
|
||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"eris": "^0.11.2",
|
"eris": "bsian03/eris#dev",
|
||||||
"eris-pagination": "git+https://github.com/bsian03/eris-pagination#a10c026e9ce0b9a99799294b7b2a64d5268be56e",
|
"eris-pagination": "git+https://github.com/bsian03/eris-pagination#a10c026e9ce0b9a99799294b7b2a64d5268be56e",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
|
|
|
@ -28,3 +28,4 @@ export { default as unban } from './unban';
|
||||||
export { default as unlock } from './unlock';
|
export { default as unlock } from './unlock';
|
||||||
export { default as warn } from './warn';
|
export { default as warn } from './warn';
|
||||||
export { default as whois } from './whois';
|
export { default as whois } from './whois';
|
||||||
|
export { default as whoisold } from './whoisold';
|
||||||
|
|
|
@ -1,70 +1,113 @@
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Message } from 'eris';
|
import { Message, GuildTextableChannel, Member, Role } from 'eris';
|
||||||
import { Client } from '..';
|
import { Client } from '..';
|
||||||
import { Command, RichEmbed } from '../class';
|
import { Command, RichEmbed } from '../class';
|
||||||
import { dataConversion } from '../functions';
|
import { dataConversion } from '../functions';
|
||||||
import User from './whois_user';
|
import { AccountInterface } from '../models';
|
||||||
|
|
||||||
export default class Whois extends Command {
|
export default class Whois extends Command {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
super(client);
|
super(client);
|
||||||
this.name = 'whois';
|
this.name = 'whois';
|
||||||
this.description = 'Views information for a cloud account.';
|
this.description = 'Gets information about an account.';
|
||||||
this.aliases = ['account', 'user'];
|
this.usage = `${this.client.config.prefix}whois <username | user ID>`;
|
||||||
this.usage = `${this.client.config.prefix}account [User Name | User ID | Email Address]`;
|
this.aliases = ['account', 'user'];
|
||||||
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
|
this.enabled = true;
|
||||||
this.subcmds = [User];
|
}
|
||||||
this.enabled = true;
|
|
||||||
}
|
public fullRoles = ['662163685439045632', '701454780828221450'];
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public IP_REGEX = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/g
|
||||||
try {
|
|
||||||
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
|
public async run(message: Message<GuildTextableChannel>, args: string[]) {
|
||||||
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }, { emailAddress: args[0] }, { supportKey: args[0].toUpperCase() }] });
|
try {
|
||||||
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found.***`);
|
let full = false;
|
||||||
const embed = new RichEmbed();
|
let account: AccountInterface;
|
||||||
embed.setTitle('Account Information');
|
if (args[1] === '--full' && !this.fullRoles.some((r) => message.member.roles.includes(r))) full = true;
|
||||||
if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL);
|
|
||||||
embed.setColor(0x36393f);
|
const user = args[0] || message.author.id;
|
||||||
let fingerInformation = await this.client.util.exec(`finger ${account.username}`);
|
if (full) account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }, { emailAddress: user }, { supportKey: user.toUpperCase() }] });
|
||||||
if (message.member && !message.member.roles.includes('662163685439045632')) {
|
else account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }] });
|
||||||
fingerInformation = fingerInformation.replace(/((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[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\d)){3}))|:)))(%.+)?\s*$))/g, '[MASKED IP ADDRESS]');
|
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Account not found.***`);
|
||||||
}
|
|
||||||
embed.setDescription(`${fingerInformation}\n${await this.client.util.exec(`chage -l ${account.username}`)}`);
|
const thumbnail = this.client.users.get(account.userID)?.avatarURL || message.channel.guild.iconURL;
|
||||||
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
|
|
||||||
embed.addField('ID', account.userID, true);
|
const embed = new RichEmbed();
|
||||||
embed.addField('Email Address', account.emailAddress, true);
|
embed.setTitle('Account Information');
|
||||||
embed.addField('Tier', String(account.tier), true);
|
embed.setThumbnail(thumbnail);
|
||||||
embed.addField('Support Key', account.supportKey, true);
|
if (full) this.full(account, embed, message.member);
|
||||||
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
|
else this.default(account, embed);
|
||||||
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
|
|
||||||
const cpuUsage = await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`);
|
let details = '';
|
||||||
embed.addField('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true);
|
let role: Role;
|
||||||
embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), true);
|
if (account.locked) details += '__This account is currently locked.__\n';
|
||||||
const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(await this.client.redis.get(`storage-${account.username}`))) : 'N/A';
|
switch (true) {
|
||||||
embed.addField('Storage', data, true);
|
case account.permissions.director:
|
||||||
let details = '';
|
details += 'This account belongs to a Director.\n';
|
||||||
if (account.locked) details += '__This account is currently locked.__\n';
|
role = message.member.guild.roles.get('662163685439045632');
|
||||||
if (account.permissions.director) {
|
break;
|
||||||
details += 'This account belongs to a Director.\n';
|
case account.permissions.technician:
|
||||||
const roleColor = this.client.guilds.get('446067825673633794').roles.get('662163685439045632').color;
|
details += 'This account belongs to a Technician.\n';
|
||||||
embed.setColor(roleColor);
|
role = message.member.guild.roles.get('701454780828221450');
|
||||||
} else if (account.permissions.technician) {
|
break;
|
||||||
details += 'This account belongs to a Technician.\n';
|
case account.permissions.staff:
|
||||||
const roleColor = this.client.guilds.get('446067825673633794').roles.get('701454780828221450').color;
|
details += 'This account belongs to a Staff member.\n';
|
||||||
embed.setColor(roleColor);
|
role = message.member.guild.roles.get('453689940140883988');
|
||||||
} else if (account.permissions.staff) {
|
break;
|
||||||
details += 'This account belongs to a Staff member.\n';
|
default:
|
||||||
const roleColor = this.client.guilds.get('446067825673633794').roles.get('453689940140883988').color;
|
role = message.member.guild.roles.get(message.member.guild.id);
|
||||||
embed.setColor(roleColor);
|
break;
|
||||||
} else embed.setColor(0x36393f);
|
}
|
||||||
if (account.root) details += '**This account has root/administrative privileges.**\n';
|
if (account.root) details += '**This account has root/administrative privileges.**\n';
|
||||||
if (details) embed.addField('Additional Details', details, true);
|
embed.setColor(role.color || 0x36393f);
|
||||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
if (details) embed.addField('Additional Details', details, true);
|
||||||
embed.setTimestamp();
|
|
||||||
return message.channel.createMessage({ embed });
|
embed.setTimestamp();
|
||||||
} catch (error) {
|
return message.channel.createMessage({ embed });
|
||||||
return this.client.util.handleError(error, message, this);
|
} catch (error) {
|
||||||
}
|
return this.client.util.handleError(error, message, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async full(account: AccountInterface, embed: RichEmbed, member: Member) {
|
||||||
|
const [cpuUsage, data, fingerInformation, chage, memory] = await Promise.all([
|
||||||
|
this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`),
|
||||||
|
this.client.redis.get(`storage-${account.username}`),
|
||||||
|
this.client.util.exec(`finger ${account.username}`),
|
||||||
|
this.client.util.exec(`chage -l ${account.username}`),
|
||||||
|
this.client.util.exec(`memory ${account.username}`),
|
||||||
|
]);
|
||||||
|
const finger = !member.roles.includes('662163685439045632') ? fingerInformation.replace(this.IP_REGEX, '[MASKED IP ADDRRESS]') : fingerInformation;
|
||||||
|
|
||||||
|
embed.setDescription(`${finger}\n${chage}`);
|
||||||
|
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
|
||||||
|
embed.addField('ID', account.userID, true);
|
||||||
|
embed.addField('Email Address', account.emailAddress, true);
|
||||||
|
embed.addField('Tier', String(account.tier), true);
|
||||||
|
embed.addField('Support Key', account.supportKey, true);
|
||||||
|
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
|
||||||
|
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] || '0'}%`, true);
|
||||||
|
embed.addField('Memory', dataConversion(Number(memory) * 1000), true);
|
||||||
|
embed.addField('Storage', data ? dataConversion(Number(data)) : 'N/A', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async default(account: AccountInterface, embed: RichEmbed) {
|
||||||
|
const [cpuUsage, data, memory] = await Promise.all([
|
||||||
|
this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`),
|
||||||
|
this.client.redis.get(`storage-${account.username}`),
|
||||||
|
this.client.util.exec(`memory ${account.username}`),
|
||||||
|
]);
|
||||||
|
|
||||||
|
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
|
||||||
|
embed.addField('ID', account.userID, true);
|
||||||
|
embed.addField('Tier', String(account.tier), true);
|
||||||
|
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
|
||||||
|
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] || '0'}%`, true);
|
||||||
|
embed.addField('Memory', dataConversion(Number(memory) * 1000), true);
|
||||||
|
embed.addField('Storage', data ? dataConversion(Number(data)) : 'N/A', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whois user only includes username, id, tier, created by, created at, cpu usage, memory, storage and additional details
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
import moment from 'moment';
|
|
||||||
import { Message } from 'eris';
|
|
||||||
import { Client } from '..';
|
|
||||||
import { Command, RichEmbed } from '../class';
|
|
||||||
import { dataConversion } from '../functions';
|
|
||||||
import { AccountInterface } from '../models';
|
|
||||||
|
|
||||||
export default class Whois_User extends Command {
|
|
||||||
constructor(client: Client) {
|
|
||||||
super(client);
|
|
||||||
this.name = 'user';
|
|
||||||
this.description = 'Gets information about your account.';
|
|
||||||
this.usage = `${this.client.config.prefix}whois user <username | user ID>`;
|
|
||||||
this.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
|
||||||
try {
|
|
||||||
let account: AccountInterface;
|
|
||||||
if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id });
|
|
||||||
else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] });
|
|
||||||
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`);
|
|
||||||
const embed = new RichEmbed();
|
|
||||||
embed.setTitle('Account Information');
|
|
||||||
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.addField('ID', account.userID, true);
|
|
||||||
embed.addField('Tier', String(account.tier), true);
|
|
||||||
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
|
|
||||||
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), 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('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true);
|
|
||||||
embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), 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('Storage', data, true);
|
|
||||||
let details = '';
|
|
||||||
if (account.locked) details += '__This account is currently locked.__\n';
|
|
||||||
if (account.permissions.director) {
|
|
||||||
details += 'This account belongs to a Director.\n';
|
|
||||||
const roleColor = this.client.guilds.get('446067825673633794').roles.get('662163685439045632').color;
|
|
||||||
embed.setColor(roleColor);
|
|
||||||
} else if (account.permissions.technician) {
|
|
||||||
details += 'This account belongs to a Technician.\n';
|
|
||||||
const roleColor = this.client.guilds.get('446067825673633794').roles.get('701454780828221450').color;
|
|
||||||
embed.setColor(roleColor);
|
|
||||||
} else if (account.permissions.staff) {
|
|
||||||
details += 'This account belongs to a Staff member.\n';
|
|
||||||
const roleColor = this.client.guilds.get('446067825673633794').roles.get('453689940140883988').color;
|
|
||||||
embed.setColor(roleColor);
|
|
||||||
} else embed.setColor(0x36393f);
|
|
||||||
if (account.root) details += '**This account has root/administrative privileges.**\n';
|
|
||||||
if (details) embed.addField('Additional Details', details, true);
|
|
||||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
|
||||||
embed.setTimestamp();
|
|
||||||
return message.channel.createMessage({ embed });
|
|
||||||
} catch (error) {
|
|
||||||
return this.client.util.handleError(error, message, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -616,10 +616,9 @@ eris-reactions@^0.1.2:
|
||||||
resolved "https://registry.yarnpkg.com/eris-reactions/-/eris-reactions-0.1.2.tgz#2d4edbf5f80dc964f0bb42fd301d3d8a141a5aa1"
|
resolved "https://registry.yarnpkg.com/eris-reactions/-/eris-reactions-0.1.2.tgz#2d4edbf5f80dc964f0bb42fd301d3d8a141a5aa1"
|
||||||
integrity sha512-p497xAdNsw3RRfAoklYemWRk1HT22rBmRaiemG6TVZ1yPTuQf41r4GteyKOJZ3hkphD3Rte7/1GiZwPzUNOHcw==
|
integrity sha512-p497xAdNsw3RRfAoklYemWRk1HT22rBmRaiemG6TVZ1yPTuQf41r4GteyKOJZ3hkphD3Rte7/1GiZwPzUNOHcw==
|
||||||
|
|
||||||
eris@^0.11.2:
|
eris@bsian03/eris#dev:
|
||||||
version "0.11.2"
|
version "0.13.1"
|
||||||
resolved "https://registry.yarnpkg.com/eris/-/eris-0.11.2.tgz#a4adad72d795d64d71a74833ccf5adc4db0ad8c0"
|
resolved "https://codeload.github.com/bsian03/eris/tar.gz/3607027f1ea64b81b302006f564ff69679b800d1"
|
||||||
integrity sha512-OhccRcxrPiNUylTamrjIbZM6itKMLjNrwLIXGvNwQZj4CRVOOz9eUVIqOJULB713x1ezw7HoC8AEsnsMNUneDA==
|
|
||||||
dependencies:
|
dependencies:
|
||||||
ws "^7.2.1"
|
ws "^7.2.1"
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
|
|
Loading…
Reference in New Issue