1
0
Fork 0
cloudservices/src/commands/exec.ts

47 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Message } from 'discord.js';
2019-10-21 20:21:25 -04:00
import axios from 'axios';
2020-06-29 02:50:26 -04:00
import { Client, Command } from '../class';
2019-10-21 20:21:25 -04:00
export default class Exec extends Command {
constructor(client: Client) {
super(client);
this.name = 'exec';
this.description = 'Executes command';
this.aliases = ['ex'];
this.enabled = true;
2020-05-01 17:46:05 -04:00
this.permissions = { users: ['253600545972027394', '278620217221971968', '239261547959025665'] };
2019-11-16 14:42:34 -05:00
this.guildOnly = false;
2019-10-21 20:21:25 -04:00
}
public async run(message: Message, args: string[]) {
try {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
2020-07-01 00:49:58 -04:00
const response = await this.loading(message.channel, `\`${args.join(' ')}\``);
2019-10-29 16:16:08 -04:00
let result: string;
try {
2020-03-17 01:39:18 -04:00
result = await this.client.util.exec(args.join(' '), { cwd: '/opt/CloudServices' });
2019-10-29 16:16:08 -04:00
} catch (error) {
result = error.message;
}
2019-10-21 20:21:25 -04:00
if (result.length <= 1975) return response.edit(`\`\`\`bash\n${result}\n\`\`\``);
const splitResult = this.client.util.splitString(result, 1975);
if (splitResult[5]) {
try {
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', splitResult.join(''));
return response.edit(`${this.client.stores.emojis.success} Your command execution output can be found on https://snippets.cloud.libraryofcode.org/${data.key}`);
} catch (error) {
return response.edit(`${this.client.stores.emojis.error} ${error}`);
}
}
await response.delete();
return splitResult.forEach((m) => message.channel.send(`\`\`\`bash\n${m}\n\`\`\``));
2019-10-21 20:21:25 -04:00
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}