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:
parent
c16bf27cec
commit
3143423edf
72
index.js
72
index.js
|
@ -401,9 +401,9 @@ If you want to choose an opponent yourself, simply use \`/chooseopponent\` to ge
|
|||
await ctx.next();
|
||||
}
|
||||
|
||||
async function playerLoss(ctx) {}
|
||||
async function playerLoss(ctx) { }
|
||||
|
||||
async function playerWin(ctx) {}
|
||||
async function playerWin(ctx) { }
|
||||
|
||||
app.action("continue", checkButton, async (ctx) => {
|
||||
const user = await initializeUser(ctx.context.userId);
|
||||
|
@ -428,13 +428,13 @@ app.action("continue", checkButton, async (ctx) => {
|
|||
},
|
||||
{
|
||||
"type": "mrkdwn",
|
||||
"text": `${AllOpponents.find(x=> x.rawId == user.currentopponent).name}:\n\n*Health:* ${user.opponenthealth}\n*Min Damage:* ${user.opponentmin}\n*Max Damage:* ${user.opponentmax}`
|
||||
"text": `${AllOpponents.find(x => x.rawId == user.currentopponent).name}:\n\n*Health:* ${user.opponenthealth}\n*Min Damage:* ${user.opponentmin}\n*Max Damage:* ${user.opponentmax}`
|
||||
}
|
||||
],
|
||||
"accessory": {
|
||||
"type": "image",
|
||||
"image_url": AllOpponents.find(x=> x.rawId == user.currentopponent).image,
|
||||
"alt_text": AllOpponents.find(x=> x.rawId == user.currentopponent).name
|
||||
"image_url": AllOpponents.find(x => x.rawId == user.currentopponent).image,
|
||||
"alt_text": AllOpponents.find(x => x.rawId == user.currentopponent).name
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -442,7 +442,7 @@ app.action("continue", checkButton, async (ctx) => {
|
|||
"elements": [
|
||||
{
|
||||
"type": "mrkdwn",
|
||||
"text": `*${slackUser.display_name_normalized}* vs *${AllOpponents.find(x=> x.rawId == user.currentopponent).name}* | Your Turn`
|
||||
"text": `*${slackUser.display_name_normalized}* vs *${AllOpponents.find(x => x.rawId == user.currentopponent).name}* | Your Turn`
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -505,42 +505,80 @@ 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;
|
||||
|
||||
switch (ctx.payload.action_id) {
|
||||
case 'attack':
|
||||
if (user.opponentdefense == 'Strong') {
|
||||
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x => x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||
} else if (user.opponentdefense == 'Moderate') {
|
||||
if (Math.random() < 0.5) {
|
||||
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x => x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||
} else {
|
||||
const damage = Math.floor(Math.random() * (user.playermax - user.playermin + 1) ) + user.playermin;
|
||||
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\`\`\``
|
||||
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x => x.rawId == user.currentopponent).name}_*\n\n\`\`\`${damage.toLocaleString()} DAMAGE\`\`\``
|
||||
}
|
||||
} else if (user.opponentdefense == 'Weak') {
|
||||
if (Math.random() < 0.25) {
|
||||
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x => x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||
} else {
|
||||
const damage = Math.floor(Math.random() * (user.playermax - user.playermin + 1) ) + user.playermin;
|
||||
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\`\`\``
|
||||
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": [
|
||||
{
|
||||
"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({
|
||||
|
|
Loading…
Reference in a new issue