Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Include world and regionId as metadata with every notifier message #490

Merged
merged 11 commits into from
Jun 15, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Minor: Send logout notifications to the Custom Metadata Handler in advanced settings. (#492)
- Bugfix: Fire death notifications for Doom modifier in Fortis Colosseum. (#474)
- Dev: Include player region and world to notification metadata for all notifiers. (#490)
- Dev: Allow custom webhook handlers to use HTTP status code 307 and 308 to redirect requests. (#484)
- Dev: Add message source to chat notification metadata. (#476)

Expand Down
8 changes: 6 additions & 2 deletions docs/json-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ JSON sent with every notification:
"type": "NOTIFICATION_TYPE",
"playerName": "your rsn",
"accountType": "NORMAL | IRONMAN | HARDCORE_IRONMAN",
"seasonalWorld": "true | false",
"dinkAccountHash": "abcdefghijklmnopqrstuvwxyz1234abcdefghijklmnopqrstuvwxyz",
"embeds": []
}
Expand All @@ -47,12 +48,15 @@ JSON sent with every notification but only in certain circumstances:
"id":"012345678910111213",
"name":"Gamer",
"avatarHash":"abc123def345abc123def345abc123de"
},
},
"world": 518,
"regionId": 12850,
```

`clanName` is only sent when the player is in a clan and has the advanced setting `Send Clan Name` enabled.
`groupIronClanName` is only sent when the player is a GIM and has the advanced setting `Send GIM Clan Name` enabled.
The `discordUser` object is only sent when Discord is open and the advanced setting `Send Discord Profile` is enabled.
The `discordUser` object is only sent when Discord is open and the advanced setting `Send Discord Profile` is enabled.
`world` and `regionId` are only sent when the advanced setting `Include Location` is enabled (default: true).

Note: The examples below omit `playerName`, `accountType`, and `dinkAccountHash` keys because they are always the same.

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/dinkplugin/DinkPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,17 @@ default boolean ignoreSeasonal() {
return false;
}

@ConfigItem(
keyName = "pkIncludeLocation", // legacy name to avoid config migration code
name = "Include Location",
description = "Whether to include the player location and world in notification metadata.",
position = 1016,
section = advancedSection
)
default boolean includeLocation() {
return true;
}

@ConfigItem(
keyName = "discordWebhook", // do not rename; would break old configs
name = "Primary Webhook URLs",
Expand Down Expand Up @@ -1644,24 +1655,13 @@ default int pkMinValue() {
return 0;
}

@ConfigItem(
keyName = "pkIncludeLocation",
name = "Include Location",
description = "Whether notifications should include the world and location of the killed player.",
position = 135,
section = pkSection
)
default boolean pkIncludeLocation() {
return true;
}

@ConfigItem(
keyName = "pkNotifyMessage",
name = "Notification Message",
description = "The message to be sent through the webhook.<br/>" +
"Use %USERNAME% to insert your username<br/>" +
"Use %TARGET% to insert the victim's username",
position = 136,
position = 135,
section = pkSection
)
default String pkNotifyMessage() {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dinkplugin/message/DiscordMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dinkplugin.notifiers.data.NotificationData;
import dinkplugin.util.DiscordProfile;
import dinkplugin.util.Utils;
import dinkplugin.util.WorldUtils;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
Expand Down Expand Up @@ -241,6 +242,16 @@ private NotificationBody<?> enrichBody(NotificationBody<?> mBody, boolean sendIm

NotificationBody.NotificationBodyBuilder<?> builder = mBody.toBuilder();

if (config.includeLocation()) {
if (mBody.getWorld() == null) {
builder.world(client.getWorld());
}

if (mBody.getRegionId() == null) {
builder.regionId(WorldUtils.getLocation(client).getRegionID());
}
}

if (config.sendDiscordUser()) {
builder.discordUser(DiscordProfile.of(discordService.getCurrentUser()));
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/dinkplugin/message/NotificationBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class NotificationBody<T extends NotificationData> {
String groupIronClanName;
boolean seasonalWorld;
@Nullable
Integer world;
@Nullable
Integer regionId;
@Nullable
T extra;
@NotNull
@EqualsAndHashCode.Include
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dinkplugin/notifiers/PlayerKillNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void handleKill(Player target, int myLastDamage) {
if (value < minValue)
return;

boolean sendLocation = config.pkIncludeLocation();
boolean sendLocation = config.includeLocation();
PlayerKillNotificationData extra = new PlayerKillNotificationData(
target.getName(),
target.getCombatLevel(),
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/dinkplugin/notifiers/MockedNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.runelite.api.Player;
import net.runelite.api.Varbits;
import net.runelite.api.WorldType;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.config.ConfigDescriptor;
Expand Down Expand Up @@ -108,6 +109,7 @@ protected void setUp() {
when(client.getLocalPlayer()).thenReturn(localPlayer);
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
when(localPlayer.getName()).thenReturn(PLAYER_NAME);
when(localPlayer.getWorldLocation()).thenReturn(new WorldPoint(2500, 2500, 0));

doAnswer(invocation -> {
Consumer<Image> callback = invocation.getArgument(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void setUp() {
// init config mocks
when(config.notifyPk()).thenReturn(true);
when(config.pkMinValue()).thenReturn(EQUIPMENT_VALUE);
when(config.pkIncludeLocation()).thenReturn(true);
when(config.includeLocation()).thenReturn(true);
when(config.pkNotifyMessage()).thenReturn("%USERNAME% has PK'd %TARGET%");
when(config.playerLookupService()).thenReturn(PlayerLookupService.NONE);

Expand Down
Loading