cloudservices/src/commands/systemd_status.ts

36 lines
1.6 KiB
TypeScript

import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
export default class SystemD_Status extends Command {
constructor(client: Client) {
super(client);
this.name = 'status';
this.description = 'Prints out the status of a SystemD service that you run.';
this.usage = `${this.client.config.prefix}systemd status <service name.`;
this.enabled = false;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, ['systemd', this.name]);
const account = await this.client.db.Account.findOne({ userID: message.author.id }).lean().exec();
if (!account) return this.error(message.channel, 'You do not have a Cloud Services account.');
let cmd: string = '';
try {
cmd += await this.client.util.exec(`runuser ${account.username} -c 'DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/\${UID}/bus" systemctl --user status ${args[0]}'`);
} catch (err) {
if (err.toString().includes('could not be found')) return this.error(message.channel, 'The service name you provided doesn\'t exist.');
return this.error(message.channel, err.toString());
}
const embed = new RichEmbed();
embed.setTitle(`SystemD Status | ${args[0]}`);
embed.setDescription(`\`\`\`sh\n${cmd}\n\`\`\``);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
return message.channel.createMessage({ embed });
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}