diff --git a/package-lock.json b/package-lock.json index a1a8e06..a3b47f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,23 +1,24 @@ { "name": "sknsybot", - "version": "0.4.0", + "version": "0.4.0.b2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sknsybot", - "version": "0.4.0", + "version": "0.4.0.b2", "license": "Apache-2.0", "dependencies": { "chalk": "^5.4.1", "discord.js": "^14.14.1", - "dotenv": "^16.4.7", + "dotenv": "^17.3.1", "drizzle-orm": "^0.45.1", "node-cron": "^3.0.3", "pg": "^8.18.0", "wikijs": "^6.4.1" }, "devDependencies": { + "@types/chalk": "^0.4.31", "@types/node": "^22.10.7", "@types/node-cron": "^3.0.11", "@types/pg": "^8.16.0", @@ -1144,6 +1145,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/chalk": { + "version": "0.4.31", + "resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-0.4.31.tgz", + "integrity": "sha512-nF0fisEPYMIyfrFgabFimsz9Lnuu9MwkNrrlATm2E4E46afKDyeelT+8bXfw1VSc7sLBxMxRgT7PxTC2JcqN4Q==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/node": { "version": "22.10.7", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.7.tgz", @@ -1333,9 +1341,9 @@ } }, "node_modules/dotenv": { - "version": "16.4.7", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", - "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "version": "17.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.3.1.tgz", + "integrity": "sha512-IO8C/dzEb6O3F9/twg6ZLXz164a2fhTnEWb95H23Dm4OuN+92NmEAlTrupP9VW6Jm3sO26tQlqyvyi4CsnY9GA==", "license": "BSD-2-Clause", "engines": { "node": ">=12" diff --git a/package.json b/package.json index 6dfef07..d4b3749 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sknsybot", - "version": "0.4.0.b1", + "version": "0.4.0.b2", "private": true, "description": "", "license": "Apache-2.0", @@ -14,13 +14,14 @@ "dependencies": { "chalk": "^5.4.1", "discord.js": "^14.14.1", - "dotenv": "^16.4.7", + "dotenv": "^17.3.1", "drizzle-orm": "^0.45.1", "node-cron": "^3.0.3", "pg": "^8.18.0", "wikijs": "^6.4.1" }, "devDependencies": { + "@types/chalk": "^0.4.31", "@types/node": "^22.10.7", "@types/node-cron": "^3.0.11", "@types/pg": "^8.16.0", diff --git a/src/db/database.ts b/src/db/database.ts index f2cf501..9d91033 100644 --- a/src/db/database.ts +++ b/src/db/database.ts @@ -3,13 +3,28 @@ import { drizzle } from "drizzle-orm/node-postgres"; import * as schema from "./schema"; import { Pool } from "pg"; +function urlToObj(url: string) { + if (!url) throw new Error('DATABASE_URL is not set'); + + const { username, password, hostname, port, pathname } = URL.parse(url); + + return { + user: username, + password, + host: hostname, + port: +(port || 5432), + database: pathname.split('/')[1] + } +} + + const client = new Pool({ - connectionString: process.env.DATABASE_URL! + ...urlToObj(process.env.DATABASE_URL!) }); export const db = drizzle({ client, - casing: 'snake_case', + // casing: 'snake_case', [DOES NOT WORK ON DRIZZLEKIT] schema }); diff --git a/src/initConfig.ts b/src/initConfig.ts index 7a513ba..64d3565 100644 --- a/src/initConfig.ts +++ b/src/initConfig.ts @@ -1,6 +1,7 @@ -import { config as configDotenv } from 'dotenv'; +import { configDotenv } from 'dotenv'; +import process from 'node:process'; export default function init (){ configDotenv(); diff --git a/src/main.ts b/src/main.ts index 18b0d1a..1fb4574 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,17 +1,19 @@ -import init from "./initConfig"; +import { configDotenv } from "dotenv"; -init(); +configDotenv(); // apparently init does not get executed + +const client = (await import("./bot")).default; -import client from "./bot"; // query TEST -import { db } from "./db/database"; -import { count } from "drizzle-orm"; -import { users } from "./db/schema"; -import chalk from "chalk"; (async function () { - const uCount = await db.select({ count: count() }).from(users); + // async imports because yes + const { db } = await import("./db/database"); + const { count } = await import("drizzle-orm"); + const { users } = await import("./db/schema"); + const chalk = (await import("chalk")).default; + const uCount = (await db.select({ count: count() }).from(users))[0].count; console.log(`Watching over ${chalk.bold(uCount)} users`); })().then(() => { }); // END query TEST diff --git a/src/mediawiki.ts b/src/mediawiki.ts index 69cb6c5..c8bddf8 100644 --- a/src/mediawiki.ts +++ b/src/mediawiki.ts @@ -14,8 +14,6 @@ function strToObjArr(s: string | object[]): object[] { export type SectionObject = {title: string, content: string}; -type WithPageId = {pageId: any}; - export class MediaWikiClient { apiUrl: string siteName: string | null @@ -29,7 +27,7 @@ export class MediaWikiClient { const wikiClient = wiki({ apiUrl: this.apiUrl, origin: null - }); + }) as any; const page = await wikiClient.page(title); const pageId = page.raw.pageid; const pageUrl = page.url(); diff --git a/tsconfig.json b/tsconfig.json index 5e79b6e..9efc68e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,7 @@ { "compilerOptions": { + "target": "es2017", + "module": "preserve", "rootDir": "src/", "outDir": "build/", "esModuleInterop": true,