feat: add defend + item to player's turn

also fixed a bug where anyone could run eval but we don't talk about that
This commit is contained in:
DaInfLoop 2024-06-20 22:17:26 +01:00
parent c16bf27cec
commit 3143423edf

View file

@ -505,7 +505,7 @@ app.action('forfeit', checkButton, async (ctx) => {
})
app.action(/attack|defend|item/, checkButton, async (ctx) => {
let response = "";
let response = "This error message isn't meant to show up. If it does, contact Haroon.";
const user = await initializeUser(ctx.context.userId);
const slackUser = (await ctx.client.users.info({ user: ctx.context.userId })).user.profile;
@ -529,10 +529,48 @@ app.action(/attack|defend|item/, checkButton, async (ctx) => {
await sql`UPDATE users SET opponenthealth = ${user.opponenthealth - damage} WHERE slack_id = ${ctx.context.userId};`
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x => x.rawId == user.currentopponent).name}_*\n\n\`\`\`${damage.toLocaleString()} DAMAGE\`\`\``
}
} else {
const damage = Math.floor(Math.random() * (user.playermax - user.playermin + 1)) + user.playermin;
await sql`UPDATE users SET opponenthealth = ${user.opponenthealth - damage} WHERE slack_id = ${ctx.context.userId};`
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x => x.rawId == user.currentopponent).name}_*\n\n\`\`\`${damage.toLocaleString()} DAMAGE\`\`\``
}
await sql`UPDATE users SET opponentdefense = 'None' WHERE slack_id = ${ctx.context.userId};`
break;
case 'defend':
if (user.playerdefendcount < 3) {
await sql`UPDATE users SET playerdefense = 'Strong' WHERE slack_id = ${ctx.context.userId};`
response = `*_A blue forcefield magically appears around ${slackUser.display_name_normalized}_*\n\n\`\`\`STRONG DEFENCE\`\`\``
} else {
const type = ["Strong", "Moderate", "Weak"][Math.floor(Math.random() * 3)];
await sql`UPDATE users SET playerdefense = ${type} WHERE slack_id = ${ctx.context.userId};`
response = `*_A blue forcefield magically appears around ${slackUser.display_name_normalized}_*\n\n\`\`\`${type.toUpperCase()} DEFENCE\`\`\``
}
break;
case 'item':
const increase = Math.floor(Math.random() * 5) + 1;
switch (['health', 'min', 'max', 'nothing'][Math.floor(Math.random() * 4)]) {
case 'health':
await sql`UPDATE users SET playerhealth = ${user.playerhealth + increase} WHERE slack_id = ${ctx.context.userId};`
response = `*_${slackUser.display_name_normalized} drinks some squash. U N D I L U T E D._*\n\n\`\`\`+ ${increase} HEALTH\`\`\``
break;
case 'min':
if ((user.playermin + increase) < user.playermax) {
response = `*_${slackUser.display_name_normalized} touches some grass_*\n\n\`\`\`NOTHING HAPPENED\`\`\``
break;
}
await sql`UPDATE users SET playermin = ${user.playermin + increase} WHERE slack_id = ${ctx.context.userId};`
response = `*_${slackUser.display_name_normalized} drinks some squash. U N D I L U T E D._*\n\n\`\`\`+ ${increase} MIN DAMAGE\`\`\``
break;
case 'max':
await sql`UPDATE users SET playermax = ${user.playermax + increase} WHERE slack_id = ${ctx.context.userId};`
response = `*_${slackUser.display_name_normalized} drinks some squash. U N D I L U T E D._*\n\n\`\`\`+ ${increase} MAX DAMAGE\`\`\``
break;
case 'nothing':
response = `*_${slackUser.display_name_normalized} touches some grass_*\n\n\`\`\`NOTHING HAPPENED\`\`\``
break;
}
}
await sql`UPDATE users SET opponentdefense = 'None' WHERE slack_id = ${ctx.context.userId};`
await ctx.respond({
"blocks": [
@ -540,7 +578,7 @@ app.action(/attack|defend|item/, checkButton, async (ctx) => {
"type": "section",
"text": {
"type": "mrkdwn",
"text": ""
"text": response
}
},
{
@ -567,6 +605,8 @@ app.action(/attack|defend|item/, checkButton, async (ctx) => {
app.command('/bm-eval', async (ctx) => {
await ctx.ack();
if (ctx.context.userId != 'U06TBP41C3E') return;
const resp = require('util').inspect(await eval(ctx.body.text), undefined, 1)
ctx.respond({