From ef9776362dd2635dd112cef8faf2dd57c52b12d5 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 11 Jul 2022 18:17:49 -0400 Subject: [PATCH] -Updated gradle -Add Collection Log option -Add pet rolls --- build.gradle | 2 +- .../DiscordLootLoggerConfig.java | 62 ++++++++++++------- .../DiscordLootLoggerPlugin.java | 61 ++++++++++++++---- 3 files changed, 90 insertions(+), 35 deletions(-) diff --git a/build.gradle b/build.gradle index 8aa09409..8bc23b35 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ repositories { mavenCentral() } -def runeLiteVersion = '1.6.35' +def runeLiteVersion = '1.8.26' dependencies { compileOnly group: 'net.runelite', name:'client', version: runeLiteVersion diff --git a/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerConfig.java b/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerConfig.java index e12ba8e5..4cc71937 100644 --- a/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerConfig.java +++ b/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerConfig.java @@ -10,16 +10,16 @@ public interface DiscordLootLoggerConfig extends Config String GROUP = "discordlootlogger"; @ConfigItem( - keyName = "webhook", - name = "Webhook URL", - description = "The Discord Webhook URL to send messages to" + keyName = "webhook", + name = "Webhook URL", + description = "The Discord Webhook URL to send messages to" ) String webhook(); @ConfigItem( - keyName = "sendScreenshot", - name = "Send Screenshot", - description = "Includes a screenshot when receiving the loot" + keyName = "sendScreenshot", + name = "Send Screenshot", + description = "Includes a screenshot when receiving the loot" ) default boolean sendScreenshot() { @@ -27,16 +27,16 @@ default boolean sendScreenshot() } @ConfigItem( - keyName = "lootnpcs", - name = "Loot NPCs", - description = "Only logs loot from these NPCs, comma separated" + keyName = "lootnpcs", + name = "Loot NPCs", + description = "Only logs loot from these NPCs, comma separated" ) String lootNpcs(); @ConfigItem( - keyName = "includeLowValueItems", - name = "Include Low Value Items", - description = "Only log loot items worth more than the value set in loot value option." + keyName = "includeLowValueItems", + name = "Include Low Value Items", + description = "Only log loot items worth more than the value set in loot value option." ) default boolean includeLowValueItems() { @@ -44,9 +44,9 @@ default boolean includeLowValueItems() } @ConfigItem( - keyName = "lootvalue", - name = "Loot Value", - description = "Only logs loot worth more then the given value. 0 to disable." + keyName = "lootvalue", + name = "Loot Value", + description = "Only logs loot worth more then the given value. 0 to disable." ) default int lootValue() { @@ -54,9 +54,9 @@ default int lootValue() } @ConfigItem( - keyName = "stackvalue", - name = "Include Stack Value", - description = "Include the value of each stack." + keyName = "stackvalue", + name = "Include Stack Value", + description = "Include the value of each stack." ) default boolean stackValue() { @@ -64,13 +64,33 @@ default boolean stackValue() } @ConfigItem( - keyName = "includeusername", - name = "Include Username", - description = "Include your RSN in the post." + keyName = "includeusername", + name = "Include Username", + description = "Include your RSN in the post." ) default boolean includeUsername() { return false; } + @ConfigItem( + keyName = "includepets", + name = "Include Pets", + description = "Log pet drops." + ) + default boolean includePets() + { + return false; + } + + @ConfigItem( + keyName = "includecollectionlog", + name = "Include Collection Log", + description = "Log collection log drops. (Must enable Settings>Chat>Collection log - New addition notification)" + ) + default boolean includeCollectionLog() + { + return false; + } + } diff --git a/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerPlugin.java b/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerPlugin.java index 0d51f265..d58aa3df 100644 --- a/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerPlugin.java +++ b/src/main/java/info/sigterm/plugins/discordlootlogger/DiscordLootLoggerPlugin.java @@ -5,16 +5,16 @@ import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; +import java.util.regex.Pattern; import javax.imageio.ImageIO; import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; +import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.ItemComposition; import net.runelite.api.NPC; +import net.runelite.api.events.ChatMessage; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.ConfigChanged; @@ -30,6 +30,8 @@ import net.runelite.client.util.QuantityFormatter; import net.runelite.client.util.Text; import net.runelite.client.util.WildcardMatcher; + +import static net.runelite.api.ChatMessageType.CONSOLE; import static net.runelite.http.api.RuneLiteAPI.GSON; import net.runelite.http.api.loottracker.LootRecordType; import okhttp3.Call; @@ -44,7 +46,7 @@ @Slf4j @PluginDescriptor( - name = "Discord Loot Logger" + name = "Discord Loot Logger" ) public class DiscordLootLoggerPlugin extends Plugin { @@ -65,6 +67,10 @@ public class DiscordLootLoggerPlugin extends Plugin private List lootNpcs; + private static final Pattern COLLECTION_LOG_ITEM_REGEX = Pattern.compile("New item added to your collection log:.*"); + + private static final Pattern Pet_LOG_ITEM_REGEX = Pattern.compile("You have a funny feeling like you.*"); + private static String itemImageUrl(int itemId) { return "https://static.runelite.net/cache/item/icon/" + itemId + ".png"; @@ -141,15 +147,44 @@ public void onLootReceived(LootReceived lootReceived) processLoot(lootReceived.getName(), lootReceived.getItems()); } + @Subscribe + public void onChatMessage(ChatMessage chatMessage) { + boolean processCollection = false; + if (chatMessage.getType() != ChatMessageType.GAMEMESSAGE && chatMessage.getType() != ChatMessageType.SPAM) { + return; + } + String inputMessage = chatMessage.getMessage(); + String outputMessage = inputMessage.replaceAll("\\<.*?>", ""); + if (config.includeCollectionLog() && COLLECTION_LOG_ITEM_REGEX.matcher(outputMessage).matches()) { + processCollection = true; + } + if (config.includePets() && Pet_LOG_ITEM_REGEX.matcher(outputMessage).matches()) { + processCollection = true; + } + if(processCollection) { + processCollection(outputMessage); + } + } + private String getPlayerName() { return client.getLocalPlayer().getName(); } - + private void processCollection(String name){ + WebhookBody webhookBody = new WebhookBody(); + boolean sendMessage = false; + StringBuilder stringBuilder = new StringBuilder(); + if (config.includeUsername()) + { + stringBuilder.append("\n**").append(getPlayerName()).append("**").append("\n\n"); + } + stringBuilder.append("***").append(name).append("***").append("\n"); + webhookBody.setContent(stringBuilder.toString()); + sendWebhook(webhookBody); + } private void processLoot(String name, Collection items) { WebhookBody webhookBody = new WebhookBody(); - boolean sendMessage = false; long totalValue = 0; StringBuilder stringBuilder = new StringBuilder(); @@ -200,8 +235,8 @@ private void sendWebhook(WebhookBody webhookBody) HttpUrl url = HttpUrl.parse(configUrl); MultipartBody.Builder requestBodyBuilder = new MultipartBody.Builder() - .setType(MultipartBody.FORM) - .addFormDataPart("payload_json", GSON.toJson(webhookBody)); + .setType(MultipartBody.FORM) + .addFormDataPart("payload_json", GSON.toJson(webhookBody)); if (config.sendScreenshot()) { @@ -230,7 +265,7 @@ private void sendWebhookWithScreenshot(HttpUrl url, MultipartBody.Builder reques } requestBodyBuilder.addFormDataPart("file", "image.png", - RequestBody.create(MediaType.parse("image/png"), imageBytes)); + RequestBody.create(MediaType.parse("image/png"), imageBytes)); buildRequestAndSend(url, requestBodyBuilder); }); } @@ -239,9 +274,9 @@ private void buildRequestAndSend(HttpUrl url, MultipartBody.Builder requestBodyB { RequestBody requestBody = requestBodyBuilder.build(); Request request = new Request.Builder() - .url(url) - .post(requestBody) - .build(); + .url(url) + .post(requestBody) + .build(); sendRequest(request); }