Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,87 @@ 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()
{
return false;
}

@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()
{
return true;
}

@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()
{
return 0;
}

@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()
{
return false;
}

@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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -44,7 +46,7 @@

@Slf4j
@PluginDescriptor(
name = "Discord Loot Logger"
name = "Discord Loot Logger"
)
public class DiscordLootLoggerPlugin extends Plugin
{
Expand All @@ -65,6 +67,10 @@ public class DiscordLootLoggerPlugin extends Plugin

private List<String> 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";
Expand Down Expand Up @@ -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<ItemStack> items)
{
WebhookBody webhookBody = new WebhookBody();

boolean sendMessage = false;
long totalValue = 0;
StringBuilder stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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);
});
}
Expand All @@ -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);
}

Expand Down