Fixed all typescript errors (hopefully, github)

pull/11/head
pineafan 3 years ago
parent 96228bdb24
commit a2e39c7ffb
No known key found for this signature in database
GPG Key ID: 0AEF25BAA0FB1C74

@ -4,7 +4,7 @@
"es2020": true, "es2020": true,
"node": true "node": true
}, },
"ignorePatterns": ["dist/", "src/Unfinished/"], "ignorePatterns": ["dist/", "src/Unfinished/", "src/config/main.d.ts", "*.js"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/strict", "prettier"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/strict", "prettier"],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {

6
.gitignore vendored

@ -2,10 +2,12 @@ dist/
.history/ .history/
node_modules/ node_modules/
src/config/* src/config/*
!src/config/*.d.ts
!src/config/format.ts !src/config/format.ts
!src/config/default.json !src/config/default.json
!src/config/emojis.json !src/config/emojis.json
src/config/main.json src/config/main.ts
.vscode/ .vscode/
.vim/ .vim/
yarn-error.log yarn-error.log
@ -16,4 +18,4 @@ src/utils/temp/*.jpeg
src/utils/temp/*.jpg src/utils/temp/*.jpg
ClicksMigratingProblems/oldData/ ClicksMigratingProblems/oldData/
ClicksMigratingProblems/oldData copy/ ClicksMigratingProblems/oldData copy/

@ -5,7 +5,7 @@ src/config/*
!src/config/format.ts !src/config/format.ts
!src/config/default.json !src/config/default.json
!src/config/emojis.json !src/config/emojis.json
src/config/main.json !src/config/main.ts
.vscode/ .vscode/
yarn-error.log yarn-error.log
yarn.lock yarn.lock

@ -23,7 +23,7 @@ However, you **must**:
## How to: ## How to:
We hide the config file with our important data like the bot token. Below you can find a copy of `src/config/main.json`. We hide the config file with our important data like the bot token. Below you can find a copy of `src/config/main.ts`.
Alternatively, you can run `Installer.js` to generate it for you. Alternatively, you can run `Installer.js` to generate it for you.
```json ```json

@ -1,3 +1,4 @@
import fs from "fs"; import fs from "fs";
import * as readLine from "node:readline/promises"; import * as readLine from "node:readline/promises";
@ -50,25 +51,27 @@ export default async function (walkthrough = false) {
// } // }
} }
let json; let json: typeof defaultDict;
let out = true; let out = true;
try { try {
json = JSON.parse(fs.readFileSync("./src/config/main.json", "utf8")); json = await import("./main.js") as unknown as typeof defaultDict;
} catch (e) { } catch (e) {
console.log("\x1b[31m⚠ No main.json found, creating one."); console.log("\x1b[31m⚠ No main.ts 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[2mYou can edit src/config/main.ts directly using template written to the file.\x1b[0m\n");
out = false; out = false;
json = {}; json = {} as typeof defaultDict;
} }
if (json) {
if (json.token === defaultDict["token"] || json.developmentToken === defaultDict["developmentToken"]) { if (Object.keys(json).length) {
console.log("\x1b[31m⚠ No main.json found, creating one."); if (json["token"] === defaultDict["token"] || json["developmentToken"] === defaultDict["developmentToken"]) {
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");
json = {}; json = {};
} }
} }
for (const key in defaultDict) { for (const key in defaultDict) {
if (!json[key]) { if (Object.keys(json).includes(key)) {
if (walkthrough) { if (walkthrough) {
switch (key) { switch (key) {
case "enableDevelopment": { case "enableDevelopment": {
@ -99,13 +102,13 @@ export default async function (walkthrough = false) {
} }
} }
} else { } else {
json[key] = defaultDict[key]; json[key] = defaultDict[key]!;
} }
} }
} }
if (walkthrough && !json.mongoUrl) json.mongoUrl = "mongodb://127.0.0.1:27017"; if (walkthrough && !(json["mongoUrl"] ?? false)) json["mongoUrl"] = "mongodb://127.0.0.1:27017";
if (!json.mongoUrl.endsWith("/")) json.mongoUrl += "/"; if (!((json["mongoUrl"] as string | undefined) ?? "").endsWith("/")) json["mongoUrl"] += "/";
if (!json.baseUrl.endsWith("/")) json.baseUrl += "/"; if (!((json["baseUrl"] as string | undefined) ?? "").endsWith("/")) json["baseUrl"] += "/";
let hosts; let hosts;
try { try {
hosts = fs.readFileSync("/etc/hosts", "utf8").toString().split("\n"); hosts = fs.readFileSync("/etc/hosts", "utf8").toString().split("\n");
@ -114,16 +117,16 @@ export default async function (walkthrough = false) {
"\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)" "\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) { if (localhost) {
localhost = localhost.split(" ")[0]; localhost = localhost.split(" ")[0];
} else { } else {
localhost = "127.0.0.1"; localhost = "127.0.0.1";
} }
json.mongoUrl = json.mongoUrl.replace("localhost", localhost); json["mongoUrl"] = (json["mongoUrl"]! as string).replace("localhost", localhost!);
json.baseUrl = json.baseUrl.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) { if (walkthrough) {
console.log("\x1b[32m✓ All properties added.\x1b[0m"); console.log("\x1b[32m✓ All properties added.\x1b[0m");

@ -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;

@ -1,6 +1,6 @@
import runServer from "./api/index.js"; import runServer from "./api/index.js";
import client from "./utils/client.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 register from "./utils/commandRegistration/register.js";
import { record as recordPerformance } from "./utils/performanceTesting/record.js"; import { record as recordPerformance } from "./utils/performanceTesting/record.js";

@ -5,7 +5,7 @@ import type { VerifySchema } from "../reflex/verify.js";
import { Guilds, History, ModNotes, Premium, PerformanceTest, ScanCache } from "../utils/database.js"; import { Guilds, History, ModNotes, Premium, PerformanceTest, ScanCache } from "../utils/database.js";
import EventScheduler from "../utils/eventScheduler.js"; import EventScheduler from "../utils/eventScheduler.js";
import type { RoleMenuSchema } from "../actions/roleMenu.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 { class NucleusClient extends Client {

@ -1,6 +1,6 @@
import type { CommandInteraction } from 'discord.js'; import type { CommandInteraction } from 'discord.js';
import Discord, { Interaction, SlashCommandBuilder, ApplicationCommandType } 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 client from "../client.js";
import fs from "fs"; import fs from "fs";
import EmojiEmbed from '../generateEmojiEmbed.js'; import EmojiEmbed from '../generateEmojiEmbed.js';

@ -1,6 +1,6 @@
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from "discord.js"; import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from "discord.js";
import type { SlashCommandBuilder } 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 getSubcommandsInFolder from "./getFilesInFolder.js";
import client from "../client.js"; import client from "../client.js";
import Discord from "discord.js"; import Discord from "discord.js";

@ -1,6 +1,6 @@
import type Discord from "discord.js"; import type Discord from "discord.js";
import { Collection, MongoClient } from "mongodb"; 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"; import client from "../utils/client.js";
const mongoClient = new MongoClient(config.mongoUrl); const mongoClient = new MongoClient(config.mongoUrl);

@ -2,7 +2,7 @@ import { Agenda } from "@hokify/agenda";
import client from "./client.js"; import client from "./client.js";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import config from "../config/main.json" assert { type: "json" }; import config from "../config/main.js";
class EventScheduler { class EventScheduler {
private agenda: Agenda; private agenda: Agenda;

@ -2,7 +2,7 @@ import client from "../client.js";
import * as CP from 'child_process'; import * as CP from 'child_process';
import * as process from 'process'; import * as process from 'process';
import systeminformation from "systeminformation"; import systeminformation from "systeminformation";
import config from "../../config/main.json" assert { type: "json" }; import config from "../../config/main.js";
import singleNotify from "../singleNotify.js"; import singleNotify from "../singleNotify.js";

@ -14,6 +14,6 @@
"noImplicitReturns": false, "noImplicitReturns": false,
"ignoreDeprecations": "5.0" "ignoreDeprecations": "5.0"
}, },
"include": ["src/**/*", "src/index.d.ts"], "include": ["src/**/*", "src/*", "src/config/main.d.ts", "src/config/main.ts"],
"exclude": ["src/Unfinished/**/*"] "exclude": ["src/Unfinished/**/*"]
} }

Loading…
Cancel
Save