11import { APIButtonComponentBase , BaseMessageOptions , ButtonBuilder , ButtonStyle , ChannelType , ComponentType , Guild , GuildTextBasedChannel , If , Message , PermissionResolvable , PermissionsBitField , StageChannel , inlineCode , mergeDefault } from 'discord.js' ;
22import { Logger , recursiveObjectReplaceValues , PartialDeep } from 'fallout-utility' ;
33import { resolveFromCachedManager } from '../utils/managers.js' ;
4- import { readFileSync , rmSync , writeFileSync } from 'fs' ;
54import { PingData , pingServer } from '../utils/ping.js' ;
65import { ChildProcess , spawn } from 'child_process' ;
76import { ServerManager } from './ServerManager.js' ;
87import { Kirin } from '../../Kirin.js' ;
98import { randomBytes } from 'crypto' ;
109import { cli } from 'reciple' ;
1110import path from 'path' ;
11+ import { readFile , rm , writeFile } from 'fs/promises' ;
1212
1313export type ServerDataWithIdStatus = ServerData & { id : string ; status : ServerStatus ; } ;
1414
@@ -156,7 +156,6 @@ export class Server<Ready extends boolean = boolean> {
156156 detached : ! this . server . killOnBotStop ,
157157 killSignal : this . server . killSignal || 'SIGINT' ,
158158 env : process . env ,
159- // shell: true,
160159 stdio : [ ]
161160 } ) ;
162161
@@ -256,7 +255,7 @@ export class Server<Ready extends boolean = boolean> {
256255
257256 this . _deleted = true ;
258257
259- if ( deleteJsonFile && this . file ) rmSync ( this . file , { force : true , recursive : true } ) ;
258+ if ( deleteJsonFile && this . file ) await rm ( this . file , { force : true , recursive : true } ) ;
260259 }
261260
262261 public async update ( options : PartialDeep < ServerData > ) : Promise < this> {
@@ -279,7 +278,7 @@ export class Server<Ready extends boolean = boolean> {
279278 if ( isFetch ) await this . fetch ( ) ;
280279 if ( ! oldOptions . messageId && newOptions . messageId && this . channel ) await this . createMessage ( { deleteOld : true } ) ;
281280
282- this . saveJson ( ) ;
281+ await this . saveJson ( ) ;
283282
284283 return this ;
285284 }
@@ -302,7 +301,7 @@ export class Server<Ready extends boolean = boolean> {
302301 this . options . channelId = channel ?. id ;
303302 }
304303
305- this . saveJson ( ) ;
304+ await this . saveJson ( ) ;
306305 }
307306
308307 public async ping ( ) : Promise < PingData > {
@@ -321,12 +320,12 @@ export class Server<Ready extends boolean = boolean> {
321320 return newPing ;
322321 }
323322
324- public saveJson ( file ?: string | null ) : void {
323+ public async saveJson ( file ?: string | null ) : Promise < void > {
325324 file = file ?? this . file ;
326325 if ( ! file ) throw new Error ( 'No file path specified' ) ;
327326 if ( ! this . file ) this . options . file = file ;
328327
329- writeFileSync ( file , JSON . stringify ( this . toJSON ( true ) , null , 2 ) ) ;
328+ await writeFile ( file , JSON . stringify ( this . toJSON ( true ) , null , 2 ) ) ;
330329 }
331330
332331 public isFetched ( ) : this is Server < true > {
@@ -381,7 +380,7 @@ export class Server<Ready extends boolean = boolean> {
381380 if ( cached ) return cached ;
382381 }
383382
384- const serverJson : ServerData = JSON . parse ( readFileSync ( file , 'utf-8' ) ) ;
383+ const serverJson : ServerData = JSON . parse ( await readFile ( file , 'utf-8' ) ) ;
385384 const server : Server = new Server ( serverJson , kirin ) ;
386385
387386 serverJson . file = file ;
0 commit comments