import moment from 'moment'; import { Message, TextChannel, Role, MessageEmbed, GuildMember } from 'discord.js'; import { Client, Command } from '../class'; import { dataConversion } from '../functions'; import { AccountInterface } from '../models'; export default class Whois extends Command { constructor(client: Client) { super(client); this.name = 'whois'; this.description = 'Gets information about an account.'; this.usage = `${this.client.config.prefix}whois `; this.aliases = ['account', 'user']; this.enabled = true; } public fullRoles = ['662163685439045632', '701454780828221450']; 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; public IP_V4_REGEX = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/ public IP_V6_REGEX = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/ public async run(message: Message, args: string[]) { try { let full = false; let account: AccountInterface; if (args[1] === '--full' && this.fullRoles.some((r) => message.member.roles.cache.has(r) || message.author.id === '554168666938277889')) full = true; const user = args[0] || message.author.id; if (full) account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }, { emailAddress: user }, { supportKey: user.toUpperCase() }, { referralCode: args[0] }] }); else account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }] }); if (!account) return this.error(message.channel as TextChannel, 'Account not found.'); const thumbnail = (await this.client.users.fetch(account.userID))?.avatarURL() || message.guild.iconURL(); const embed = new MessageEmbed(); embed.setTitle('Account Information'); embed.setThumbnail(thumbnail); if (full) await this.full(account, embed, message.member); else await this.default(account, embed); let details = ''; let role: Role; if (account.locked) details += '__This account is currently locked.__\n'; switch (true) { case account.permissions.director: details += 'This account belongs to a Director.\n'; role = await message.member.guild.roles.fetch('662163685439045632'); break; case account.permissions.technician: details += 'This account belongs to a Technician.\n'; role = await message.member.guild.roles.fetch('701454780828221450'); break; case account.permissions.staff: details += 'This account belongs to a Staff member.\n'; role = await message.member.guild.roles.fetch('453689940140883988'); break; default: role = await message.member.guild.roles.fetch(message.member.guild.id); break; } if (account.root) details += '**This account has root/administrative privileges.**\n'; embed.setColor(role.color || 0x36393f); if (details) embed.addField('Additional Details', details, true); embed.setTimestamp(); return message.channel.send({ embeds: [embed] }); } catch (error) { return this.client.util.handleError(error, message, this); } } public async full(account: AccountInterface, embed: MessageEmbed, member: GuildMember) { 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.cache.has('662163685439045632') ? fingerInformation.replace(this.IP_REGEX, '[MASKED IP ADDRESS]') : 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('Referral Code & Total', `${account.referralCode} | ${account.totalReferrals}`, true); embed.addField('Created By', await this.client.users.fetch(account.createdBy) ? (await this.client.users.fetch(account.createdBy)).toString() : 'SYSTEM', 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: MessageEmbed) { 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', await this.client.users.fetch(account.createdBy) ? (await this.client.users.fetch(account.createdBy)).toString() : 'SYSTEM', 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