summary refs log tree commit diff homepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Discord.ts24
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()
     }
   }
 
302c78bc75577e&follow=1'>Use 4M- for window resizing in cwmJune McEnroe 2021-02-08Tweak trackpad scaling, mouse accelerationJune McEnroe 2021-02-08Use xsel in up and add it do install.shJune McEnroe 2021-02-07Swap root window coloursJune McEnroe 2021-02-07Add -X flag to install X stuff on OpenBSDJune McEnroe 2021-02-07Adjust brightness by smaller incrementsJune McEnroe 2021-02-07Fix cwm window cycling, move big by defaultJune McEnroe 2021-02-07Use class names for Foreground, Background, BorderColorJune McEnroe 2021-02-07Add simple battery status and clock to xsessionJune McEnroe 2021-02-07Set cursor theme and sizeJune McEnroe 2021-02-07Use scrot for up -s if no screencaptureJune McEnroe 2021-02-07Enable mouse acceleration in XJune McEnroe 2021-02-07Set colours for Xt and cwmJune McEnroe 2021-02-07Set urgency on bell in xtermJune McEnroe 2021-02-07Add bindings for brightness controlJune McEnroe 2021-02-07Set X key repeat rateJune McEnroe 2021-02-07Bump font size to 12June McEnroe 2021-02-07Fully configure and rebind cwmJune McEnroe 2021-02-07Add BintiJune McEnroe 2021-02-07Finish configuring xtermJune McEnroe 2021-02-06Enable tapping, reverse scroll, set scaling in wsconsctlJune McEnroe 2021-02-06Set root window to black on purple snowJune McEnroe 2021-02-06Add xmodmap configurationJune McEnroe 2021-02-06Add initial OpenBSD X configurationJune McEnroe 2021-02-06Add xterm output to schemeJune McEnroe