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

37 lines
1.5 KiB
TypeScript

/* eslint-disable consistent-return */
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class SystemdD_Linger extends Command {
constructor(client: Client) {
super(client);
this.name = 'linger';
this.description = 'Enables login linger for your user, this means your SystemD services will start on reboot.';
this.usage = `${this.client.config.prefix}systemd linger <enable | disable>`;
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.');
switch (args[0]) {
case 'enable':
await this.client.util.exec(`loginctl enable-linger ${account.username}`);
this.success(message.channel, 'Successfully activated SystemD linger.');
break;
case 'disable':
await this.client.util.exec(`loginctl disable-linger ${account.username}`);
this.success(message.channel, 'Successfully deactivated SystemD linger.');
break;
default:
this.error(message.channel, 'Invalid argument provided.');
break;
}
} catch (err) {
this.client.util.handleError(err, message, this);
}
}
}