Skip to content

Commit

Permalink
updated bot.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Oct 23, 2024
1 parent f194a66 commit 210e394
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 44 deletions.
158 changes: 123 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -124,6 +123,7 @@
"#buttons/*": "./dist/buttons/*"
},
"optionalDependencies": {
"@types/pg": "^8.11.10",
"through2": "^4.0.2"
}
}
14 changes: 14 additions & 0 deletions src/app/database.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions src/namespaces/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})),
)

Expand Down
16 changes: 15 additions & 1 deletion templates/pg
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -24,4 +27,15 @@ const client = new orm.ORM({

export * from "@ghom/orm"

export default client
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)
}

0 comments on commit 210e394

Please sign in to comment.