diff --git a/commands/message/dev/test.js b/commands/message/dev/test.js index b65ff4f..a1eac10 100644 --- a/commands/message/dev/test.js +++ b/commands/message/dev/test.js @@ -1,7 +1,7 @@ const { createEmbed, page } = require("#utils/embed"); const { acknowledge } = require("#utils/interactions"); -const DynamicCardStack = require("../../../labscore/cardstack/DynamicCardStack"); +const { DynamicCardStack } = require("../../../labscore/cardstack/DynamicCardStack"); module.exports = { label: "text", diff --git a/commands/message/search/anime.js b/commands/message/search/anime.js index c87d75d..bb2e698 100644 --- a/commands/message/search/anime.js +++ b/commands/message/search/anime.js @@ -7,7 +7,7 @@ const { acknowledge } = require('#utils/interactions'); const { smallPill, link, pill, stringwrapPreserveWords, timestamp, TIMESTAMP_FLAGS} = require('#utils/markdown'); const { editOrReply } = require('#utils/message'); -const DynamicCardStack = require("../../../labscore/cardstack/DynamicCardStack"); +const { DynamicCardStack } = require("../../../labscore/cardstack/DynamicCardStack"); const {STATIC_ASSETS} = require("#utils/statics"); function renderAnimeResultsPage(context, res){ diff --git a/labscore/cardstack/DynamicCardStack.js b/labscore/cardstack/DynamicCardStack.js index 873ee01..3b7d93f 100644 --- a/labscore/cardstack/DynamicCardStack.js +++ b/labscore/cardstack/DynamicCardStack.js @@ -1,13 +1,14 @@ +const { createEmbed, page } = require("#utils/embed"); const { iconAsEmojiObject } = require("#utils/markdown"); const { editOrReply } = require("#utils/message"); +const { STATIC_ASSETS } = require("#utils/statics"); + const { Context } = require("detritus-client/lib/command"); const { MessageComponentTypes, InteractionCallbackTypes } = require("detritus-client/lib/constants"); const { Message } = require("detritus-client/lib/structures"); const { ComponentContext, Components, ComponentActionRow} = require("detritus-client/lib/utils"); -const {createEmbed, page} = require("#utils/embed"); -const {STATIC_ASSETS} = require("#utils/statics"); -const activeStacks = new Map(); +const activeStacks = new WeakMap(); const DEFAULT_BUTTON_ICON_MAPPINGS = Object.freeze({ "next": "button_chevron_right", @@ -51,7 +52,7 @@ class DynamicCardStack { this.index = options.startingIndex || 0; this.rootIndex = this.index; this.loopPages = options.loop || true; - this.expires = options.expires || 1*60*1000; + this.expires = options.expires || 5*60*1000; this.uniqueId = (Date.now()*Math.random()).toString(36); @@ -78,7 +79,7 @@ class DynamicCardStack { if(clearComponents) await this._edit(this.currentPage(), []) // Remove reference to free the cardstack for GC - activeStacks.delete(this.context.message?.id); + activeStacks.delete(this.context.message); } /** @@ -92,12 +93,12 @@ class DynamicCardStack { _createDynamicCardStack(){ // Kill any previously active cardstacks - if(activeStacks.get(this.context.message?.id)){ + if(activeStacks.get(this.context.message)){ console.log(this.uniqueId + " is replacing " + this._getStackByMessageId(this.context.message?.id).uniqueId); - this._getStackByMessageId(this.context.message?.id).kill(); + this._getStackByMessageId(this.context.message).kill(); } - activeStacks.set(this.context.message?.id, this); + activeStacks.set(this.context.message, this); } _createTimeout(){ @@ -364,7 +365,6 @@ class DynamicCardStack { console.log("new category is " + this.currentSelectedSubcategory) - // TODO: allow overriding index this.index = 0; try{ @@ -413,4 +413,4 @@ class DynamicCardStack { } } -module.exports = DynamicCardStack \ No newline at end of file +module.exports.DynamicCardStack = DynamicCardStack; \ No newline at end of file