diff --git a/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java b/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java index 75ae64b932..d9e75ba1be 100644 --- a/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java +++ b/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java @@ -33,7 +33,7 @@ import okhttp3.Response; public class ChatClient { - public boolean submit(String username, String boss, int kc) throws IOException + public boolean submitKc(String username, String boss, int kc) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("chat") @@ -54,7 +54,7 @@ public class ChatClient } } - public int get(String username, String boss) throws IOException + public int getKc(String username, String boss) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() .addPathSegment("chat") @@ -76,4 +76,46 @@ public class ChatClient return Integer.parseInt(response.body().string()); } } + + public boolean submitQp(String username, int qp) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("qp") + .addQueryParameter("name", username) + .addQueryParameter("qp", Integer.toString(qp)) + .build(); + + Request request = new Request.Builder() + .post(RequestBody.create(null, new byte[0])) + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + return response.isSuccessful(); + } + } + + public int getQp(String username) throws IOException + { + HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") + .addPathSegment("qp") + .addQueryParameter("name", username) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + + try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) + { + if (!response.isSuccessful()) + { + throw new IOException("Unable to look up quest points!"); + } + return Integer.parseInt(response.body().string()); + } + } } diff --git a/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java b/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java index ed608bf7d0..9060737974 100644 --- a/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java +++ b/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java @@ -48,7 +48,7 @@ public class ChatController private ChatService chatService; @PostMapping("/kc") - public void submit(@RequestParam String name, @RequestParam String boss, @RequestParam int kc) + public void submitKc(@RequestParam String name, @RequestParam String boss, @RequestParam int kc) { if (kc <= 0) { @@ -60,7 +60,7 @@ public class ChatController } @GetMapping("/kc") - public int get(@RequestParam String name, @RequestParam String boss) + public int getKc(@RequestParam String name, @RequestParam String boss) { Integer kc = killCountCache.getIfPresent(new KillCountKey(name, boss)); if (kc == null) @@ -78,4 +78,26 @@ public class ChatController } return kc; } + + @PostMapping("/qp") + public void submitQp(@RequestParam String name, @RequestParam int qp) + { + if (qp < 0) + { + return; + } + + chatService.setQp(name, qp); + } + + @GetMapping("/qp") + public int getKc(@RequestParam String name) + { + Integer kc = chatService.getQp(name); + if (kc == null) + { + throw new NotFoundException(); + } + return kc; + } } diff --git a/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java b/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java index 7824218e61..b8f4955f28 100644 --- a/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java +++ b/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java @@ -60,4 +60,22 @@ public class ChatService jedis.setex("kc." + name + "." + boss, (int) EXPIRE.getSeconds(), Integer.toString(kc)); } } + + public Integer getQp(String name) + { + String value; + try (Jedis jedis = jedisPool.getResource()) + { + value = jedis.get("qp." + name); + } + return value == null ? null : Integer.parseInt(value); + } + + public void setQp(String name, int qp) + { + try (Jedis jedis = jedisPool.getResource()) + { + jedis.setex("qp." + name, (int) EXPIRE.getSeconds(), Integer.toString(qp)); + } + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index 9cc2eeab88..143e064d1b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -285,7 +285,7 @@ public class ChatCommandsPlugin extends Plugin { try { - chatClient.submit(playerName, boss, kc); + chatClient.submitKc(playerName, boss, kc); } catch (Exception ex) { @@ -325,7 +325,7 @@ public class ChatCommandsPlugin extends Plugin final int kc; try { - kc = chatClient.get(player, search); + kc = chatClient.getKc(player, search); } catch (IOException ex) {