feat: upgrades
This commit is contained in:
parent
c8d528b48f
commit
b5cea8ee2e
185
index.js
185
index.js
|
@ -173,10 +173,16 @@ function generateProfile(dbUser, slackUser) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "section",
|
"type": "section",
|
||||||
"text": {
|
"fields": [
|
||||||
|
{
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": `*Base Health:* ${dbUser.health}\n*Base Min Damage:* ${dbUser.mindmg}\n*Base Max Damage:* ${dbUser.maxdmg}`
|
"text": `*Base Health:* ${dbUser.health}\n*Base Min Damage:* ${dbUser.mindmg}\n*Base Max Damage:* ${dbUser.maxdmg}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "mrkdwn",
|
||||||
|
"text": `*Creation Shards:* ${dbUser.cshards}\n*Destruction Shards:* ${dbUser.dshards}\n*Skill Points:* ${dbUser.spoints}`
|
||||||
}
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1012,7 +1018,7 @@ function getTimeDifference(date1, date2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.command('/b-daily', async (ctx) => {
|
app.command('/daily', async (ctx) => {
|
||||||
await ctx.ack();
|
await ctx.ack();
|
||||||
const [ cooldown ] = await sql`SELECT * FROM cooldowns WHERE slack_id = ${ctx.context.userId};`
|
const [ cooldown ] = await sql`SELECT * FROM cooldowns WHERE slack_id = ${ctx.context.userId};`
|
||||||
const user = await initializeUser(ctx.context.userId)
|
const user = await initializeUser(ctx.context.userId)
|
||||||
|
@ -1057,7 +1063,7 @@ app.command('/b-daily', async (ctx) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.command('/b-weekly', async (ctx) => {
|
app.command('/weekly', async (ctx) => {
|
||||||
await ctx.ack();
|
await ctx.ack();
|
||||||
const [ cooldown ] = await sql`SELECT * FROM cooldowns WHERE slack_id = ${ctx.context.userId};`
|
const [ cooldown ] = await sql`SELECT * FROM cooldowns WHERE slack_id = ${ctx.context.userId};`
|
||||||
const user = await initializeUser(ctx.context.userId)
|
const user = await initializeUser(ctx.context.userId)
|
||||||
|
@ -1102,7 +1108,7 @@ app.command('/b-weekly', async (ctx) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.command('/b-monthly', async (ctx) => {
|
app.command('/monthly', async (ctx) => {
|
||||||
await ctx.ack();
|
await ctx.ack();
|
||||||
const [ cooldown ] = await sql`SELECT * FROM cooldowns WHERE slack_id = ${ctx.context.userId};`
|
const [ cooldown ] = await sql`SELECT * FROM cooldowns WHERE slack_id = ${ctx.context.userId};`
|
||||||
const user = await initializeUser(ctx.context.userId)
|
const user = await initializeUser(ctx.context.userId)
|
||||||
|
@ -1147,6 +1153,177 @@ app.command('/b-monthly', async (ctx) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.command('/upgrade', async (ctx) => {
|
||||||
|
await ctx.ack();
|
||||||
|
|
||||||
|
const user = await initializeUser(ctx.context.userId);
|
||||||
|
|
||||||
|
await ctx.client.views.open({
|
||||||
|
trigger_id: ctx.body.trigger_id,
|
||||||
|
view: {
|
||||||
|
"private_metadata": ctx.payload.channel_id,
|
||||||
|
"type": "modal",
|
||||||
|
"callback_id": "upgrade",
|
||||||
|
"title": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Upgrade your stats",
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"submit": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Upgrade",
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"close": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Never mind",
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"text": {
|
||||||
|
"type": "mrkdwn",
|
||||||
|
"text": `*Battle Builder:* Helloooo <@${ctx.context.userId}>! You're here to upgrade yourself right? No problem! What would you like to... Erm... Upgrade?-`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"block_id": "select",
|
||||||
|
"type": "input",
|
||||||
|
"element": {
|
||||||
|
"type": "static_select",
|
||||||
|
"placeholder": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Choose a statistic...",
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"text": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Health // 5 Skill Points" + (user.spoints < 5 ? " :lock:" : ""),
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"value": "health"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Min Damage // 10 Skill Points" + (user.spoints < 10 || user.mindmg + 5 == user.maxdmg ? " :lock:" : ""),
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"value": "mindmg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Max Damage // 15 Skill Points" + (user.spoints < 15 ? " :lock:" : ""),
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"value": "maxdmg"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action_id": "upgrade-modal"
|
||||||
|
},
|
||||||
|
"label": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "What would you like to upgrade?",
|
||||||
|
"emoji": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
app.view('upgrade', async (ctx) => {
|
||||||
|
const user = await initializeUser(ctx.context.userId);
|
||||||
|
|
||||||
|
const { selected_option } = ctx.view.state.values['select']['upgrade-modal'];
|
||||||
|
|
||||||
|
if (selected_option.value == "health" && user.spoints < 5) {
|
||||||
|
return await ctx.ack({
|
||||||
|
response_action: 'errors',
|
||||||
|
errors: {
|
||||||
|
'select': "You don't have enough skill points to upgrade your health!"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (selected_option.value == "mindmg" && user.spoints < 10) {
|
||||||
|
return await ctx.ack({
|
||||||
|
response_action: 'errors',
|
||||||
|
errors: {
|
||||||
|
'select': "You don't have enough skill points to upgrade your minimum damage!"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (selected_option == "mindmg" && user.mindmg + 5 == user.maxdmg) {
|
||||||
|
return await ctx.ack({
|
||||||
|
response_action: 'errors',
|
||||||
|
errors: {
|
||||||
|
'select': "You need to upgrade your maximum damage first!"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (selected_option.value == "maxdmg" && user.spoints < 15) {
|
||||||
|
return await ctx.ack({
|
||||||
|
response_action: 'errors',
|
||||||
|
errors: {
|
||||||
|
'select': "You don't have enough skill points to upgrade your maximum damage!"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.ack();
|
||||||
|
|
||||||
|
if (selected_option.value == "health") {
|
||||||
|
await sql`UPDATE users SET spoints = ${user.spoints - 5}, health = ${user.health + 1} WHERE slack_id = ${ctx.context.userId};`
|
||||||
|
|
||||||
|
await ctx.client.chat.postEphemeral({
|
||||||
|
channel: ctx.view.private_metadata,
|
||||||
|
user: ctx.context.userId,
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: `*Battle Builder:* Yayyy <@${ctx.context.userId}>! Your health has been successfully increased!\n\n\`\`\`HEALTH INCREASED (${user.health} > ${user.health + 1})\`\`\``
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
} else if (selected_option.value == "mindmg") {
|
||||||
|
await sql`UPDATE users SET spoints = ${user.spoints - 10}, mindmg = ${user.mindmg + 1} WHERE slack_id = ${ctx.context.userId};`
|
||||||
|
|
||||||
|
await ctx.client.chat.postEphemeral({
|
||||||
|
channel: ctx.view.private_metadata,
|
||||||
|
user: ctx.context.userId,
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: `*Battle Builder:* Yayyy <@${ctx.context.userId}>! Your minimum damage has been successfully increased!\n\n\`\`\`MIN DAMAGE INCREASED (${user.mindmg} > ${user.mindmg + 1})\`\`\``
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
} else if (selected_option.value == "maxdmg") {
|
||||||
|
await sql`UPDATE users SET spoints = ${user.spoints - 15}, maxdmg = ${user.maxdmg + 1} WHERE slack_id = ${ctx.context.userId};`
|
||||||
|
|
||||||
|
await ctx.client.chat.postEphemeral({
|
||||||
|
channel: ctx.view.private_metadata,
|
||||||
|
user: ctx.context.userId,
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: `*Battle Builder:* Yayyy <@${ctx.context.userId}>! Your maximum damage has been successfully increased!\n\n\`\`\`MAX DAMAGE INCREASED (${user.maxdmg} > ${user.maxdmg + 1})\`\`\``
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
; (async () => {
|
; (async () => {
|
||||||
await app.start(process.env.PORT);
|
await app.start(process.env.PORT);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue