feat: simple battler customisation
This commit is contained in:
parent
78dd59d686
commit
6e17f7175e
42
index.js
42
index.js
|
@ -27,11 +27,27 @@ async function initializeUser(slackUserId) {
|
||||||
if (a.length === 0) {
|
if (a.length === 0) {
|
||||||
a = await sql`INSERT INTO users (slack_id) VALUES (${slackUserId}) RETURNING *;`
|
a = await sql`INSERT INTO users (slack_id) VALUES (${slackUserId}) RETURNING *;`
|
||||||
await sql`INSERT INTO cooldowns (slack_id) VALUES (${slackUserId});`
|
await sql`INSERT INTO cooldowns (slack_id) VALUES (${slackUserId});`
|
||||||
|
await sql`INSERT INTO customization (slack_id) VALUES (${slackUserId});`
|
||||||
}
|
}
|
||||||
|
|
||||||
return a[0];
|
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) => {
|
app.use(async (ctx) => {
|
||||||
await initializeUser(ctx.context.userId)
|
await initializeUser(ctx.context.userId)
|
||||||
|
|
||||||
|
@ -137,7 +153,7 @@ ${user.battlemessage}`
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateProfile(dbUser, slackUser) {
|
async function generateProfile(dbUser, slackUser) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"type": "section",
|
"type": "section",
|
||||||
|
@ -184,7 +200,12 @@ function generateProfile(dbUser, slackUser) {
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": `*Creation Shards:* ${dbUser.cshards}\n*Destruction Shards:* ${dbUser.dshards}\n*Skill Points:* ${dbUser.spoints}`
|
"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}\``
|
"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\``
|
"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 ? [{
|
...(opponent.battleAwareness ? [{
|
||||||
type: 'section',
|
type: 'section',
|
||||||
text: {
|
text: {
|
||||||
|
@ -800,6 +829,11 @@ app.action(/attack|defend|item/, checkButton, async (ctx) => {
|
||||||
"text": response
|
"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",
|
"type": "actions",
|
||||||
"elements": [
|
"elements": [
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
"rawId": "rapStar",
|
"rawId": "RapStar",
|
||||||
"name": "Rap Star",
|
"name": "Rap Star",
|
||||||
"stats": {
|
"stats": {
|
||||||
"health": 25,
|
"health": 25,
|
||||||
|
@ -26,7 +26,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rawId: "artMaster",
|
rawId: "ArtMaster",
|
||||||
name: "Art Master",
|
name: "Art Master",
|
||||||
stats: {
|
stats: {
|
||||||
health: 28,
|
health: 28,
|
||||||
|
@ -51,7 +51,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rawId: "guitarHero",
|
rawId: "GuitarHero",
|
||||||
name: "Guitar Hero",
|
name: "Guitar Hero",
|
||||||
stats: {
|
stats: {
|
||||||
health: 30,
|
health: 30,
|
||||||
|
@ -75,7 +75,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rawId: "delta",
|
rawId: "Delta",
|
||||||
name: "Delta",
|
name: "Delta",
|
||||||
stats: {
|
stats: {
|
||||||
health: 40,
|
health: 40,
|
||||||
|
@ -102,7 +102,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rawId: "smallKey",
|
rawId: "SmallKeyMaster",
|
||||||
name: "Small KeyMaster",
|
name: "Small KeyMaster",
|
||||||
stats: {
|
stats: {
|
||||||
health: 35,
|
health: 35,
|
||||||
|
@ -131,7 +131,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rawId: "common",
|
rawId: "CommonOverseer",
|
||||||
name: "Common Overseer",
|
name: "Common Overseer",
|
||||||
stats: {
|
stats: {
|
||||||
health: 45,
|
health: 45,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
"rawId": "battler",
|
"rawId": "Battler",
|
||||||
"name": "Battler",
|
"name": "Battler",
|
||||||
"stats": {
|
"stats": {
|
||||||
health: (user) => user.health * 2,
|
health: (user) => user.health * 2,
|
||||||
|
@ -27,7 +27,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"rawId": "elliton",
|
"rawId": "BattlerElite",
|
||||||
"name": "Battler Elite",
|
"name": "Battler Elite",
|
||||||
"stats": {
|
"stats": {
|
||||||
health: (user) => user.health * 3,
|
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>.`
|
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",
|
name: "DEMUL",
|
||||||
stats: {
|
stats: {
|
||||||
health: (user) => user.maxdmg * 10,
|
health: (user) => user.maxdmg * 10,
|
||||||
|
@ -74,7 +74,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rawId: "incomingSword",
|
rawId: "IncomingSword",
|
||||||
name: "Incoming Sword",
|
name: "Incoming Sword",
|
||||||
stats: {
|
stats: {
|
||||||
health: (user) => user.maxdmg * 5,
|
health: (user) => user.maxdmg * 5,
|
||||||
|
@ -215,7 +215,7 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rawId: "masterOG",
|
rawId: "MasterOG",
|
||||||
name: "Master OG",
|
name: "Master OG",
|
||||||
stats: {
|
stats: {
|
||||||
health: (user) => user.maxdmg * 30,
|
health: (user) => user.maxdmg * 30,
|
||||||
|
|
Loading…
Reference in a new issue