Skip to content

Commit

Permalink
fix: migrate item keywords with asterisks
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Oct 6, 2024
1 parent 7728026 commit f3dfc4d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
14 changes: 6 additions & 8 deletions src/main/java/dinkplugin/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,20 @@ private void setFilteredNames(String configValue) {
log.debug("Updated RSN Filter List to: {}", filteredNames);
}

private void migrateConfig(String sourceGroup, Map<String, String> keyMappings) {
Map<String, Object> valuesByKey = new HashMap<>(keyMappings.size() * 4 / 3);
keyMappings.forEach((sourceKey, dinkKey) -> {
private void migrateConfig(MigrationUtil.Metadata data) {
Map<String, Object> valuesByKey = new HashMap<>(data.mappings().size() * 4 / 3);
data.mappings().forEach((sourceKey, dinkKey) -> {
Type valueType = configValueTypes.get(dinkKey);
if (valueType == null) return;

Object sourceValue = configManager.getConfiguration(sourceGroup, sourceKey, valueType);
var sourceValue = configManager.getConfiguration(data.configGroup(), sourceKey, valueType);
if (sourceValue != null) {
valuesByKey.put(dinkKey, sourceValue);
var transformedValue = data.transform(sourceKey, sourceValue);
valuesByKey.put(dinkKey, transformedValue);
}
});
handleImport(valuesByKey, true);
}

private void migrateConfig(MigrationUtil.Metadata data) {
migrateConfig(data.configGroup(), data.mappings());
if (data.notifierEnabledKey() != null && !isPluginDisabled(configManager, data.pluginClassName().toLowerCase()) && !data.notifierEnabled().test(config)) {
configManager.setConfiguration(CONFIG_GROUP, data.notifierEnabledKey(), true);
}
Expand Down
33 changes: 24 additions & 9 deletions src/main/java/dinkplugin/util/MigrationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@UtilityClass
public class MigrationUtil {
Expand All @@ -23,15 +24,15 @@ private Metadata getAdamMappings(DinkPluginConfig config) {
"sendScreenshot", "lootSendImage",
"lootvalue", "minLootValue"
);
return new Metadata("discordlootlogger", mappings, "DiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled");
return new Metadata("discordlootlogger", mappings, "DiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled", null);
}

private Metadata getBoredskaMappings(DinkPluginConfig config) {
// https://github.com/Boredska/gim-bank-discord/blob/master/src/main/java/gim/bank/discord/GimBankDiscordConfig.java
Map<String, String> mappings = Map.of("webhook",
config.groupStorageWebhook().isBlank() && config.notifyGroupStorage() ? "discordWebhook" : "groupStorageWebhook"
);
return new Metadata("gimbankdiscord", mappings, "GimBankDiscordPlugin", DinkPluginConfig::notifyGroupStorage, "groupStorageEnabled");
return new Metadata("gimbankdiscord", mappings, "GimBankDiscordPlugin", DinkPluginConfig::notifyGroupStorage, "groupStorageEnabled", null);
}

private Metadata getBossHusoMappings(DinkPluginConfig config) {
Expand All @@ -47,7 +48,15 @@ private Metadata getBossHusoMappings(DinkPluginConfig config) {
"sendEmbeddedMessage", "discordRichEmbeds",
"whiteListedRSNs", config.nameFilterMode() == FilterMode.ALLOW ? "ignoredNames" : ""
);
return new Metadata("discordraredropnotificater", mappings, "DiscordRareDropNotificaterPlugin", DinkPluginConfig::notifyLoot, "lootEnabled");
Function<Object, Object> itemListTransformer = v -> ConfigUtil
.readDelimited(v.toString())
.map(s -> '*' + s + '*')
.collect(Collectors.joining("\n"));
var transformers = Map.of(
"whiteListedItems", itemListTransformer,
"ignoredkeywords", itemListTransformer
);
return new Metadata("discordraredropnotificater", mappings, "DiscordRareDropNotificaterPlugin", DinkPluginConfig::notifyLoot, "lootEnabled", transformers);
}

private Metadata getJakeMappings(DinkPluginConfig config) {
Expand Down Expand Up @@ -85,15 +94,15 @@ private Metadata getJakeMappings(DinkPluginConfig config) {
Map.entry("clueMinValue", "clueMinValue"),
Map.entry("clueNotifMessage", "clueNotifMessage")
);
return new Metadata("universalDiscord", mappings, "UniversalDiscordPlugin", null, null);
return new Metadata("universalDiscord", mappings, "UniversalDiscordPlugin", null, null, null);
}

private Metadata getJamesMappings(DinkPluginConfig config) {
// https://github.com/jamesdrudolph/Discord-Death-Notifications/blob/master/src/main/java/moe/cuteanimegirls/discorddeathnotifications/DeathNotificationsConfig.java
Map<String, String> mappings = Map.of(
"webhook", config.deathWebhook().isBlank() ? "discordWebhook" : "deathWebhook"
);
return new Metadata("discorddeathnotifications", mappings, "DeathNotificationsPlugin", DinkPluginConfig::notifyDeath, "deathEnabled");
return new Metadata("discorddeathnotifications", mappings, "DeathNotificationsPlugin", DinkPluginConfig::notifyDeath, "deathEnabled", null);
}

private Metadata getPaulMappings(DinkPluginConfig config) {
Expand All @@ -103,7 +112,7 @@ private Metadata getPaulMappings(DinkPluginConfig config) {
"sendScreenshot", "collectionSendImage",
"includepets", config.notifyPet() ? "" : "petEnabled"
);
return new Metadata("discordcollectionlogger", mappings, "DiscordCollectionLoggerPlugin", DinkPluginConfig::notifyCollectionLog, "collectionLogEnabled");
return new Metadata("discordcollectionlogger", mappings, "DiscordCollectionLoggerPlugin", DinkPluginConfig::notifyCollectionLog, "collectionLogEnabled", null);
}

private Metadata getRinzMappings(DinkPluginConfig config) {
Expand All @@ -115,7 +124,7 @@ private Metadata getRinzMappings(DinkPluginConfig config) {
"valuableDropThreshold", "minLootValue",
"collectionLogItem", config.notifyCollectionLog() ? "" : "collectionLogEnabled"
);
return new Metadata("betterdiscordlootlogger", mappings, "BetterDiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled");
return new Metadata("betterdiscordlootlogger", mappings, "BetterDiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled", null);
}

private Metadata getShamerMappings(DinkPluginConfig config) {
Expand All @@ -124,7 +133,7 @@ private Metadata getShamerMappings(DinkPluginConfig config) {
"webhookLink", config.deathWebhook().isBlank() ? "discordWebhook" : "deathWebhook",
"captureOwnDeaths", config.notifyDeath() ? "" : "deathEnabled"
);
return new Metadata("raidshamer", mappings, "RaidShamerPlugin", DinkPluginConfig::notifyDeath, "deathEnabled");
return new Metadata("raidshamer", mappings, "RaidShamerPlugin", DinkPluginConfig::notifyDeath, "deathEnabled", null);
}

private Metadata getTakamokMappings(DinkPluginConfig config) {
Expand All @@ -135,7 +144,7 @@ private Metadata getTakamokMappings(DinkPluginConfig config) {
"minimumLevel", "levelMinValue",
"levelInterval", "levelInterval"
);
return new Metadata("discordlevelnotifications", mappings, "LevelNotificationsPlugin", DinkPluginConfig::notifyLevel, "levelEnabled");
return new Metadata("discordlevelnotifications", mappings, "LevelNotificationsPlugin", DinkPluginConfig::notifyLevel, "levelEnabled", null);
}

@Value
Expand All @@ -146,6 +155,12 @@ public static class Metadata {
String pluginClassName;
Predicate<DinkPluginConfig> notifierEnabled;
String notifierEnabledKey;
Map<String, Function<Object, Object>> configValueTransformers;

public Object transform(String configKey, Object configValue) {
if (configValueTransformers == null) return configValue;
return configValueTransformers.getOrDefault(configKey, v -> v).apply(configValue);
}
}

static {
Expand Down

0 comments on commit f3dfc4d

Please sign in to comment.