diff --git a/src/main/java/org/cascadebot/cascadebot/commands/developer/EvalCommand.java b/src/main/java/org/cascadebot/cascadebot/commands/developer/EvalCommand.java index 19e6847b1..35b058b5f 100644 --- a/src/main/java/org/cascadebot/cascadebot/commands/developer/EvalCommand.java +++ b/src/main/java/org/cascadebot/cascadebot/commands/developer/EvalCommand.java @@ -86,6 +86,7 @@ public void onCommand(Member sender, CommandContext context) { scriptEngine.put("context", context); scriptEngine.put("channel", context.getChannel()); scriptEngine.put("guild", context.getGuild()); + scriptEngine.put("data", context.getData()); String imports = IMPORTS.stream().map(s -> "import " + s + ".*;").collect(Collectors.joining(" ")); diff --git a/src/main/java/org/cascadebot/cascadebot/data/managers/CascadeUserDataManager.java b/src/main/java/org/cascadebot/cascadebot/data/managers/CascadeUserDataManager.java index fe8f12df7..bf0b8907d 100644 --- a/src/main/java/org/cascadebot/cascadebot/data/managers/CascadeUserDataManager.java +++ b/src/main/java/org/cascadebot/cascadebot/data/managers/CascadeUserDataManager.java @@ -10,7 +10,7 @@ import org.bson.conversions.Bson; import org.cascadebot.cascadebot.CascadeBot; import org.cascadebot.cascadebot.data.database.DebugLogCallback; -import org.cascadebot.cascadebot.data.objects.CascadeUser; +import org.cascadebot.cascadebot.data.objects.user.CascadeUser; import java.util.concurrent.TimeUnit; @@ -18,10 +18,10 @@ public class CascadeUserDataManager { - private static final String COLLECTION = "users"; + private static final String COLLECTION = "bot_users"; private static LoadingCache users = Caffeine.newBuilder() - .expireAfterAccess(5,TimeUnit.MINUTES) + .expireAfterAccess(1,TimeUnit.SECONDS) .recordStats() .build(id -> { CascadeUser user = CascadeBot.INS.getDatabaseManager().getDatabase().getCollection(COLLECTION, CascadeUser.class).find(eq("_id", id)).first(); diff --git a/src/main/java/org/cascadebot/cascadebot/data/objects/donation/Tier.java b/src/main/java/org/cascadebot/cascadebot/data/objects/donation/Tier.java index 8f0e4ff99..e5ba52325 100644 --- a/src/main/java/org/cascadebot/cascadebot/data/objects/donation/Tier.java +++ b/src/main/java/org/cascadebot/cascadebot/data/objects/donation/Tier.java @@ -122,6 +122,18 @@ public Set getFlags() { return flags; } + public Flag getFlag(String id) { + for (Flag flag : flags) { + if (flag.getId().equals(id)) { + return flag; + } + } + if (!parent.isEmpty()) { + return tiers.get(parent).getFlag(id); + } + return null; + } + /** * Returns the guild benefits gave in this tier. * diff --git a/src/main/java/org/cascadebot/cascadebot/data/objects/guild/GuildData.java b/src/main/java/org/cascadebot/cascadebot/data/objects/guild/GuildData.java index 2a0a97457..bd9845a05 100644 --- a/src/main/java/org/cascadebot/cascadebot/data/objects/guild/GuildData.java +++ b/src/main/java/org/cascadebot/cascadebot/data/objects/guild/GuildData.java @@ -19,6 +19,9 @@ import org.cascadebot.cascadebot.commandmeta.ICommandMain; import org.cascadebot.cascadebot.commandmeta.Module; import org.cascadebot.cascadebot.data.language.Locale; +import org.cascadebot.cascadebot.data.managers.CascadeUserDataManager; +import org.cascadebot.cascadebot.data.objects.donation.Tier; +import org.cascadebot.cascadebot.data.objects.user.CascadeUser; import org.cascadebot.cascadebot.utils.buttons.ButtonGroup; import org.cascadebot.cascadebot.utils.buttons.ButtonsCache; import org.cascadebot.cascadebot.utils.buttons.PersistentButtonGroup; @@ -57,13 +60,6 @@ public class GuildData { private GuildSettingsUseful usefulSettings = new GuildSettingsUseful(); private GuildModeration guildModeration = new GuildModeration(); - /* - Eventually these will be used but they're commented out for now - - private GuildModeration guildModeration = new GuildModeration(); - - */ - //endregion //region Transient fields @@ -76,6 +72,8 @@ public class GuildData { private HashMap> persistentButtons = new HashMap<>(); + private long userForTiers = -1; + @PreSave public void preSave() { this.stateLock = UUID.randomUUID(); @@ -185,4 +183,17 @@ public Collection getGuildCommandInfos() { //endregion + public Tier getGuildTier() { + if (userForTiers == -1) { + return Tier.getTier("default"); + } + + CascadeUser user = CascadeUserDataManager.getUser(userForTiers); + return user.getTier(); + } + + public void setUserForTiers(long userId) { + this.userForTiers = userId; + } + } diff --git a/src/main/java/org/cascadebot/cascadebot/data/objects/CascadeUser.java b/src/main/java/org/cascadebot/cascadebot/data/objects/user/CascadeUser.java similarity index 69% rename from src/main/java/org/cascadebot/cascadebot/data/objects/CascadeUser.java rename to src/main/java/org/cascadebot/cascadebot/data/objects/user/CascadeUser.java index 9dfdef934..af1fbb99f 100644 --- a/src/main/java/org/cascadebot/cascadebot/data/objects/CascadeUser.java +++ b/src/main/java/org/cascadebot/cascadebot/data/objects/user/CascadeUser.java @@ -3,13 +3,15 @@ * Licensed under the MIT license. */ -package org.cascadebot.cascadebot.data.objects; +package org.cascadebot.cascadebot.data.objects.user; import de.bild.codec.annotations.Id; import lombok.AccessLevel; +import lombok.Getter; import lombok.NoArgsConstructor; import org.cascadebot.cascadebot.data.objects.donation.Tier; +@Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CascadeUser { @@ -20,6 +22,10 @@ public CascadeUser(long id) { userId = id; } - private Tier tier; + private String tier = "default"; + + public Tier getTier() { + return Tier.getTier(tier); + } } diff --git a/src/main/resources/default_tiers.json b/src/main/resources/default_tiers.json index 3f645023d..d335bd48b 100644 --- a/src/main/resources/default_tiers.json +++ b/src/main/resources/default_tiers.json @@ -77,6 +77,7 @@ "music_services", "music_controls", "music_soundcloud", + "donator_node", "custom_backgrounds", "planner_agenda", "medium_badge"