diff --git a/.env.sample b/.env.sample index 162df5e..d174367 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,4 @@ # Default database credentials are used. This should be adjusted based on your own postgres configuration. -DATABASE_URL=postgresql://postgres:postgres@postgres:5432/postgres +DATABASE_URL=postgresql://postgres:postgres@postgres:5432/pond DEV_GUILD= DISCORD_TOKEN= diff --git a/docker-compose.yml b/docker-compose.yml index dac38e9..28f625c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,7 +12,7 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres + POSTGRES_DB: pond volumes: - postgres_data:/var/lib/postgresql/data ports: diff --git a/src/commands/index.ts b/src/commands/index.ts index 2b992b3..a8557da 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,7 +1,6 @@ import leaderboard from './leaderboard'; import rank from './rank'; -import settings from './settings'; // ---------- -export default [leaderboard, rank, settings]; +export default [leaderboard, rank]; diff --git a/src/database.ts b/src/database.ts index 59eb656..ebb5b63 100644 --- a/src/database.ts +++ b/src/database.ts @@ -6,7 +6,7 @@ const client = postgres(process.env.DATABASE_URL); async function init() { await client` - CREATE TABLE IF NOT EXISTS user_points ( + CREATE TABLE IF NOT EXISTS points ( user_id TEXT NOT NULL, guild_id TEXT NOT NULL, points INTEGER NOT NULL DEFAULT 0 CHECK (points >= 0), @@ -19,7 +19,7 @@ async function init() { async function getPoints(id: string, guild_id: string): Promise { const [row] = await client` SELECT points - FROM user_points + FROM points WHERE user_id = ${id} AND guild_id = ${guild_id} `; @@ -29,7 +29,7 @@ async function getPoints(id: string, guild_id: string): Promise { async function addPoints(id: string, guild_id: string, count: number) { await client` - INSERT INTO user_points (user_id, guild_id, points) + INSERT INTO points (user_id, guild_id, points) VALUES (${id}, ${guild_id}, ${count}) ON CONFLICT (user_id, guild_id) DO UPDATE SET points = user_points.points + ${count} @@ -38,7 +38,7 @@ async function addPoints(id: string, guild_id: string, count: number) { async function takePoints(id: string, guild_id: string, count: number) { await client` - INSERT INTO user_points (user_id, guild_id, points) + INSERT INTO points (user_id, guild_id, points) VALUES (${id}, ${guild_id}, 0) ON CONFLICT (user_id, guild_id) DO UPDATE SET points = GREATEST(user_points.points - ${count}, 0) @@ -50,7 +50,7 @@ async function takePoints(id: string, guild_id: string, count: number) { async function getLeaderboard(guild_id: string, limit: number = 10): Promise<{ user_id: string; points: number }[]> { return await client` SELECT user_id, points - FROM user_points + FROM points WHERE guild_id = ${guild_id} ORDER BY points DESC, user_id ASC LIMIT ${limit} @@ -64,7 +64,7 @@ async function getLeaderboardPosition(id: string, guild_id: string): Promise