chat commands: add ba high gamble command

This commit is contained in:
sdburns1998
2019-06-29 00:28:22 +02:00
parent a5d3e5de94
commit 63664fbac7
4 changed files with 76 additions and 6 deletions

View File

@@ -225,7 +225,7 @@ public class ChatClient
public boolean submitGc(String username, int gc) throws IOException
{
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("chat")
.addPathSegment("gc")
.addQueryParameter("name", username)
@@ -237,7 +237,7 @@ public class ChatClient
.url(url)
.build();
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
{
return response.isSuccessful();
}
@@ -245,7 +245,7 @@ public class ChatClient
public int getGc(String username) throws IOException
{
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("chat")
.addPathSegment("gc")
.addQueryParameter("name", username)
@@ -255,7 +255,7 @@ public class ChatClient
.url(url)
.build();
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
{
if (!response.isSuccessful())
{

View File

@@ -100,4 +100,4 @@ public class ChatController
{
return chatService.getHosts(world, location);
}
}
}

View File

@@ -117,4 +117,4 @@ public class ChatService
jedis.lrem(key, 0, json);
}
}
}
}

View File

@@ -98,6 +98,7 @@ public class ChatCommandsPlugin extends Plugin
private static final String QP_COMMAND_STRING = "!qp";
private static final String GC_COMMAND_STRING = "!gc";
private static final String PB_COMMAND = "!pb";
private static final String GC_COMMAND_STRING = "!gc";
private final HiscoreClient hiscoreClient = new HiscoreClient();
private final ChatClient chatClient = new ChatClient();
@@ -148,6 +149,7 @@ public class ChatCommandsPlugin extends Plugin
chatCommandManager.registerCommandAsync(QP_COMMAND_STRING, this::questPointsLookup, this::questPointsSubmit);
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit);
chatCommandManager.registerCommandAsync(PB_COMMAND, this::personalBestLookup, this::personalBestSubmit);
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit);
}
@Override
@@ -647,6 +649,74 @@ public class ChatCommandsPlugin extends Plugin
return true;
}
private void gambleCountLookup(ChatMessage chatMessage, String message)
{
if (!config.gc())
{
return;
}
ChatMessageType type = chatMessage.getType();
final String player;
if (type == ChatMessageType.PRIVATECHATOUT)
{
player = client.getLocalPlayer().getName();
}
else
{
player = sanitize(chatMessage.getName());
}
int gc;
try
{
gc = chatClient.getGc(player);
}
catch (IOException ex)
{
log.debug("unable to lookup gamble count", ex);
return;
}
String response = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)
.append("Barbarian Assault High-level gambles: ")
.append(ChatColorType.HIGHLIGHT)
.append(Integer.toString(gc))
.build();
log.debug("Setting response {}", response);
final MessageNode messageNode = chatMessage.getMessageNode();
messageNode.setRuneLiteFormatMessage(response);
chatMessageManager.update(messageNode);
client.refreshChat();
}
private boolean gambleCountSubmit(ChatInput chatInput, String value)
{
final int gc = client.getVar(Varbits.BA_GC);
final String playerName = client.getLocalPlayer().getName();
executor.execute(() ->
{
try
{
chatClient.submitGc(playerName, gc);
}
catch (Exception ex)
{
log.warn("unable to submit gamble count", ex);
}
finally
{
chatInput.resume();
}
});
return true;
}
/**
* Looks up the item price and changes the original message to the
* response.