diff --git a/labscore/cardstack/index.js b/labscore/cardstack/index.js index e68835d..ddaaaf6 100644 --- a/labscore/cardstack/index.js +++ b/labscore/cardstack/index.js @@ -21,7 +21,7 @@ module.exports = { * @returns {DynamicCardStack} */ createDynamicCardStack: (context, options)=>{ - return new DynamicCardStack(context, options) + new DynamicCardStack(context, options); }, CARD_STACK_CONSTANTS: require("./constants"), } \ No newline at end of file diff --git a/labscore/cardstack/stack.js b/labscore/cardstack/stack.js index 97edd1e..27a2947 100644 --- a/labscore/cardstack/stack.js +++ b/labscore/cardstack/stack.js @@ -44,7 +44,7 @@ class DynamicCardStack { * @param {boolean} options.pageNumbers Renders Page Numbers in the footer of all embeds in cards. * @param {Function} options.pageNumberGenerator Function that renders a page number. Default style is `Page /` * @param {boolean} options.disableCloning Disables cloning a card stack when someone other than the author interacts with it. - * @param {boolean} options.ephemeral Makes the response ephemeral (primarily used by cloning) + * @param {boolean} options.flags Flags that should be used for the response message. */ constructor(context, options) { this.context = context; @@ -59,7 +59,7 @@ class DynamicCardStack { this.pageNumbers = options.pageNumbers || true; this.pageNumberGenerator = options.pageNumberGenerator || ((pg) => `Page ${pg.index + 1}/${pg.activeCardStack.length}`); this.disableCloning = options.disableCloning || false; - this.ephemeral = options.ephemeral || false; + this.flags = options.flags || 0; this.rootIndex = this.index; this.killed = false; @@ -73,7 +73,7 @@ class DynamicCardStack { this.lastInteraction = Date.now(); this.spawned = 0; - return this._spawn(); + this._spawn(); } /** @@ -87,6 +87,7 @@ class DynamicCardStack { // Remove reference to free the cardstack for GC activeStacks.delete(this.context.message || this.context.interaction); + delete this; } /** @@ -98,7 +99,7 @@ class DynamicCardStack { return setTimeout(async () => { // If we have an interaction within the expiry window // restart the expiry window with 30s - if((this.lastInteraction - this.spawned) >= 0){ + if((this.lastInteraction - this.spawned) > 0){ clearTimeout(this.timeout) this.spawned = Date.now(); // New expiry time is 30 seconds @@ -210,7 +211,7 @@ class DynamicCardStack { } // TODO: ensure flags don't get overwritten/allow supplying custom flags - if (this.ephemeral) card.flags = MessageFlags.EPHEMERAL; + card.flags = this.flags; return card; } catch (e) { @@ -276,7 +277,7 @@ class DynamicCardStack { reference: true, allowedMentions: {parse: [], repliedUser: false}, // TODO: allow supplying flags - flags: this.ephemeral ? MessageFlags.EPHEMERAL : 0 + flags: this.flags }) } catch (e) { console.error("Message editing failed:")