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: allow customizable delay for loot screenshots #390

Closed
wants to merge 3 commits into from
Closed
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
27 changes: 20 additions & 7 deletions src/main/java/dinkplugin/DinkPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,24 @@ default boolean lootSendImage() {
return true;
}

@ConfigItem(
keyName = "lootImageDelay",
name = "Screenshot Delay",
description = "The number of seconds to wait before capturing a screenshot",
position = 32,
section = lootSection
)
@Range(max = 10)
@Units(Units.SECONDS)
default int lootImageDelay() {
return 0;
}

@ConfigItem(
keyName = "lootIcons",
name = "Show loot icons",
description = "Show icons for the loot obtained as additional embeds",
position = 32,
position = 33,
section = lootSection
)
default boolean lootIcons() {
Expand All @@ -795,7 +808,7 @@ default boolean lootIcons() {
name = "Min Loot value",
description = "The minimum value of an item for a notification to be sent.<br/>" +
"For PK chests, the <i>total</i> value of the items is compared with this threshold",
position = 33,
position = 34,
section = lootSection
)
default int minLootValue() {
Expand All @@ -807,7 +820,7 @@ default int minLootValue() {
name = "Screenshot Min Value",
description = "The minimum combined loot value to send a screenshot.<br/>" +
"Must have 'Send Image' enabled",
position = 34,
position = 35,
section = lootSection
)
default int lootImageMinValue() {
Expand All @@ -818,7 +831,7 @@ default int lootImageMinValue() {
keyName = "lootIncludePlayer",
name = "Include PK Loot",
description = "Allow notifications for loot from player kills",
position = 35,
position = 36,
section = lootSection
)
default boolean includePlayerLoot() {
Expand All @@ -831,7 +844,7 @@ default boolean includePlayerLoot() {
description = "Whether to send PK loot to the PK override webhook URL, rather than the loot URL.<br/>" +
"Must have 'Include PK Loot' (above) enabled.<br/>" +
"Has no effect if the Player Kills notifier override URL is absent",
position = 35,
position = 36,
section = lootSection
)
default boolean lootRedirectPlayerKill() {
Expand All @@ -842,7 +855,7 @@ default boolean lootRedirectPlayerKill() {
keyName = "lootIncludeClueScrolls",
name = "Include Clue Loot",
description = "Allow notifications for loot from Clue Scrolls",
position = 36,
position = 37,
section = lootSection
)
default boolean lootIncludeClueScrolls() {
Expand All @@ -854,7 +867,7 @@ default boolean lootIncludeClueScrolls() {
name = "Item Allowlist",
description = "Always fire notifications for these items, despite value settings.<br/>" +
"Place one item name per line (case-insensitive; asterisks are wildcards)",
position = 37,
position = 38,
section = lootSection
)
default String lootItemAllowlist() {
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/dinkplugin/notifiers/LootNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ private void handleNotify(Collection<ItemStack> items, String dropper, LootRecor
}

if (sendMessage) {
String overrideUrl = getWebhookUrl();
if (config.lootRedirectPlayerKill() && !config.pkWebhook().isBlank()) {
if (type == LootRecordType.PLAYER || (type == LootRecordType.EVENT && "Loot Chest".equals(dropper))) {
overrideUrl = config.pkWebhook();
}
String overrideUrl;
if (config.lootRedirectPlayerKill() && !config.pkWebhook().isBlank() &&
(type == LootRecordType.PLAYER || (type == LootRecordType.EVENT && "Loot Chest".equals(dropper)))) {
overrideUrl = config.pkWebhook();
} else {
overrideUrl = getWebhookUrl();
}
boolean screenshot = config.lootSendImage() && totalStackValue >= config.lootImageMinValue();
Template notifyMessage = Template.builder()
Expand All @@ -249,15 +250,23 @@ private void handleNotify(Collection<ItemStack> items, String dropper, LootRecor
.replacement("%TOTAL_VALUE%", Replacements.ofText(QuantityFormatter.quantityToStackSize(totalStackValue)))
.replacement("%SOURCE%", Replacements.ofText(dropper))
.build();
createMessage(overrideUrl, screenshot,
String thumbnail = ItemUtils.getItemImageUrl(max.getId());

Runnable sendNotification = () -> createMessage(overrideUrl, screenshot,
NotificationBody.builder()
.text(notifyMessage)
.embeds(embeds)
.extra(new LootNotificationData(serializedItems, dropper, type, kc))
.type(NotificationType.LOOT)
.thumbnailUrl(ItemUtils.getItemImageUrl(max.getId()))
.thumbnailUrl(thumbnail)
.build()
);
int delay = config.lootImageDelay();
if (delay <= 0) {
sendNotification.run();
} else {
executor.schedule(sendNotification, delay, TimeUnit.SECONDS);
}
}
}

Expand Down
Loading