diff options
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() } } |