2021-08-06 17:11:27 -04:00
import { Message } from 'discord.js' ;
2020-07-01 01:24:00 -04:00
import { Client , Command } from '../class' ;
export default class SystemD_Start extends Command {
constructor ( client : Client ) {
super ( client ) ;
this . name = 'start' ;
this . description = ` Starts a SystemD user service, if the service is already running use \` ${ this . client . config . prefix } systemd restart <service name> \` . ` ;
this . usage = ` ${ this . client . config . prefix } systemd start <service name> ` ;
2020-07-07 05:29:34 -04:00
this . enabled = false ;
2020-07-01 01:24:00 -04:00
}
public async run ( message : Message , args : string [ ] ) {
try {
if ( ! args [ 0 ] ) return this . client . commands . get ( 'help' ) . run ( message , [ 'systemd' , this . name ] ) ;
2021-08-08 22:41:32 -04:00
const account = await this . client . db . Account . findOne ( { userID : message.author.id } ) ;
2020-07-01 01:24:00 -04:00
if ( ! account ) return this . error ( message . channel , 'You do not have a Cloud Services account.' ) ;
try {
await this . client . util . exec ( ` runuser ${ account . username } -c 'DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/ \ ${ UID } /bus" systemctl --user start ${ args [ 0 ] } ' ` ) ;
message . delete ( ) ;
return this . success ( message . channel , 'Service started.' ) ;
} catch ( err ) {
2020-07-01 16:42:43 -04:00
if ( err . toString ( ) . includes ( 'could not be found' ) ) return this . error ( message . channel , 'Service not found.' ) ;
2020-07-01 01:24:00 -04:00
return this . error ( message . channel , err . toString ( ) ) ;
}
} catch ( err ) {
return this . client . util . handleError ( err , message , this ) ;
}
}
}