1
0
Fork 0

Added disk command

refactor/models
Bsian 2019-11-01 22:27:15 +00:00
parent bf7d86d5a5
commit 0c4902fb61
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
3 changed files with 45 additions and 0 deletions

View File

@ -17,6 +17,7 @@
"eris-pagination": "bsian03/eris-pagination", "eris-pagination": "bsian03/eris-pagination",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"moment-precise-range-plugin": "^1.3.0",
"mongoose": "^5.7.4", "mongoose": "^5.7.4",
"nodemailer": "^6.3.1", "nodemailer": "^6.3.1",
"signale": "^1.4.0", "signale": "^1.4.0",

43
src/commands/disk.ts Normal file
View File

@ -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);
}
}
}

View File

@ -2,6 +2,7 @@ export { default as Announce } from './announce';
export { default as CreateAccount } from './createaccount'; export { default as CreateAccount } from './createaccount';
export { default as CWG } from './cwg'; export { default as CWG } from './cwg';
export { default as DeleteAccount } from './deleteaccount'; export { default as DeleteAccount } from './deleteaccount';
export { default as Disk } from './disk';
export { default as Eval } from './eval'; export { default as Eval } from './eval';
export { default as Exec } from './exec'; export { default as Exec } from './exec';
export { default as Help } from './help'; export { default as Help } from './help';