new menu for battler shop

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

189
index.js
View file

@ -1600,60 +1600,82 @@ app.view('downgrade', async (ctx) => {
}
});
const selectedOption = new Map();
const viewId = new Map();
function initialShop(ctx) {
return {
"type": "modal",
"callback_id": "battlershop",
"title": {
"type": "plain_text",
"text": "Battler Shop",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Select",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Never mind",
"emoji": true
},
"blocks": [
{
"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": "Select an accessory",
"emoji": true
},
"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
}
}
]
}
}
app.command('/battlershop', async (ctx) => {
await ctx.ack();
await ctx.client.views.open({
const v = await ctx.client.views.open({
trigger_id: ctx.payload.trigger_id,
view: {
"type": "modal",
"callback_id": "battlershop",
"title": {
"type": "plain_text",
"text": "Battler Shop",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Select",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Never mind",
"emoji": true
},
"blocks": [
{
"type": "actions",
"elements": Object.entries(shop).map(x => {
return {
"type": "button",
"text": {
"type": "plain_text",
"text": x[0],
"emoji": true
},
"value": x[0],
"action_id": "battlershop-"+x[0]
}
})
}
]
}
})
view: initialShop(ctx)
});
//viewId.set(ctx.context.userId, v.view.id)
});
const selectedOption = new Map();
app.action(/battlershop-(.+)/, async (ctx) => {
await ctx.ack();
selectedOption.set(ctx.context.userId, ctx.payload.action_id.slice(12));
})
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,46 +1723,48 @@ app.view("battlershop", async (ctx) => {
],
"action_id": "accessory-type"
},
{
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Select a colour",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "*plain_text option 0*",
"emoji": true
},
"value": "value-0"
...(sel != "Buddy" ? [
{
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Select a colour",
"emoji": true
},
{
"text": {
"type": "plain_text",
"text": "*plain_text option 1*",
"emoji": true
"options": [
{
"text": {
"type": "plain_text",
"text": "*plain_text option 0*",
"emoji": true
},
"value": "value-0"
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "*plain_text option 2*",
"emoji": true
{
"text": {
"type": "plain_text",
"text": "*plain_text option 1*",
"emoji": true
},
"value": "value-1"
},
"value": "value-2"
}
],
"action_id": "actionId-1"
}
{
"text": {
"type": "plain_text",
"text": "*plain_text option 2*",
"emoji": true
},
"value": "value-2"
}
],
"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"
}
]