diff options
author | June McEnroe <june@causal.agency> | 2023-01-14 21:43:20 +0000 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2023-01-14 21:43:20 +0000 |
commit | aced837d31535f59e367b99e1bd445fa41de4579 (patch) | |
tree | 5ba4ca746e60165c7da3770565b4107dbe45dc47 /src | |
parent | Run npm audit or whatever (diff) | |
download | shulker-aced837d31535f59e367b99e1bd445fa41de4579.tar.gz shulker-aced837d31535f59e367b99e1bd445fa41de4579.zip |
Stay connected to rcon
Diffstat (limited to 'src')
-rw-r--r-- | src/Discord.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/Discord.ts b/src/Discord.ts index caf8996..be3b9ee 100644 --- a/src/Discord.ts +++ b/src/Discord.ts @@ -15,6 +15,8 @@ class Discord { channel: TextChannel | null + rcon: Rcon + mentionCache: Map<string, User> constructor (config: Config, onReady?: () => void) { @@ -28,6 +30,8 @@ class Discord { this.channel = null + this.rcon = new Rcon(this.config.MINECRAFT_SERVER_RCON_IP, this.config.MINECRAFT_SERVER_RCON_PORT, this.config.DEBUG) + this.mentionCache = new Map() } @@ -57,6 +61,14 @@ class Discord { if (this.channel) { console.log(`[INFO] Using channel #${this.channel.name} (id: ${this.channel.id}) in the server "${this.channel.guild.name}"`) } + + try { + await this.rcon.auth(this.config.MINECRAFT_SERVER_RCON_PASSWORD) + } catch (e) { + console.log('[ERROR] Could not auth with the server!') + if (this.config.DEBUG) console.error(e) + process.exit(1) + } } private async onMessage (message: Message) { @@ -94,17 +106,9 @@ class Discord { if (command) { if (this.config.DEBUG) console.log(`[DEBUG] Sending command "${command}" to the server`) - const rcon = new Rcon(this.config.MINECRAFT_SERVER_RCON_IP, this.config.MINECRAFT_SERVER_RCON_PORT, this.config.DEBUG) - try { - await rcon.auth(this.config.MINECRAFT_SERVER_RCON_PASSWORD) - } catch (e) { - console.log('[ERROR] Could not auth with the server!') - if (this.config.DEBUG) console.error(e) - } - let response: string | undefined; try { - response = await rcon.command(command) + response = await this.rcon.command(command) } catch (e) { console.log('[ERROR] Could not send command!') if (this.config.DEBUG) console.error(e) @@ -116,8 +120,6 @@ class Discord { console.log('[INFO] Your Minecraft version may not support tellraw, please check MINECRAFT_TELLRAW_DOESNT_EXIST in the README') } } - - rcon.close() } } |