[nextgen/cardstack] support flags for cardstack

This commit is contained in:
bignutty 2025-02-23 00:19:47 +01:00
parent ceb8eb097b
commit 47dcf378a9
2 changed files with 8 additions and 7 deletions

View file

@ -21,7 +21,7 @@ module.exports = {
* @returns {DynamicCardStack} * @returns {DynamicCardStack}
*/ */
createDynamicCardStack: (context, options)=>{ createDynamicCardStack: (context, options)=>{
return new DynamicCardStack(context, options) new DynamicCardStack(context, options);
}, },
CARD_STACK_CONSTANTS: require("./constants"), CARD_STACK_CONSTANTS: require("./constants"),
} }

View file

@ -44,7 +44,7 @@ class DynamicCardStack {
* @param {boolean} options.pageNumbers Renders Page Numbers in the footer of all embeds in cards. * @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 <index>/<total>` * @param {Function} options.pageNumberGenerator Function that renders a page number. Default style is `Page <index>/<total>`
* @param {boolean} options.disableCloning Disables cloning a card stack when someone other than the author interacts with it. * @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) { constructor(context, options) {
this.context = context; this.context = context;
@ -59,7 +59,7 @@ class DynamicCardStack {
this.pageNumbers = options.pageNumbers || true; this.pageNumbers = options.pageNumbers || true;
this.pageNumberGenerator = options.pageNumberGenerator || ((pg) => `Page ${pg.index + 1}/${pg.activeCardStack.length}`); this.pageNumberGenerator = options.pageNumberGenerator || ((pg) => `Page ${pg.index + 1}/${pg.activeCardStack.length}`);
this.disableCloning = options.disableCloning || false; this.disableCloning = options.disableCloning || false;
this.ephemeral = options.ephemeral || false; this.flags = options.flags || 0;
this.rootIndex = this.index; this.rootIndex = this.index;
this.killed = false; this.killed = false;
@ -73,7 +73,7 @@ class DynamicCardStack {
this.lastInteraction = Date.now(); this.lastInteraction = Date.now();
this.spawned = 0; this.spawned = 0;
return this._spawn(); this._spawn();
} }
/** /**
@ -87,6 +87,7 @@ class DynamicCardStack {
// Remove reference to free the cardstack for GC // Remove reference to free the cardstack for GC
activeStacks.delete(this.context.message || this.context.interaction); activeStacks.delete(this.context.message || this.context.interaction);
delete this;
} }
/** /**
@ -98,7 +99,7 @@ class DynamicCardStack {
return setTimeout(async () => { return setTimeout(async () => {
// If we have an interaction within the expiry window // If we have an interaction within the expiry window
// restart the expiry window with 30s // restart the expiry window with 30s
if((this.lastInteraction - this.spawned) >= 0){ if((this.lastInteraction - this.spawned) > 0){
clearTimeout(this.timeout) clearTimeout(this.timeout)
this.spawned = Date.now(); this.spawned = Date.now();
// New expiry time is 30 seconds // New expiry time is 30 seconds
@ -210,7 +211,7 @@ class DynamicCardStack {
} }
// TODO: ensure flags don't get overwritten/allow supplying custom flags // TODO: ensure flags don't get overwritten/allow supplying custom flags
if (this.ephemeral) card.flags = MessageFlags.EPHEMERAL; card.flags = this.flags;
return card; return card;
} catch (e) { } catch (e) {
@ -276,7 +277,7 @@ class DynamicCardStack {
reference: true, reference: true,
allowedMentions: {parse: [], repliedUser: false}, allowedMentions: {parse: [], repliedUser: false},
// TODO: allow supplying flags // TODO: allow supplying flags
flags: this.ephemeral ? MessageFlags.EPHEMERAL : 0 flags: this.flags
}) })
} catch (e) { } catch (e) {
console.error("Message editing failed:") console.error("Message editing failed:")