chat commands: add ba high gamble command
This commit is contained in:
@@ -216,4 +216,46 @@ public class ChatClient
|
||||
return Integer.parseInt(response.body().string());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean submitGc(String username, int gc) throws IOException
|
||||
{
|
||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||
.addPathSegment("chat")
|
||||
.addPathSegment("gc")
|
||||
.addQueryParameter("name", username)
|
||||
.addQueryParameter("gc", Integer.toString(gc))
|
||||
.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 getGc(String username) throws IOException
|
||||
{
|
||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||
.addPathSegment("chat")
|
||||
.addPathSegment("gc")
|
||||
.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 gamble count!");
|
||||
}
|
||||
return Integer.parseInt(response.body().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,28 @@ public class ChatController
|
||||
return kc;
|
||||
}
|
||||
|
||||
@PostMapping("/gc")
|
||||
public void submitGc(@RequestParam String name, @RequestParam int gc)
|
||||
{
|
||||
if (gc < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
chatService.setGc(name, gc);
|
||||
}
|
||||
|
||||
@GetMapping("/gc")
|
||||
public int getKc(@RequestParam String name)
|
||||
{
|
||||
Integer gc = chatService.getGc(name);
|
||||
if (gc == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return gc;
|
||||
}
|
||||
|
||||
@PostMapping("/task")
|
||||
public void submitTask(@RequestParam String name, @RequestParam("task") String taskName, @RequestParam int amount,
|
||||
@RequestParam int initialAmount, @RequestParam String location)
|
||||
|
||||
@@ -139,4 +139,22 @@ public class ChatService
|
||||
jedis.setex("pb." + boss + "." + name, (int) EXPIRE.getSeconds(), Integer.toString(pb));
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getGc(String name)
|
||||
{
|
||||
String value;
|
||||
try (Jedis jedis = jedisPool.getResource())
|
||||
{
|
||||
value = jedis.get("gc." + name);
|
||||
}
|
||||
return value == null ? null : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
public void setGc(String name, int gc)
|
||||
{
|
||||
try (Jedis jedis = jedisPool.getResource())
|
||||
{
|
||||
jedis.setex("gc." + name, (int) EXPIRE.getSeconds(), Integer.toString(gc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,6 +217,7 @@ public enum Varbits
|
||||
* Barbarian Assault
|
||||
*/
|
||||
IN_GAME_BA(3923),
|
||||
BA_GC(4768),
|
||||
|
||||
/**
|
||||
* 0 = Outside wilderness
|
||||
|
||||
@@ -99,6 +99,17 @@ public interface ChatCommandsConfig extends Config
|
||||
|
||||
@ConfigItem(
|
||||
position = 6,
|
||||
keyName = "gc",
|
||||
name = "GC Command",
|
||||
description = "Configures whether the Barbarian Assault High gamble count command is enabled<br> !gc"
|
||||
)
|
||||
default boolean gc()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 7,
|
||||
keyName = "clearShortcuts",
|
||||
name = "Clear shortcuts",
|
||||
description = "Enable shortcuts (ctrl+w and backspace) for clearing the chatbox"
|
||||
|
||||
@@ -42,6 +42,7 @@ import net.runelite.api.IconID;
|
||||
import net.runelite.api.ItemComposition;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
@@ -95,6 +96,7 @@ public class ChatCommandsPlugin extends Plugin
|
||||
private static final String CMB_COMMAND_STRING = "!cmb";
|
||||
private static final String QP_COMMAND_STRING = "!qp";
|
||||
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();
|
||||
@@ -143,6 +145,7 @@ public class ChatCommandsPlugin extends Plugin
|
||||
chatCommandManager.registerCommandAsync(KILLCOUNT_COMMAND_STRING, this::killCountLookup, this::killCountSubmit);
|
||||
chatCommandManager.registerCommandAsync(QP_COMMAND_STRING, this::questPointsLookup, this::questPointsSubmit);
|
||||
chatCommandManager.registerCommandAsync(PB_COMMAND, this::personalBestLookup, this::personalBestSubmit);
|
||||
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,6 +163,7 @@ public class ChatCommandsPlugin extends Plugin
|
||||
chatCommandManager.unregisterCommand(KILLCOUNT_COMMAND_STRING);
|
||||
chatCommandManager.unregisterCommand(QP_COMMAND_STRING);
|
||||
chatCommandManager.unregisterCommand(PB_COMMAND);
|
||||
chatCommandManager.unregisterCommand(GC_COMMAND_STRING);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -570,6 +574,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.
|
||||
|
||||
Reference in New Issue
Block a user