Fixed all typescript errors (hopefully, github)
diff --git a/src/config/format.ts b/src/config/format.ts
index b00b3e4..a80094e 100644
--- a/src/config/format.ts
+++ b/src/config/format.ts
@@ -1,3 +1,4 @@
+
import fs from "fs";
import * as readLine from "node:readline/promises";
@@ -50,25 +51,27 @@
// }
}
- let json;
+ let json: typeof defaultDict;
let out = true;
try {
- json = JSON.parse(fs.readFileSync("./src/config/main.json", "utf8"));
+ json = await import("./main.js") as unknown as typeof defaultDict;
} catch (e) {
- console.log("\x1b[31m⚠ No main.json found, creating one.");
- console.log(" \x1b[2mYou can edit src/config/main.json directly using template written to the file.\x1b[0m\n");
+ console.log("\x1b[31m⚠ No main.ts found, creating one.");
+ console.log(" \x1b[2mYou can edit src/config/main.ts directly using template written to the file.\x1b[0m\n");
out = false;
- json = {};
+ json = {} as typeof defaultDict;
}
- if (json) {
- if (json.token === defaultDict["token"] || json.developmentToken === defaultDict["developmentToken"]) {
- console.log("\x1b[31m⚠ No main.json found, creating one.");
- console.log(" \x1b[2mYou can edit src/config/main.json directly using template written to the file.\x1b[0m\n");
+
+ if (Object.keys(json).length) {
+ if (json["token"] === defaultDict["token"] || json["developmentToken"] === defaultDict["developmentToken"]) {
+ console.log("\x1b[31m⚠ No main.ts found, creating one.");
+ console.log(" \x1b[2mYou can edit src/config/main.ts directly using template written to the file.\x1b[0m\n");
json = {};
}
}
+
for (const key in defaultDict) {
- if (!json[key]) {
+ if (Object.keys(json).includes(key)) {
if (walkthrough) {
switch (key) {
case "enableDevelopment": {
@@ -99,13 +102,13 @@
}
}
} else {
- json[key] = defaultDict[key];
+ json[key] = defaultDict[key]!;
}
}
}
- if (walkthrough && !json.mongoUrl) json.mongoUrl = "mongodb://127.0.0.1:27017";
- if (!json.mongoUrl.endsWith("/")) json.mongoUrl += "/";
- if (!json.baseUrl.endsWith("/")) json.baseUrl += "/";
+ if (walkthrough && !(json["mongoUrl"] ?? false)) json["mongoUrl"] = "mongodb://127.0.0.1:27017";
+ if (!((json["mongoUrl"] as string | undefined) ?? "").endsWith("/")) json["mongoUrl"] += "/";
+ if (!((json["baseUrl"] as string | undefined) ?? "").endsWith("/")) json["baseUrl"] += "/";
let hosts;
try {
hosts = fs.readFileSync("/etc/hosts", "utf8").toString().split("\n");
@@ -114,16 +117,16 @@
"\x1b[31m⚠ No /etc/hosts found. Please ensure the file exists and is readable. (Windows is not supported, Mac and Linux users should not experience this error)"
);
}
- let localhost = hosts.find((line) => line.split(" ")[1] === "localhost");
+ let localhost: string | undefined = hosts.find((line) => line.split(" ")[1] === "localhost");
if (localhost) {
localhost = localhost.split(" ")[0];
} else {
localhost = "127.0.0.1";
}
- json.mongoUrl = json.mongoUrl.replace("localhost", localhost);
- json.baseUrl = json.baseUrl.replace("localhost", localhost);
+ json["mongoUrl"] = (json["mongoUrl"]! as string).replace("localhost", localhost!);
+ json["baseUrl"] = (json["baseUrl"]! as string).replace("localhost", localhost!);
- fs.writeFileSync("./src/config/main.json", JSON.stringify(json, null, 4));
+ fs.writeFileSync("./src/config/main.ts", "export default " + JSON.stringify(json, null, 4) + ";");
if (walkthrough) {
console.log("\x1b[32m✓ All properties added.\x1b[0m");
diff --git a/src/config/main.d.ts b/src/config/main.d.ts
new file mode 100644
index 0000000..be6a253
--- /dev/null
+++ b/src/config/main.d.ts
@@ -0,0 +1,21 @@
+declare const config: {
+ developmentToken: string,
+ developmentGuildID: string,
+ enableDevelopment: boolean,
+ token: string,
+ managementGuildID: string,
+ owners: string[],
+ commandsFolder: string,
+ eventsFolder: string,
+ messageContextFolder: string,
+ userContextFolder: string,
+ verifySecret: string,
+ mongoUrl: string,
+ baseUrl: string,
+ pastebinApiKey: string,
+ pastebinUsername: string,
+ pastebinPassword: string,
+ rapidApiKey: string
+};
+
+export default config;
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 306ca50..3c132bc 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,6 @@
import runServer from "./api/index.js";
import client from "./utils/client.js";
-import config from "./config/main.json" assert { type: "json" };
+import config from "./config/main.js";
import register from "./utils/commandRegistration/register.js";
import { record as recordPerformance } from "./utils/performanceTesting/record.js";
diff --git a/src/utils/client.ts b/src/utils/client.ts
index 32c9f7a..b05ef5f 100644
--- a/src/utils/client.ts
+++ b/src/utils/client.ts
@@ -5,7 +5,7 @@
import { Guilds, History, ModNotes, Premium, PerformanceTest, ScanCache } from "../utils/database.js";
import EventScheduler from "../utils/eventScheduler.js";
import type { RoleMenuSchema } from "../actions/roleMenu.js";
-import config from "../config/main.json" assert { type: "json" };
+import config from "../config/main.js";
class NucleusClient extends Client {
diff --git a/src/utils/commandRegistration/register.ts b/src/utils/commandRegistration/register.ts
index 693ad00..1a19e2c 100644
--- a/src/utils/commandRegistration/register.ts
+++ b/src/utils/commandRegistration/register.ts
@@ -1,6 +1,6 @@
import type { CommandInteraction } from 'discord.js';
import Discord, { Interaction, SlashCommandBuilder, ApplicationCommandType } from 'discord.js';
-import config from "../../config/main.json" assert { type: "json" };
+import config from "../../config/main.js";
import client from "../client.js";
import fs from "fs";
import EmojiEmbed from '../generateEmojiEmbed.js';
diff --git a/src/utils/commandRegistration/slashCommandBuilder.ts b/src/utils/commandRegistration/slashCommandBuilder.ts
index 9a72605..66291b3 100644
--- a/src/utils/commandRegistration/slashCommandBuilder.ts
+++ b/src/utils/commandRegistration/slashCommandBuilder.ts
@@ -1,6 +1,6 @@
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from "discord.js";
import type { SlashCommandBuilder } from "discord.js";
-import config from "../../config/main.json" assert { type: "json" };
+import config from "../../config/main.js";
import getSubcommandsInFolder from "./getFilesInFolder.js";
import client from "../client.js";
import Discord from "discord.js";
diff --git a/src/utils/database.ts b/src/utils/database.ts
index d25cfdb..239da13 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -1,6 +1,6 @@
import type Discord from "discord.js";
import { Collection, MongoClient } from "mongodb";
-import config from "../config/main.json" assert { type: "json" };
+import config from "../config/main.js";
import client from "../utils/client.js";
const mongoClient = new MongoClient(config.mongoUrl);
diff --git a/src/utils/eventScheduler.ts b/src/utils/eventScheduler.ts
index 60d525c..bdd0d21 100644
--- a/src/utils/eventScheduler.ts
+++ b/src/utils/eventScheduler.ts
@@ -2,7 +2,7 @@
import client from "./client.js";
import * as fs from "fs";
import * as path from "path";
-import config from "../config/main.json" assert { type: "json" };
+import config from "../config/main.js";
class EventScheduler {
private agenda: Agenda;
diff --git a/src/utils/performanceTesting/record.ts b/src/utils/performanceTesting/record.ts
index 17cfb1e..71883c5 100644
--- a/src/utils/performanceTesting/record.ts
+++ b/src/utils/performanceTesting/record.ts
@@ -2,7 +2,7 @@
import * as CP from 'child_process';
import * as process from 'process';
import systeminformation from "systeminformation";
-import config from "../../config/main.json" assert { type: "json" };
+import config from "../../config/main.js";
import singleNotify from "../singleNotify.js";