feat: no clue what i added here
This commit is contained in:
parent
3fe3d3e728
commit
1ad640d12f
208
index.js
Normal file
208
index.js
Normal file
|
@ -0,0 +1,208 @@
|
|||
const { App } = require('@slack/bolt');
|
||||
require('dotenv').config()
|
||||
|
||||
const BeginnerOpponents = require('./opponents/beginner.json');
|
||||
|
||||
const app = new App({
|
||||
token: process.env.SLACK_BOT_TOKEN,
|
||||
signingSecret: process.env.SLACK_SIGNING_SECRET
|
||||
});
|
||||
|
||||
app.command('/chooseopponent', async (ctx) => {
|
||||
await ctx.ack();
|
||||
|
||||
await ctx.client.views.open({
|
||||
trigger_id: ctx.body.trigger_id,
|
||||
view: {
|
||||
"type": "modal",
|
||||
"callback_id": "chooseopponent",
|
||||
"title": {
|
||||
"type": "plain_text",
|
||||
"text": "Choose an opponent",
|
||||
"emoji": true
|
||||
},
|
||||
"submit": {
|
||||
"type": "plain_text",
|
||||
"text": "Choose",
|
||||
"emoji": true
|
||||
},
|
||||
"close": {
|
||||
"type": "plain_text",
|
||||
"text": "Never mind",
|
||||
"emoji": true
|
||||
},
|
||||
"blocks": [
|
||||
{
|
||||
"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!`
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"element": {
|
||||
"type": "radio_buttons",
|
||||
"options": [
|
||||
{
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": "Special",
|
||||
"emoji": true
|
||||
},
|
||||
"value": "SPECIAL"
|
||||
},
|
||||
{
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": "Beginner",
|
||||
"emoji": true
|
||||
},
|
||||
"value": "BEGINNER"
|
||||
},
|
||||
{
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": "Casual",
|
||||
"emoji": true
|
||||
},
|
||||
"value": "CASUAL"
|
||||
}
|
||||
],
|
||||
"action_id": "rank-selection"
|
||||
},
|
||||
"label": {
|
||||
"type": "plain_text",
|
||||
"text": "Choose a rank:",
|
||||
"emoji": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
app.view("chooseopponent", async (ctx) => {
|
||||
const { selected_option } = Object.values(ctx.view.state.values)[0]['rank-selection'];
|
||||
|
||||
const rank = selected_option.value;
|
||||
|
||||
await ctx.ack({
|
||||
response_action: 'update',
|
||||
view: {
|
||||
"type": "modal",
|
||||
"callback_id": "chooseopponent-" + rank,
|
||||
"title": {
|
||||
"type": "plain_text",
|
||||
"text": "Choose an opponent",
|
||||
"emoji": true
|
||||
},
|
||||
"submit": {
|
||||
"type": "plain_text",
|
||||
"text": "Battle",
|
||||
"emoji": true
|
||||
},
|
||||
"close": {
|
||||
"type": "plain_text",
|
||||
"text": "Never mind",
|
||||
"emoji": true
|
||||
},
|
||||
"blocks": [
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": `*Battle Beginner*: Hey there <@${ctx.body.user.id}>! Let's keep things simple, who do you want to battle against?`
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"element": {
|
||||
"type": "static_select",
|
||||
"options": BeginnerOpponents.map(opponent =>
|
||||
({
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": `${opponent.name} // ${opponent.stats.health + opponent.stats.min + opponent.stats.max} Battle Power`,
|
||||
"emoji": true
|
||||
},
|
||||
"value": opponent.rawId
|
||||
})
|
||||
),
|
||||
"action_id": "opponents"
|
||||
},
|
||||
"label": {
|
||||
"type": "plain_text",
|
||||
"text": "Choose an opponent:",
|
||||
"emoji": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.command('/viewopponents', async (ctx) => {
|
||||
await ctx.ack();
|
||||
|
||||
const args = ctx.body.text.split(/ +/g);
|
||||
|
||||
switch (args[0].toUpperCase()) {
|
||||
case "SPECIAL":
|
||||
ctx.respond({
|
||||
text: "You're trying to view Special opponents.",
|
||||
response_type: 'ephemeral'
|
||||
})
|
||||
break;
|
||||
case "BEGINNER":
|
||||
const mappedBeginner = BeginnerOpponents.map(opponent =>
|
||||
({
|
||||
name: opponent.name,
|
||||
battlePower:
|
||||
opponent.stats.health +
|
||||
opponent.stats.min +
|
||||
opponent.stats.max
|
||||
})
|
||||
)
|
||||
|
||||
ctx.respond({
|
||||
response_type: 'ephemeral',
|
||||
text: `*Battle Master:* Greetings battler. Here are the avaliable *Beginner* opponents for you to battle.`,
|
||||
blocks: [
|
||||
{
|
||||
type: 'section',
|
||||
text: {
|
||||
type: 'mrkdwn',
|
||||
text: `*Battle Master:* Greetings <@${ctx.body.user_id}>. Here are the avaliable *Beginner* opponents for you to battle.`
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'section',
|
||||
text: {
|
||||
type: 'mrkdwn',
|
||||
text: mappedBeginner.map(opponent => `*${opponent.name}:*\n\n${opponent.battlePower} Battle Power`).join('\n\n\n')
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
break;
|
||||
case "CASUAL":
|
||||
ctx.say("You're trying to view Casual opponents.")
|
||||
break;
|
||||
default:
|
||||
ctx.say("You either wrote nothing or just chose a rank that doesn't exist.")
|
||||
}
|
||||
});
|
||||
|
||||
; (async () => {
|
||||
// Start your app
|
||||
await app.start(process.env.PORT);
|
||||
|
||||
console.log('⚡️ Bolt app is running!');
|
||||
})();
|
Loading…
Reference in a new issue