diff --git a/package.json b/package.json index 0fb9ffc..707e959 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "eris-pagination": "bsian03/eris-pagination", "fs-extra": "^8.1.0", "moment": "^2.24.0", + "moment-precise-range-plugin": "^1.3.0", "mongoose": "^5.7.4", "nodemailer": "^6.3.1", "signale": "^1.4.0", diff --git a/src/commands/disk.ts b/src/commands/disk.ts new file mode 100644 index 0000000..3379c24 --- /dev/null +++ b/src/commands/disk.ts @@ -0,0 +1,43 @@ +import { Message } from 'eris'; +import moment from 'moment'; +import { Client } from '..'; +import { RichEmbed, Command } from '../class'; +import { dataConversion } from '../functions'; +import 'moment-precise-range-plugin'; + +export default class Disk extends Command { + constructor(client: Client) { + super(client); + this.name = 'disk'; + this.description = 'Checks the used disk space by a user'; + this.usage = `${this.client.config.prefix}disk [Username/User ID/Email]`; + this.permissions = { roles: ['446104438969466890'] }; + this.enabled = true; + } + + async run(message: Message, args: string[]) { + try { + const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }, { emailAddress: args[0] }] }); + if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); + if (account.root || args[0].includes('./')) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied***`); + const diskReply = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching total disk size may up to 10 minutes. This message will edit when the disk size has been located.***`); + const start = Date.now(); + const result = await this.client.util.exec(`du -s /home/${account.username}`); + const end = Date.now(); + // @ts-ignore + const totalTime: string = moment.preciseDiff(start, end); + const embed = new RichEmbed(); + embed.setTitle('Disk Usage'); + embed.setColor('ff0000'); + embed.setDescription(`/home/${account.username}`); + embed.addField('Result', dataConversion(Number(result)), true); + embed.addField('Time taken', totalTime, true); + embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); + embed.setTimestamp(); + // @ts-ignore + return diskReply.edit({ content: '', embed }); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index f370c62..80123f3 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -2,6 +2,7 @@ export { default as Announce } from './announce'; export { default as CreateAccount } from './createaccount'; export { default as CWG } from './cwg'; export { default as DeleteAccount } from './deleteaccount'; +export { default as Disk } from './disk'; export { default as Eval } from './eval'; export { default as Exec } from './exec'; export { default as Help } from './help';