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) => {
await ctx.ack();
const selectedOption = new Map();
const viewId = new Map();
await ctx.client.views.open({
trigger_id: ctx.payload.trigger_id,
view: {
function initialShop(ctx) {
return {
"type": "modal",
"callback_id": "battlershop",
"title": {
@ -1625,35 +1624,58 @@ app.command('/battlershop', async (ctx) => {
},
"blocks": [
{
"type": "actions",
"elements": Object.entries(shop).map(x => {
return {
"type": "button",
"text": {
"type": "section",
text: {
type: "mrkdwn",
text: `*Battle Special:* Heya <@${ctx.context.userId}>. Choose an accessory type you'd like take a look at.`
}
},
{
"type": "input",
block_id: "bap",
"element": {
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": x[0],
"text": "Select an accessory",
"emoji": true
},
"value": x[0],
"action_id": "battlershop-"+x[0]
"options": Object.keys(shop).map((x) => {
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.action(/battlershop-(.+)/, async (ctx) => {
app.command('/battlershop', async (ctx) => {
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) => {
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: {
"type": "modal",
@ -1672,6 +1694,13 @@ app.view("battlershop", async (ctx) => {
"text": "Back"
},
"blocks": [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Choose what you'd like to look at and the colour.`
}
},
{
"type": "actions",
"elements": [
@ -1694,6 +1723,7 @@ app.view("battlershop", async (ctx) => {
],
"action_id": "accessory-type"
},
...(sel != "Buddy" ? [
{
"type": "static_select",
"placeholder": {
@ -1729,11 +1759,12 @@ app.view("battlershop", async (ctx) => {
],
"action_id": "actionId-1"
}
] : [])
]
},
{
"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"
}
]