feat: initial battle prompt + button protection

This commit is contained in:
DaInfLoop 2024-06-20 18:31:27 +01:00
parent c0c45f75ac
commit 076b9f1a38

117
index.js
View file

@ -85,7 +85,7 @@ ${user.battlemessage}`
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*Battle Support*: Hiya <@${ctx.body.user_id}>! What rank opponent would you like to battle against?\n\nNot sure yet? Don't worry! Just cancel out and view what opponents you can fight with /viewopponents!`
"text": `*Battle Support*: Hiya <@${ctx.body.user_id}>! What rank opponent would you like to battle against?\n\nNot sure yet? Don't worry! Just cancel out and view what opponents you can fight with \`/viewopponents\`!`
}
},
{
@ -347,7 +347,7 @@ app.view("chooseopponent-BEGINNER", async (ctx) => {
text: {
type: 'mrkdwn',
text: opponent.intro.replaceAll("{player}", slackUser.display_name_normalized)
},
},
"accessory": {
"type": "image",
"image_url": opponent.image,
@ -359,12 +359,13 @@ app.view("chooseopponent-BEGINNER", async (ctx) => {
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Continue",
"emoji": true
},
"value": "continue",
"value": userId,
"action_id": "continue"
}
]
@ -375,6 +376,116 @@ app.view("chooseopponent-BEGINNER", async (ctx) => {
await sql`UPDATE users SET battlemessage = ${`https://hackclub.slack.com/archives/${channelId}/p${msg.ts.replace('.', '')}`} WHERE slack_id = ${userId};`
})
async function checkButton(ctx) {
await ctx.ack();
if (ctx.payload.value != ctx.context.userId) {
return ctx.respond({
replace_original: false,
response_type: 'ephemeral',
text: "Battle Support: Please do not click other battlers buttons!",
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*Battle Support:* Erm, <@${ctx.context.userId}>?... Please don't press other battlers buttons!
If you want to choose an opponent yourself, simply use \`/chooseopponent\` to get started!`
}
}
]
})
}
await ctx.next();
}
app.action("continue", checkButton, async (ctx) => {
const user = await initializeUser(ctx.context.userId);
const slackUser = (await ctx.client.users.info({ user: ctx.context.userId })).user.profile;
ctx.respond({
replace_original: true,
text: "",
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": `${slackUser.display_name_normalized}:\n\n*Health:* 20\n*Min Damage:* 1\n*Max Damage:* 9`
},
{
"type": "mrkdwn",
"text": `${AllOpponents.find(x=> x.rawId == user.currentopponent).name}:\n\n*Health:* 25\n*Min Damage:* 2\n*Max Damage:* 5`
}
],
"accessory": {
"type": "image",
"image_url": "https://media.discordapp.net/attachments/1108683335347212389/1118119440702242816/BM_-_Rap_Star_1.png?ex=6674a820&is=667356a0&hm=520cf408d3cadad838b0d2350fb212470949257cbd2768bfea64523feb33b494&",
"alt_text": AllOpponents.find(x=> x.rawId == user.currentopponent).name
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": `*${slackUser.display_name_normalized}* vs *${AllOpponents.find(x=> x.rawId == user.currentopponent).name}*`
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "⚔️ Attack",
"emoji": true
},
"value": ctx.context.userId,
"action_id": "attack"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "🛡️ Defend",
"emoji": true
},
"value": ctx.context.userId,
"action_id": "defend"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": " 🎁 Item",
"emoji": true
},
"value": ctx.context.userId,
"action_id": "item"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "☠️ Forfeit",
"emoji": true
},
"style": "danger",
"value": ctx.context.userId,
"action_id": "actionId-4"
}
]
}
]
})
})
app.command('/bm-eval', async (ctx) => {
await ctx.ack();