refactor/entry points in typescript
This commit is contained in:
10 files changed
+804
-58
No files matched your search
@@ -1,6 +1,9 @@
|
||||
# Node modules
|
||||
node_modules/*
|
||||
|
||||
# Builds
|
||||
dist/*
|
||||
|
||||
# Testing/dev related
|
||||
*_test.js
|
||||
dev-*.js
|
||||
|
||||
Generated
+728
File diff suppressed because it is too large.
Load diff
+2
-1
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"dev": "ts-node src/index.ts",
|
||||
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
|
||||
"build": "tsc"
|
||||
},
|
||||
"author": "Braeden Sowinski",
|
||||
@@ -35,6 +35,7 @@
|
||||
"eslint": "^9.36.0",
|
||||
"prettier": "^3.6.2",
|
||||
"ts-node": "^10.9.2",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"typescript": "^5.9.2"
|
||||
}
|
||||
}
|
||||
+18
-17
@@ -6,26 +6,26 @@ const Logger = require("./util/Logger");
|
||||
const crypto = require("crypto");
|
||||
|
||||
// custom util imports
|
||||
const { DownloadNitradoFile, CheckServerStatus, FetchServerSettings, PostServerSettings, NitradoCredentialStatus } = require("../util/NitradoAPI");
|
||||
const { HandlePlayerLogs, HandleActivePlayersList } = require("../util/LogsHandler");
|
||||
const { HandleKillfeed, UpdateLastDeathDate } = require("../util/KillfeedHandler");
|
||||
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require("../util/AlarmsHandler");
|
||||
const { decrypt } = require("../util/Cryptic");
|
||||
const { DownloadNitradoFile, CheckServerStatus, FetchServerSettings, PostServerSettings, NitradoCredentialStatus } = require("./util/NitradoAPI");
|
||||
const { HandlePlayerLogs, HandleActivePlayersList } = require("./util/LogsHandler");
|
||||
const { HandleKillfeed, UpdateLastDeathDate } = require("./util/KillfeedHandler");
|
||||
const { HandleExpiredUAVs, HandleEvents, PlaceFireplaceInAlarm } = require("./util/AlarmsHandler");
|
||||
const { decrypt } = require("./util/Cryptic");
|
||||
const { GetWebhook, WebhookSend } = require("./util/WebhookHandler");
|
||||
|
||||
// Data structures imports
|
||||
const { getDefaultPlayer, UpdatePlayer } = require("../database/player");
|
||||
const { Missions } = require("../database/destinations");
|
||||
const { GetGuild } = require("../database/guild");
|
||||
const { getDefaultPlayer, UpdatePlayer } = require("./database/player");
|
||||
const { Missions } = require("./database/destinations");
|
||||
const { GetGuild } = require("./database/guild");
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const readline = require("readline");
|
||||
|
||||
const minute = 60000; // 1 minute in milliseconds
|
||||
const arInterval = 600000; // Set auto-restart interval 10 minutes (600,000ms)
|
||||
const MINUTE = 60000; // 1 minute in milliseconds
|
||||
const AUTO_RESTART_INTERVAL = 600000; // Set auto-restart interval 10 minutes (600,000ms)
|
||||
|
||||
class DayzRBot extends Client {
|
||||
class DayZR extends Client {
|
||||
|
||||
constructor(options, config) {
|
||||
super(options);
|
||||
@@ -33,8 +33,8 @@ class DayzRBot extends Client {
|
||||
this.config = config;
|
||||
this.commands = new Collection();
|
||||
this.interactionHandlers = new Collection();
|
||||
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
|
||||
this.timer = this.config.Dev == "PROD." ? minute * 5 : minute / 4;
|
||||
this.logger = new Logger(path.join(__dirname, "..", "logs", "Logs.log"));
|
||||
this.timer = this.config.Dev == "PROD." ? MINUTE * 5 : MINUTE / 4;
|
||||
|
||||
if (
|
||||
this.config.Token === "" ||
|
||||
@@ -69,7 +69,7 @@ class DayzRBot extends Client {
|
||||
this.dbo;
|
||||
|
||||
this.databaseConnected = false;
|
||||
this.arInterval = arInterval;
|
||||
this.arInterval = AUTO_RESTART_INTERVAL;
|
||||
this.arIntervalIds = new Map();
|
||||
this.playerSessions = new Map();
|
||||
this.logHistory = new Map();
|
||||
@@ -415,6 +415,7 @@ class DayzRBot extends Client {
|
||||
await this.connectMongo(this.config.mongoURI, this.config.dbo);
|
||||
|
||||
if (!this.databaseConnected) return;
|
||||
|
||||
let guilds = await this.dbo.collection("guilds").find({}).toArray();
|
||||
|
||||
/*
|
||||
@@ -473,7 +474,7 @@ class DayzRBot extends Client {
|
||||
}
|
||||
|
||||
LoadCommandsAndInteractionHandlers() {
|
||||
let CommandsDir = path.join(__dirname, "..", "commands");
|
||||
let CommandsDir = path.join(__dirname, "commands");
|
||||
fs.readdir(CommandsDir, (err, files) => {
|
||||
if (err) this.error(err);
|
||||
else
|
||||
@@ -497,7 +498,7 @@ class DayzRBot extends Client {
|
||||
}
|
||||
|
||||
LoadEvents() {
|
||||
let EventsDir = path.join(__dirname, "..", "events");
|
||||
let EventsDir = path.join(__dirname, "events");
|
||||
fs.readdir(EventsDir, (err, files) => {
|
||||
if (err) this.error(err);
|
||||
else
|
||||
@@ -555,4 +556,4 @@ class DayzRBot extends Client {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DayzRBot;
|
||||
module.exports = DayZR;
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import DayZR from "./DayZRBot";
|
||||
import config from "./config/config";
|
||||
import { GatewayIntentBits } from "discord.js";
|
||||
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
// Log all uncaught exceptions before killing process.
|
||||
process.on("uncaughtException", async (error: Error) => {
|
||||
console.trace(error);
|
||||
|
||||
const log = JSON.stringify({
|
||||
level: "error",
|
||||
message: `${new Date().toISOString()} | uncaughtException: ${error.stack}`
|
||||
}) + "\n";
|
||||
|
||||
try
|
||||
{
|
||||
await fs.promises.appendFile(path.join(__dirname, "./logs/Logs.log"), log);
|
||||
}
|
||||
catch (logErr)
|
||||
{
|
||||
console.error("Error writing uncaughtException to log file:", logErr);
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
const client: DayZR = new DayZR(
|
||||
{
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.GuildMembers
|
||||
]
|
||||
},
|
||||
config
|
||||
);
|
||||
|
||||
client.build();
|
||||
@@ -1,33 +0,0 @@
|
||||
const DayzR = require("./DayZRBot");
|
||||
const config = require("./config/config");
|
||||
const { GatewayIntentBits } = require("discord.js");
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { HandleActivePlayersList } = require("./util/LogsHandler");
|
||||
|
||||
// Log all uncaught exceptions before killing process.
|
||||
process.on("uncaughtException", async (error) => {
|
||||
console.trace(error);
|
||||
let d = new Date();
|
||||
// Asynchronously write the error message to a log file using Promises
|
||||
await new Promise((resolve, reject) => {
|
||||
if (HandleActivePlayersList.lastSendMessage) HandleActivePlayersList.lastSendMessage.delete().catch(error => client.sendError(channel, `HandleActivePlayersList Error: \n${error}`)); // Remove previous embed message before closing
|
||||
fs.appendFile(path.join(__dirname, "./logs/Logs.log"),
|
||||
`{"level":"error","message":"${d.getHours()}:${d.getMinutes()} - ${d.getMonth() + 1}:${d.getDate()}:${d.getFullYear()} | uncaughtException: ${error.stack}"}`, (logErr) => {
|
||||
if (logErr) {
|
||||
console.error("Error writing uncaughtException to log file:", logErr);
|
||||
reject(logErr);
|
||||
process.exit()
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Now gracefully close the program
|
||||
process.exit()
|
||||
});
|
||||
|
||||
let client = new DayzR({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] }, config);
|
||||
client.build()
|
||||
@@ -1,6 +1,6 @@
|
||||
const { EmbedBuilder } = require("discord.js");
|
||||
const CommandOptions = require("../util/CommandOptionTypes").CommandOptionTypes;
|
||||
const package = require("../package");
|
||||
const pack = require("../../package"); // Project root package.json
|
||||
|
||||
module.exports = {
|
||||
name: "help",
|
||||
@@ -151,7 +151,7 @@ module.exports = {
|
||||
{ name: "Latency", value: `\`\`\`${end - start}ms\`\`\``, inline: true },
|
||||
{ name: "Uptime", value: `\`\`\`${client.secondsToDhms(process.uptime().toFixed(2))}\`\`\``, inline: true },
|
||||
{ name: "Bot Version", value: `\`\`\`${client.config.Dev} v${client.config.Version}\`\`\``, inline: true },
|
||||
{ name: "Discord Version", value: `\`\`\`Discord.js ${package.dependencies["discord.js"]}\`\`\``, inline: true },
|
||||
{ name: "Discord Version", value: `\`\`\`Discord.js ${pack.dependencies["discord.js"]}\`\`\``, inline: true },
|
||||
);
|
||||
|
||||
return interaction.send({ embeds: [stats] })
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const package = require("../../package.json");
|
||||
const version = require("../../package.json").version;
|
||||
require("dotenv").config();
|
||||
|
||||
const PresenceTypes = {
|
||||
@@ -19,7 +19,7 @@ const PresenceStatus = {
|
||||
|
||||
module.exports = {
|
||||
Dev: process.env.Dev || "DEV.",
|
||||
Version: package.version, // (major).(minor).(patch)
|
||||
Version: version, // (major).(minor).(patch)
|
||||
Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot
|
||||
SupportServer: "https://discord.gg/KVFJCvvFtK", // Support Server Link
|
||||
Token: process.env.token || "", //Discord Bot Token
|
||||
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
import { ShardingManager } from "discord.js";
|
||||
const config = require("./config/config");
|
||||
import config from "./config/config";
|
||||
|
||||
const manager = new ShardingManager("./bot.js", { token: config.Token });
|
||||
// ShardingManager spawns node instances and we need to explicitely point to dist/bot.js
|
||||
const manager: ShardingManager = new ShardingManager("./dist/bot.js", { token: config.Token });
|
||||
|
||||
manager.on("shardCreate", shard => console.log(`Launched shard ${shard.id}`));
|
||||
|
||||
|
||||
+4
-1
@@ -6,7 +6,10 @@
|
||||
"outDir": "dist",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules"]
|
||||
|
||||
Reference in new issue
Block a user