diff --git a/index.js b/index.js index 4251640..754b575 100644 --- a/index.js +++ b/index.js @@ -27,11 +27,27 @@ async function initializeUser(slackUserId) { if (a.length === 0) { a = await sql`INSERT INTO users (slack_id) VALUES (${slackUserId}) RETURNING *;` await sql`INSERT INTO cooldowns (slack_id) VALUES (${slackUserId});` + await sql`INSERT INTO customization (slack_id) VALUES (${slackUserId});` } return a[0]; } +async function getBattlerUrl(slackUserId, endpoint = "battler.png") { + const [ user ] = await sql`SELECT * FROM customization WHERE slack_id = ${slackUserId};` + + const url = new URL(endpoint, "https://generator.battlemaster.obl.ong/"); + + const a = Object.entries(user); + + for (let x of a) { + if (x[0] == "slack_id") continue; + url.searchParams.append(x[0], x[1] || "") + } + + return url.href; +} + app.use(async (ctx) => { await initializeUser(ctx.context.userId) @@ -137,7 +153,7 @@ ${user.battlemessage}` }) }); -function generateProfile(dbUser, slackUser) { +async function generateProfile(dbUser, slackUser) { return [ { "type": "section", @@ -184,7 +200,12 @@ function generateProfile(dbUser, slackUser) { "type": "mrkdwn", "text": `*Creation Shards:* ${dbUser.cshards}\n*Destruction Shards:* ${dbUser.dshards}\n*Skill Points:* ${dbUser.spoints}` } - ] + ], + "accessory": { + type: "image", + image_url: (await getBattlerUrl(dbUser.slack_id, "profilebattler.png")) + "&username=" + slackUser.display_name_normalized, + alt_text: "user battler" + } } ] } @@ -213,7 +234,7 @@ app.command('/profile', async (ctx) => { "text": `<@${ctx.body.user_id}> ran \`/profile @${slackUser.display_name_normalized}\`` } }, - ...generateProfile(dbUser, slackUser) + ...await generateProfile(dbUser, slackUser) ] }) } @@ -246,7 +267,7 @@ app.command('/profile', async (ctx) => { "text": `<@${ctx.body.user_id}> ran \`/profile\`` } }, - ...generateProfile(dbUser, slackUser) + ...await generateProfile(dbUser, slackUser) ] }) } @@ -450,6 +471,14 @@ app.view("chooseopponent1", async (ctx) => { } ] }, + { + type: 'image', + title: { + type: 'plain_text', + text: `${slackUser.display_name_normalized} vs ${opponent.name}` + }, + image_url: await getBattlerUrl(userId, "battlesquadfight.png") + `&username=${encodeURIComponent(slackUser.display_name_normalized)}&opponent=${opponent.rawId}` + }, ...(opponent.battleAwareness ? [{ type: 'section', text: { @@ -800,6 +829,11 @@ app.action(/attack|defend|item/, checkButton, async (ctx) => { "text": response } }, + { + type: 'image', + image_url: `https://generator.battlemaster.obl.ong/playeraction.png?action=${ctx.payload.action_id.charAt(0).toUpperCase() + ctx.payload.action_id.slice(1)}+Left&player=${encodeURIComponent(await getBattlerUrl(ctx.context.userId))}`, + alt_text: ctx.payload.action_id.charAt(0).toUpperCase() + }, { "type": "actions", "elements": [ diff --git a/opponents/beginner.js b/opponents/beginner.js index f07c803..705a2f1 100644 --- a/opponents/beginner.js +++ b/opponents/beginner.js @@ -1,6 +1,6 @@ module.exports = [ { - "rawId": "rapStar", + "rawId": "RapStar", "name": "Rap Star", "stats": { "health": 25, @@ -26,7 +26,7 @@ module.exports = [ } }, { - rawId: "artMaster", + rawId: "ArtMaster", name: "Art Master", stats: { health: 28, @@ -51,7 +51,7 @@ module.exports = [ } }, { - rawId: "guitarHero", + rawId: "GuitarHero", name: "Guitar Hero", stats: { health: 30, @@ -75,7 +75,7 @@ module.exports = [ } }, { - rawId: "delta", + rawId: "Delta", name: "Delta", stats: { health: 40, @@ -102,7 +102,7 @@ module.exports = [ } }, { - rawId: "smallKey", + rawId: "SmallKeyMaster", name: "Small KeyMaster", stats: { health: 35, @@ -131,7 +131,7 @@ module.exports = [ } }, { - rawId: "common", + rawId: "CommonOverseer", name: "Common Overseer", stats: { health: 45, diff --git a/opponents/special.js b/opponents/special.js index d5cbbd2..4a61ce2 100644 --- a/opponents/special.js +++ b/opponents/special.js @@ -1,6 +1,6 @@ module.exports = [ { - "rawId": "battler", + "rawId": "Battler", "name": "Battler", "stats": { health: (user) => user.health * 2, @@ -27,7 +27,7 @@ module.exports = [ } }, { - "rawId": "elliton", + "rawId": "BattlerElite", "name": "Battler Elite", "stats": { health: (user) => user.health * 3, @@ -52,7 +52,7 @@ module.exports = [ deniedIntro: `Battler Elite is a Battle Master Elite opponent. As well as this, he is due to recieve some changes, so for the time being I have locked him from being battled. If you wish to fight him, please ping me (Haroon) in <#C078SS377PE|battle-master>.` }, { - rawId: "sleepParalysisDemon", + rawId: "DEMUL", name: "DEMUL", stats: { health: (user) => user.maxdmg * 10, @@ -74,7 +74,7 @@ module.exports = [ } }, { - rawId: "incomingSword", + rawId: "IncomingSword", name: "Incoming Sword", stats: { health: (user) => user.maxdmg * 5, @@ -215,7 +215,7 @@ module.exports = [ } }, { - rawId: "masterOG", + rawId: "MasterOG", name: "Master OG", stats: { health: (user) => user.maxdmg * 30,