new menu for battler shop

This commit is contained in:
DaInfLoop 2024-06-29 15:10:54 +01:00
parent edd59cac86
commit 9366905c97

View file

@ -1600,12 +1600,11 @@ app.view('downgrade', async (ctx) => {
} }
}); });
app.command('/battlershop', async (ctx) => { const selectedOption = new Map();
await ctx.ack(); const viewId = new Map();
await ctx.client.views.open({ function initialShop(ctx) {
trigger_id: ctx.payload.trigger_id, return {
view: {
"type": "modal", "type": "modal",
"callback_id": "battlershop", "callback_id": "battlershop",
"title": { "title": {
@ -1625,35 +1624,58 @@ app.command('/battlershop', async (ctx) => {
}, },
"blocks": [ "blocks": [
{ {
"type": "actions", "type": "section",
"elements": Object.entries(shop).map(x => { text: {
return { type: "mrkdwn",
"type": "button", text: `*Battle Special:* Heya <@${ctx.context.userId}>. Choose an accessory type you'd like take a look at.`
"text": { }
},
{
"type": "input",
block_id: "bap",
"element": {
"type": "static_select",
"placeholder": {
"type": "plain_text", "type": "plain_text",
"text": x[0], "text": "Select an accessory",
"emoji": true "emoji": true
}, },
"value": x[0], "options": Object.keys(shop).map((x) => {
"action_id": "battlershop-"+x[0] return {
"text": {
"type": "plain_text",
"text": x,
"emoji": true
},
"value": x
}
}),
"action_id": "static_select-action"
},
"label": {
"type": "plain_text",
"text": "Choose an accessory",
"emoji": true
} }
})
} }
] ]
} }
}) }
});
const selectedOption = new Map(); app.command('/battlershop', async (ctx) => {
app.action(/battlershop-(.+)/, async (ctx) => {
await ctx.ack(); await ctx.ack();
selectedOption.set(ctx.context.userId, ctx.payload.action_id.slice(12)); const v = await ctx.client.views.open({
}) trigger_id: ctx.payload.trigger_id,
view: initialShop(ctx)
});
//viewId.set(ctx.context.userId, v.view.id)
});
app.view("battlershop", async (ctx) => { app.view("battlershop", async (ctx) => {
const sel = `${selectedOption.get(ctx.context.userId)}` const sel = ctx.view.state.values.bap['static_select-action'].selected_option.value
await ctx.ack({ response_action: 'push', view: { await ctx.ack({ response_action: 'push', view: {
"type": "modal", "type": "modal",
@ -1672,6 +1694,13 @@ app.view("battlershop", async (ctx) => {
"text": "Back" "text": "Back"
}, },
"blocks": [ "blocks": [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Choose what you'd like to look at and the colour.`
}
},
{ {
"type": "actions", "type": "actions",
"elements": [ "elements": [
@ -1694,6 +1723,7 @@ app.view("battlershop", async (ctx) => {
], ],
"action_id": "accessory-type" "action_id": "accessory-type"
}, },
...(sel != "Buddy" ? [
{ {
"type": "static_select", "type": "static_select",
"placeholder": { "placeholder": {
@ -1729,11 +1759,12 @@ app.view("battlershop", async (ctx) => {
], ],
"action_id": "actionId-1" "action_id": "actionId-1"
} }
] : [])
] ]
}, },
{ {
"type": "image", "type": "image",
"image_url": "https://assets3.thrillist.com/v1/image/1682388/size/tl-horizontal_main.jpg", "image_url": `https://generator.battlemaster.obl.ong/battler.png?${sel.toLowerCase() == "base" ? "colour" : sel.toLowerCase()}=${"None"}`,
"alt_text": "Battler preview" "alt_text": "Battler preview"
} }
] ]