From 5b84b9a70a1e6cf6166d503cfcefffeb7e142a91 Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Sun, 16 Jul 2023 23:28:13 +0200 Subject: [PATCH] logging part 2 --- index.js | 3 +++ labscore/client.js | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index d920b5a..a9d440b 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,8 @@ const manager = new ClusterManager(client, token, { (async () => { console.log(`v2 | starting v2.`) + + // Logging manager.on("clusterProcess", ({ clusterProcess }) => { clusterProcess.on('close', ({code, signal}) => { basecamp(`<:ico_w4:1086624964284788787>\`[${process.env.HOSTNAME}]\` **\` CLUSTER_CLOSED \`** Cluster ${clusterProcess.clusterId} closed with code \`${code}\` and signal \`${signal}\` @ \`${Date.now()}\``) @@ -27,6 +29,7 @@ const manager = new ClusterManager(client, token, { await basecamp(`\`\`\`js\n${error}\`\`\``) }); }) + await manager.run(); console.log(`v2 | ready. took ${(Date.now() - time) / 1000}.`) })(); \ No newline at end of file diff --git a/labscore/client.js b/labscore/client.js index 0543faa..086a5d2 100644 --- a/labscore/client.js +++ b/labscore/client.js @@ -1,5 +1,5 @@ const { Constants, ClusterClient, CommandClient, InteractionCommandClient } = require('detritus-client'); -const { ActivityTypes, PresenceStatuses, GatewayIntents, Permissions } = require('detritus-client/lib/constants'); +const { ActivityTypes, PresenceStatuses, GatewayIntents, Permissions, ClientEvents } = require('detritus-client/lib/constants'); const Paginator = require('./paginator').PaginatorCluster @@ -52,7 +52,7 @@ const interactionClient = new InteractionCommandClient(cluster, { useClusterClient: true }) -const { maintower } = require('./logging'); +const { maintower, basecamp } = require('./logging'); const { icon, highlight } = require('./utils/markdown'); const { editOrReply } = require('./utils/message'); @@ -124,11 +124,34 @@ commandClient.on('commandRunError', async ({context, error}) => { }); (async () => { - await cluster.run(); - await commandClient.addMultipleIn('../commands/message/'); - await commandClient.run() - await interactionClient.addMultipleIn('../commands/interaction/context'); - await interactionClient.addMultipleIn('../commands/interaction/slash'); - await interactionClient.run(); + // Logging + cluster.on(ClientEvents.REST_RESPONSE, async ({response, restRequest, shard}) => { + const route = response.request.route; + if (route) { + if (!response.ok) { + const message = `Shard #${shard.shardId}: (NOT OK) ${response.statusCode} ${response.request.method}-${response.request.url} (${route.path})`; + console.log(message); + console.log(await response.text()); + await basecamp(`<:ico_w3:1086624963047460874>\`[${process.env.HOSTNAME}]\` **\` SHARD_REST_ERROR \`** Shard ${shard.shardId} received request error \`${response.statusCode}\` @ \`${Date.now()}\`\n\` ${response.request.method} \` \`${response.request.url}\` (${route.path})\n\`\`\`js\n${await response.text()}\`\`\``) + } + } + }); + + cluster.on(ClientEvents.WARN, async ({error}) => { + await basecamp(`<:ico_w2:1086624961025810485>\`[${process.env.HOSTNAME}]\` **\` CLUSTER_WARNING \`** Cluster ${cluster.manager.clusterId} reported warning @ \`${Date.now()}\`:\n\`\`\`${error}\`\`\``) + }); + + try{ + await cluster.run(); + await commandClient.addMultipleIn('../commands/message/'); + await commandClient.run() + + await interactionClient.addMultipleIn('../commands/interaction/context'); + await interactionClient.addMultipleIn('../commands/interaction/slash'); + await interactionClient.run(); + } catch(e){ + console.log(e) + console.log(e.errors) + } })(); \ No newline at end of file