feat: add minor db support

This commit is contained in:
DaInfLoop 2024-06-19 21:20:41 +01:00
parent 1ad640d12f
commit 7deaf7c31f

View file

@ -1,5 +1,15 @@
const { App } = require('@slack/bolt'); const { App } = require('@slack/bolt');
const postgres = require('postgres');
require('dotenv').config() require('dotenv').config()
const sql = postgres({
host: 'hackclub.app',
port: 5432,
database: 'haroon_slackmaster',
username: 'haroon',
password: process.env.PGSQL_PASSWORD,
ssl: 'require'
})
const BeginnerOpponents = require('./opponents/beginner.json'); const BeginnerOpponents = require('./opponents/beginner.json');
@ -8,6 +18,16 @@ const app = new App({
signingSecret: process.env.SLACK_SIGNING_SECRET signingSecret: process.env.SLACK_SIGNING_SECRET
}); });
app.use(async (ctx) => {
const a = await sql`SELECT * FROM users WHERE slack_id = ${ctx.body.user_id};`
if (a.length === 0) {
await sql`INSERT INTO users (slack_id) VALUES (${ctx.body.user_id})`
}
await ctx.next()
})
app.command('/chooseopponent', async (ctx) => { app.command('/chooseopponent', async (ctx) => {
await ctx.ack(); await ctx.ack();
@ -148,6 +168,16 @@ app.view("chooseopponent", async (ctx) => {
}) })
}) })
app.view("chooseopponent-BEGINNER", async (ctx) => {
await ctx.ack();
const userId =
ctx.client.chat.postMessage({
channel: ""
})
})
app.command('/viewopponents', async (ctx) => { app.command('/viewopponents', async (ctx) => {
await ctx.ack(); await ctx.ack();