From 2eebf996c58e5729d8750b9661005059d7e688ef Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sat, 25 May 2024 10:23:18 +0200 Subject: [PATCH] better logging --- src/bot.ts | 1 + src/commands/add.ts | 2 ++ src/commands/list.ts | 2 ++ src/commands/ping.ts | 2 ++ src/commands/remove.ts | 2 ++ src/commands/update.ts | 4 +++- src/index.ts | 1 + src/player.ts | 4 ---- src/util.ts | 17 ++++++++++++++++- 9 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index de899eb..230c2c1 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -2,6 +2,7 @@ import {Client, Collection, Events, GatewayIntentBits, Interaction} from "discor import {Player} from "./player"; import fs from "node:fs"; import {Command, loadCommands} from "./command"; +require("./util.js"); export class UEMEloBot extends Client { diff --git a/src/commands/add.ts b/src/commands/add.ts index 9bdd86b..c57353d 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -15,6 +15,8 @@ class Add extends Command { if (!interaction.isChatInputCommand()) return; + console.log("Add command used"); + let client = interaction.client as UEMEloBot; const riotId = interaction.options.getString("riot-id", true); diff --git a/src/commands/list.ts b/src/commands/list.ts index 553a19e..20a9115 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -12,6 +12,8 @@ class List extends Command { if (!interaction.isChatInputCommand()) return; + console.log("List command used"); + const serverID = await checkServer(interaction); if (!serverID) return; diff --git a/src/commands/ping.ts b/src/commands/ping.ts index a0c4345..76157ca 100644 --- a/src/commands/ping.ts +++ b/src/commands/ping.ts @@ -9,6 +9,8 @@ class Ping extends Command { if (!interaction.isChatInputCommand()) return; + console.log("Ping command used"); + await interaction.reply({content: "Pong", ephemeral: true}); } } diff --git a/src/commands/remove.ts b/src/commands/remove.ts index 5459737..e4ed9d4 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -15,6 +15,8 @@ class Remove extends Command { if (!interaction.isChatInputCommand()) return; + console.log("Remove command used"); + let client = interaction.client as UEMEloBot; const riotId = interaction.options.getString("riot-id", true); diff --git a/src/commands/update.ts b/src/commands/update.ts index bd0b41f..5eedcee 100644 --- a/src/commands/update.ts +++ b/src/commands/update.ts @@ -4,12 +4,14 @@ import {UEMEloBot} from "../bot"; class Update extends Command { constructor() { - super("update", "Ränge jetzt aktualisieren (passiert automatisch alle 30min)"); + super("update", "Ränge jetzt aktualisieren (passiert automatisch alle 20min)"); } async execute(interaction: Interaction) { if (!interaction.isChatInputCommand()) return; + console.log("Update command used"); + await interaction.deferReply({ephemeral: true}); let client = interaction.client as UEMEloBot; diff --git a/src/index.ts b/src/index.ts index 41f8a5c..b9a427c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ require("dotenv").config(); import {UEMEloBot} from "./bot"; import readline from "readline"; +require("util"); readline.createInterface({input: process.stdin}).on('line', async line => { if (line == "stop") diff --git a/src/player.ts b/src/player.ts index 193e80a..6eb08d6 100644 --- a/src/player.ts +++ b/src/player.ts @@ -69,12 +69,8 @@ export class Player { try { entries = await tryRegion(PlatformId.EUW1); } catch (error){ - let response = error as Response; - console.error(await response.json()); - console.log(`Trying EUNE Region...`); try { entries = await tryRegion(PlatformId.EUNE1); - console.log(`Success with EUNE`); } catch (error){ let response = error as Response; console.error(await response.json()); diff --git a/src/util.ts b/src/util.ts index 152a569..12966ca 100644 --- a/src/util.ts +++ b/src/util.ts @@ -7,4 +7,19 @@ export async function checkServer(interaction: ChatInputCommandInteraction){ await interaction.reply({content: "Fehler!", ephemeral: true}); } return serverID; -} \ No newline at end of file +} + +const originalLog = console.log; +const originalError = console.error; + +function getTimestamp() { + return new Date().toISOString(); +} + +console.log = function(...args) { + originalLog(`[${getTimestamp()}]`, ...args); +}; + +console.error = function(...args) { + originalError(`[${getTimestamp()}]`, ...args); +}; \ No newline at end of file