mirror of
https://github.com/nx-bat/pet-the-pond.git
synced 2026-09-22 10:29:11 -04:00
it works again.
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
# Default database credentials are used. This should be adjusted based on your own postgres configuration.
|
# 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=
|
DEV_GUILD=
|
||||||
DISCORD_TOKEN=
|
DISCORD_TOKEN=
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
POSTGRES_DB: postgres
|
POSTGRES_DB: pond
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import leaderboard from './leaderboard';
|
import leaderboard from './leaderboard';
|
||||||
import rank from './rank';
|
import rank from './rank';
|
||||||
import settings from './settings';
|
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
|
|
||||||
export default [leaderboard, rank, settings];
|
export default [leaderboard, rank];
|
||||||
|
|||||||
+6
-6
@@ -6,7 +6,7 @@ const client = postgres(process.env.DATABASE_URL);
|
|||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
await client`
|
await client`
|
||||||
CREATE TABLE IF NOT EXISTS user_points (
|
CREATE TABLE IF NOT EXISTS points (
|
||||||
user_id TEXT NOT NULL,
|
user_id TEXT NOT NULL,
|
||||||
guild_id TEXT NOT NULL,
|
guild_id TEXT NOT NULL,
|
||||||
points INTEGER NOT NULL DEFAULT 0 CHECK (points >= 0),
|
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<number> {
|
async function getPoints(id: string, guild_id: string): Promise<number> {
|
||||||
const [row] = await client`
|
const [row] = await client`
|
||||||
SELECT points
|
SELECT points
|
||||||
FROM user_points
|
FROM points
|
||||||
WHERE user_id = ${id}
|
WHERE user_id = ${id}
|
||||||
AND guild_id = ${guild_id}
|
AND guild_id = ${guild_id}
|
||||||
`;
|
`;
|
||||||
@@ -29,7 +29,7 @@ async function getPoints(id: string, guild_id: string): Promise<number> {
|
|||||||
|
|
||||||
async function addPoints(id: string, guild_id: string, count: number) {
|
async function addPoints(id: string, guild_id: string, count: number) {
|
||||||
await client`
|
await client`
|
||||||
INSERT INTO user_points (user_id, guild_id, points)
|
INSERT INTO points (user_id, guild_id, points)
|
||||||
VALUES (${id}, ${guild_id}, ${count})
|
VALUES (${id}, ${guild_id}, ${count})
|
||||||
ON CONFLICT (user_id, guild_id)
|
ON CONFLICT (user_id, guild_id)
|
||||||
DO UPDATE SET points = user_points.points + ${count}
|
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) {
|
async function takePoints(id: string, guild_id: string, count: number) {
|
||||||
await client`
|
await client`
|
||||||
INSERT INTO user_points (user_id, guild_id, points)
|
INSERT INTO points (user_id, guild_id, points)
|
||||||
VALUES (${id}, ${guild_id}, 0)
|
VALUES (${id}, ${guild_id}, 0)
|
||||||
ON CONFLICT (user_id, guild_id)
|
ON CONFLICT (user_id, guild_id)
|
||||||
DO UPDATE SET points = GREATEST(user_points.points - ${count}, 0)
|
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 }[]> {
|
async function getLeaderboard(guild_id: string, limit: number = 10): Promise<{ user_id: string; points: number }[]> {
|
||||||
return await client`
|
return await client`
|
||||||
SELECT user_id, points
|
SELECT user_id, points
|
||||||
FROM user_points
|
FROM points
|
||||||
WHERE guild_id = ${guild_id}
|
WHERE guild_id = ${guild_id}
|
||||||
ORDER BY points DESC, user_id ASC
|
ORDER BY points DESC, user_id ASC
|
||||||
LIMIT ${limit}
|
LIMIT ${limit}
|
||||||
@@ -64,7 +64,7 @@ async function getLeaderboardPosition(id: string, guild_id: string): Promise<num
|
|||||||
SELECT
|
SELECT
|
||||||
user_id,
|
user_id,
|
||||||
RANK() OVER (ORDER BY points DESC) AS position
|
RANK() OVER (ORDER BY points DESC) AS position
|
||||||
FROM user_points
|
FROM points
|
||||||
WHERE guild_id = ${guild_id}
|
WHERE guild_id = ${guild_id}
|
||||||
) leaderboard
|
) leaderboard
|
||||||
WHERE user_id = ${id}
|
WHERE user_id = ${id}
|
||||||
|
|||||||
Reference in New Issue
Block a user