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

37 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-06-28 22:10:50 -04:00
/* eslint-disable consistent-return */
import { Message } from 'eris';
2020-06-29 02:50:26 -04:00
import { Client, Command } from '../class';
2020-06-28 22:10:50 -04:00
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 {
2020-06-28 22:25:17 -04:00
if (!args[0]) return this.client.commands.get('help').run(message, ['systemd', this.name]);
2020-06-28 22:10:50 -04:00
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}`);
2020-06-28 23:29:49 -04:00
this.success(message.channel, 'Successfully activated SystemD linger.');
2020-06-28 22:10:50 -04:00
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);
}
}
}