From 210e394e03360f5e12da777bdf8ac5b27347866f Mon Sep 17 00:00:00 2001 From: GhomKrosmonaute Date: Wed, 23 Oct 2024 13:49:51 +0200 Subject: [PATCH] updated bot.ts --- package-lock.json | 158 +++++++++++++++++++++++++++++++--------- package.json | 12 +-- src/app/database.ts | 14 ++++ src/namespaces/point.ts | 4 +- templates/pg | 16 +++- 5 files changed, 160 insertions(+), 44 deletions(-) diff --git a/package-lock.json b/package-lock.json index de2ea2b2..681f9abf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "ghom-prettify": "^3.0.0", "knex": "^3.0.1", "openai": "^4.28.0", - "pg": "latest", + "pg": "^8.13.0", "prettier": "^3.2.5", "regex-parser": "^2.2.11", "simple-git": "^3.27.0", @@ -63,7 +63,6 @@ "@typescript-eslint/eslint-plugin": "^8.9.0", "@typescript-eslint/parser": "^8.9.0", "del": "^6.1.1", - "dirname-filename-esm": "^1.1.1", "discord-api-types": "^0.37.102", "esbuild": "^0.24.0", "eslint": "^9.12.0", @@ -88,6 +87,7 @@ "npm": ">=10.x.x" }, "optionalDependencies": { + "@types/pg": "^8.11.10", "through2": "^4.0.2" } }, @@ -1511,6 +1511,80 @@ "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", "license": "MIT" }, + "node_modules/@types/pg": { + "version": "8.11.10", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.11.10.tgz", + "integrity": "sha512-LczQUW4dbOQzsH2RQ5qoeJ6qJPdrcM/DcMLoqWQkMLMsq83J5lAX3LXjdkWdpscFy67JSOWDnh7Ny/sPFykmkg==", + "license": "MIT", + "optional": true, + "dependencies": { + "@types/node": "*", + "pg-protocol": "*", + "pg-types": "^4.0.1" + } + }, + "node_modules/@types/pg/node_modules/pg-types": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-4.0.2.tgz", + "integrity": "sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==", + "license": "MIT", + "optional": true, + "dependencies": { + "pg-int8": "1.0.1", + "pg-numeric": "1.0.2", + "postgres-array": "~3.0.1", + "postgres-bytea": "~3.0.0", + "postgres-date": "~2.1.0", + "postgres-interval": "^3.0.0", + "postgres-range": "^1.1.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@types/pg/node_modules/postgres-array": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.2.tgz", + "integrity": "sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/@types/pg/node_modules/postgres-bytea": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-3.0.0.tgz", + "integrity": "sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==", + "license": "MIT", + "optional": true, + "dependencies": { + "obuf": "~1.1.2" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/@types/pg/node_modules/postgres-date": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-2.1.0.tgz", + "integrity": "sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/@types/pg/node_modules/postgres-interval": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-3.0.0.tgz", + "integrity": "sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=12" + } + }, "node_modules/@types/prettier": { "version": "2.7.3", "dev": true, @@ -2381,14 +2455,6 @@ "ieee754": "^1.2.1" } }, - "node_modules/buffer-writer": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", - "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==", - "engines": { - "node": ">=4" - } - }, "node_modules/cacache": { "version": "15.3.0", "license": "ISC", @@ -2975,8 +3041,9 @@ } }, "node_modules/dirname-filename-esm": { - "version": "1.1.1", - "dev": true, + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/dirname-filename-esm/-/dirname-filename-esm-1.1.2.tgz", + "integrity": "sha512-mMhH2imzJN95KnX/iDAhC0QDG0VU833c88U3SXCaQzATu7YlO9YTFD/CF9Nn2xhSwFlV9iWEKb/YyGJ4TwCcPg==", "license": "MIT" }, "node_modules/discord-api-types": { @@ -7397,6 +7464,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/obuf": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz", + "integrity": "sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==", + "license": "MIT", + "optional": true + }, "node_modules/once": { "version": "1.4.0", "devOptional": true, @@ -7521,11 +7595,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/packet-reader": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz", - "integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" - }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -7621,15 +7690,14 @@ } }, "node_modules/pg": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/pg/-/pg-8.11.3.tgz", - "integrity": "sha512-+9iuvG8QfaaUrrph+kpF24cXkH1YOOUeArRNYIxq1viYHZagBxrTno7cecY1Fa44tJeZvaoG+Djpkc3JwehN5g==", - "dependencies": { - "buffer-writer": "2.0.0", - "packet-reader": "1.0.0", - "pg-connection-string": "^2.6.2", - "pg-pool": "^3.6.1", - "pg-protocol": "^1.6.0", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.0.tgz", + "integrity": "sha512-34wkUTh3SxTClfoHB3pQ7bIMvw9dpFU1audQQeZG837fmHfHpr14n/AELVDoOYVDW2h5RDWU78tFjkD+erSBsw==", + "license": "MIT", + "dependencies": { + "pg-connection-string": "^2.7.0", + "pg-pool": "^3.7.0", + "pg-protocol": "^1.7.0", "pg-types": "^2.1.0", "pgpass": "1.x" }, @@ -7666,18 +7734,30 @@ "node": ">=4.0.0" } }, + "node_modules/pg-numeric": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pg-numeric/-/pg-numeric-1.0.2.tgz", + "integrity": "sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==", + "license": "ISC", + "optional": true, + "engines": { + "node": ">=4" + } + }, "node_modules/pg-pool": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.1.tgz", - "integrity": "sha512-jizsIzhkIitxCGfPRzJn1ZdcosIt3pz9Sh3V01fm1vZnbnCMgmGl5wvGGdNN2EL9Rmb0EcFoCkixH4Pu+sP9Og==", + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.7.0.tgz", + "integrity": "sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==", + "license": "MIT", "peerDependencies": { "pg": ">=8.0" } }, "node_modules/pg-protocol": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.0.tgz", - "integrity": "sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==" + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.7.0.tgz", + "integrity": "sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==", + "license": "MIT" }, "node_modules/pg-types": { "version": "2.2.0", @@ -7695,9 +7775,10 @@ } }, "node_modules/pg/node_modules/pg-connection-string": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.2.tgz", - "integrity": "sha512-ch6OwaeaPYcova4kKZ15sbJ2hKb/VP48ZD2gE7i1J+L4MspCtBMAx8nMgz7bksc7IojCIIWuEhHibSMFH8m8oA==" + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz", + "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==", + "license": "MIT" }, "node_modules/pgpass": { "version": "1.0.5", @@ -7777,6 +7858,13 @@ "node": ">=0.10.0" } }, + "node_modules/postgres-range": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/postgres-range/-/postgres-range-1.1.4.tgz", + "integrity": "sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==", + "license": "MIT", + "optional": true + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/package.json b/package.json index 1bd66d09..4843eab3 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "ghom-prettify": "^3.0.0", "knex": "^3.0.1", "openai": "^4.28.0", - "pg": "latest", + "pg": "^8.13.0", "prettier": "^3.2.5", "regex-parser": "^2.2.11", "simple-git": "^3.27.0", @@ -68,6 +68,9 @@ }, "devDependencies": { "@esbuild/linux-x64": "^0.24.0", + "@eslint/compat": "^1.2.0", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.12.0", "@ghom/bot.ts-cli": "^8.2.0", "@types/boxen": "^3.0.1", "@types/cron": "^1.7.3", @@ -84,7 +87,6 @@ "@typescript-eslint/eslint-plugin": "^8.9.0", "@typescript-eslint/parser": "^8.9.0", "del": "^6.1.1", - "dirname-filename-esm": "^1.1.1", "discord-api-types": "^0.37.102", "esbuild": "^0.24.0", "eslint": "^9.12.0", @@ -101,10 +103,7 @@ "make-bot.ts": "^6.0.5", "nodemon": "^2.0.19", "typescript": "^5.4.0-beta", - "vinyl-paths": "^4.0.0", - "@eslint/compat": "^1.2.0", - "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "^9.12.0" + "vinyl-paths": "^4.0.0" }, "engines": { "node": ">=22.x.x", @@ -124,6 +123,7 @@ "#buttons/*": "./dist/buttons/*" }, "optionalDependencies": { + "@types/pg": "^8.11.10", "through2": "^4.0.2" } } \ No newline at end of file diff --git a/src/app/database.ts b/src/app/database.ts index e2982dd0..482061eb 100644 --- a/src/app/database.ts +++ b/src/app/database.ts @@ -1,10 +1,13 @@ // system file, please don't modify it +import pg from "pg" import * as orm from "@ghom/orm" import * as logger from "./logger.ts" import env from "./env.ts" import path from "path" +setTypeParsers() + const client = new orm.ORM({ location: path.join(process.cwd(), "dist", "tables"), database: { @@ -25,3 +28,14 @@ const client = new orm.ORM({ export * from "@ghom/orm" export default client + +function setTypeParsers() { + const int = (value: string) => parseInt(value) + const float = (value: string) => parseFloat(value) + + pg.types.setTypeParser(pg.types.builtins.INT2, int) + pg.types.setTypeParser(pg.types.builtins.INT4, int) + pg.types.setTypeParser(pg.types.builtins.INT8, int) + pg.types.setTypeParser(pg.types.builtins.FLOAT4, float) + pg.types.setTypeParser(pg.types.builtins.FLOAT8, float) +} diff --git a/src/namespaces/point.ts b/src/namespaces/point.ts index 8e5227a2..42d62dfe 100644 --- a/src/namespaces/point.ts +++ b/src/namespaces/point.ts @@ -126,8 +126,8 @@ export async function refreshHelpingFooter(topic: app.ThreadChannel) { const ranks = await Promise.all( Array.from(helpers).map(async (helper) => ({ - ...helper, - ...(await getPointRank(helper)), + id: helper.id, + rank: await getPointRank(helper).then((r) => r.rank), })), ) diff --git a/templates/pg b/templates/pg index c6fe5ac8..f4cad95a 100644 --- a/templates/pg +++ b/templates/pg @@ -1,10 +1,13 @@ // system file, please don't modify it +import pg from "pg" import * as orm from "@ghom/orm" import * as logger from "./logger.ts" import env from "./env.ts" import path from "path" +setTypeParsers() + const client = new orm.ORM({ location: path.join(process.cwd(), "dist", "tables"), database: { @@ -24,4 +27,15 @@ const client = new orm.ORM({ export * from "@ghom/orm" -export default client \ No newline at end of file +export default client + +function setTypeParsers() { + const int = (value: string) => parseInt(value) + const float = (value: string) => parseFloat(value) + + pg.types.setTypeParser(pg.types.builtins.INT2, int) + pg.types.setTypeParser(pg.types.builtins.INT4, int) + pg.types.setTypeParser(pg.types.builtins.INT8, int) + pg.types.setTypeParser(pg.types.builtins.FLOAT4, float) + pg.types.setTypeParser(pg.types.builtins.FLOAT8, float) +}