package co.phoenixlab.discord.api;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;

public class DiscordWebSocketClient extends WebSocketClient {

    private final DiscordApiClient apiClient;

    public DiscordWebSocketClient(DiscordApiClient apiClient, URI serverUri) {
        super(serverUri);
        this.apiClient = apiClient;
    }

    @Override
    public void onOpen(ServerHandshake handshakedata) {

    }

    @Override
    public void onMessage(String message) {

    }

    @Override
    public void onClose(int code, String reason, boolean remote) {

    }

    @Override
    public void onError(Exception ex) {

    }
}

@@ -136,92 +136,359 @@
 ke;%0A
-%0Aimport java.net.URI;%0A%0Apublic class DiscordWebSocketClient extends WebSocketClient %7B
+import org.json.simple.JSONObject;%0Aimport org.json.simple.parser.JSONParser;%0Aimport org.json.simple.parser.ParseException;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.net.URI;%0A%0Apublic class DiscordWebSocketClient extends WebSocketClient %7B%0A%0A    private static final Logger LOGGER = LoggerFactory.getLogger(%22DiscordApiClient%22);
 %0A%0A  
@@ -530,16 +530,53 @@
 iClient;
+%0A    private final JSONParser parser;
 %0A%0A    pu
@@ -706,24 +706,64 @@
  apiClient;%0A
+        this.parser = new JSONParser();%0A
     %7D%0A%0A    @
@@ -831,163 +831,1411 @@
 ) %7B%0A
-%0A    %7D%0A%0A    @Override%0A    public void onMessage(String message) %7B%0A%0A    %7D%0A%0A    @Override%0A    public void onClose(int code, String reason, boolean remote) %7B%0A
+        Thread.currentThread().setName(%22WebSocketClient%22);%0A        LOGGER.info(%22WebSocket connection opened%22);%0A        send(%22%7B%5C%22op%5C%22:2,%5C%22d%5C%22:%7B%5C%22token%5C%22:%5C%22%22 + apiClient.getToken() + %22%5C%22,%5C%22properties%5C%22:%7B%5C%22$os%5C%22:%5C%22Linux%5C%22,%5C%22%22 +%0A                %22$browser%5C%22:%5C%22DesuBot%5C%22,%5C%22$device%5C%22:%5C%22DesuBot%5C%22,%5C%22$referrer%5C%22:%5C%22%5C%22,%5C%22$referring_domain%5C%22%22 +%0A                %22:%5C%22%5C%22%7D,%5C%22v%5C%22:2%7D%7D%22);%0A    %7D%0A%0A    @Override%0A    public void onMessage(String message) %7B%0A        LOGGER.debug(%22Recieved message: %7B%7D%22, message);%0A        try %7B%0A            JSONObject msg = (JSONObject) parser.parse(message);%0A            String errorMessage = (String) msg.get(%22message%22);%0A            if (errorMessage != null) %7B%0A                if (errorMessage.isEmpty()) %7B%0A                    LOGGER.warn(%22Discord returned an unknown error%22);%0A                %7D else %7B%0A                    LOGGER.warn(%22Discord returned error: %7B%7D%22, errorMessage);%0A                %7D%0A                return;%0A            %7D%0A            String type = (String) msg.get(%22t%22);%0A            JSONObject data = (JSONObject) msg.get(%22d%22);%0A            switch (type) %7B%0A                //  TODO%0A            %7D%0A        %7D catch (ParseException e) %7B%0A            LOGGER.warn(%22Unable to parse message%22, e);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onClose(int code, String reason, boolean remote) %7B%0A        LOGGER.info(%22Closing WebSocket %7B%7D: %7B%7D %7B%7D%22, code, reason, remote ? %22remote%22 : %22local%22);
 %0A   
@@ -2292,16 +2292,59 @@
 n ex) %7B%0A
+        LOGGER.warn(%22WebSocket error%22, ex);
 %0A    %7D%0A%7D

Implement WebSocket client basics