add systemd status cmd

merge-requests/4/head
Matthew 2020-07-01 00:38:47 -04:00
parent 51ba72ff08
commit 050335b760
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
2 changed files with 32 additions and 1 deletions

View File

@ -17,7 +17,7 @@ export default class Exec extends Command {
try { try {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]); if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const response = await this.loading(message.channel, `***Executing \`${args.join(' ')}\``); const response = await this.loading(message.channel, `***Executing \`${args.join(' ')}\`***`);
let result: string; let result: string;
try { try {
result = await this.client.util.exec(args.join(' '), { cwd: '/opt/CloudServices' }); result = await this.client.util.exec(args.join(' '), { cwd: '/opt/CloudServices' });

View File

@ -0,0 +1,31 @@
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 = true;
}
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.');
const cmd = await this.client.util.exec(`runuser ${account.username} -c 'DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/\${UID}/bus" systemctl --user s
tatus ${args[0]}'`);
if (cmd.includes('could not be found')) return this.error(message.channel, 'The service name you provided doesn\'t exist.');
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);
}
}
}