Skip to content

Commit

Permalink
Log shards date
Browse files Browse the repository at this point in the history
  • Loading branch information
Feiryn committed Jan 10, 2024
1 parent 1f72f2c commit 0131aa8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/core/bot/DraftBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {BigEventsController} from "../events/BigEventsController";
import {MapCache} from "../maps/MapCache";
import {LeagueInfoConstants} from "../constants/LeagueInfoConstants";
import {Settings} from "../database/game/models/Setting";
import {getDateLogString} from "../utils/StringUtils";

/**
* The main class of the bot, manages the bot in general
Expand Down Expand Up @@ -559,9 +560,7 @@ export class DraftBot {
if (!message) {
return;
}
const now = new Date();
// eslint-disable-next-line max-len
const dateStr = `[${now.getFullYear()}/${`0${now.getMonth() + 1}`.slice(-2)}/${`0${now.getDate()}`.slice(-2)} ${`0${now.getHours()}`.slice(-2)}:${`0${now.getMinutes()}`.slice(-2)}:${`0${now.getSeconds()}`.slice(-2)}] `;
const dateStr = `${getDateLogString()} `;
try {
fs.appendFileSync(
thisInstance.currLogsFile,
Expand Down
5 changes: 5 additions & 0 deletions src/core/utils/StringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ export function getIdFromMention(variable: string): string {
*/
export function getMention(discordUserId: string): string {
return `<@${discordUserId}>`;
}

export function getDateLogString(): string {
const now = new Date();
return `[${now.getFullYear()}/${`0${now.getMonth() + 1}`.slice(-2)}/${`0${now.getDate()}`.slice(-2)} ${`0${now.getHours()}`.slice(-2)}:${`0${now.getMinutes()}`.slice(-2)}:${`0${now.getSeconds()}`.slice(-2)}]`;
}
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {IPCServer} from "./core/bot/ipc/IPCServer";
import AutoPoster from "topgg-autoposter";
import {initWebServer} from "./core/bot/DraftBotWebServer";
import {error} from "console";
import {getDateLogString} from "./core/utils/StringUtils";

process.on("unhandledRejection", function(err: Error) {
console.log(err);
Expand Down Expand Up @@ -32,14 +33,14 @@ function main(): void {

shardingManager.on("shardCreate", shard => {
shard.on("ready", () => {
console.log(`[DEBUG/SHARD] Shard ${shard.id} connected to Discord's Gateway.`);
console.log(`${getDateLogString()} [DEBUG/SHARD] Shard ${shard.id} connected to Discord's Gateway.`);
shard.send({type: "shardId", data: {shardId: shard.id}}).then();
});
shard.on("spawn", () => error(`Shard ${shard.id} created`));
shard.on("death", () => error(`Shard ${shard.id} exited`));
shard.on("disconnect", () => error(`Shard ${shard.id} disconnected`));
shard.on("reconnecting", () => error(`Shard ${shard.id} reconnected`));
shard.on("error", (err) => error(`Shard ${shard.id} an error occurred ${err}`));
shard.on("spawn", () => error(`${getDateLogString()} Shard ${shard.id} created`));
shard.on("death", () => error(`${getDateLogString()} Shard ${shard.id} exited`));
shard.on("disconnect", () => error(`${getDateLogString()} Shard ${shard.id} disconnected`));
shard.on("reconnecting", () => error(`${getDateLogString()} Shard ${shard.id} reconnected`));
shard.on("error", (err) => error(`${getDateLogString()} Shard ${shard.id} an error occurred: ${err}`));
});

// Auto posting stats to top.gg
Expand Down

0 comments on commit 0131aa8

Please sign in to comment.