From ce93f9e84cd4ee57e79356d63a920525cda98cbf Mon Sep 17 00:00:00 2001 From: Brian Le Date: Fri, 5 Apr 2024 22:39:48 -0700 Subject: [PATCH] Fetch test-runner messages from cache (#2068) * Fetch test-runner messages from cache * lint --- src/helpers/discord_utils.ts | 20 +++++++------------- src/kmq_worker.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/helpers/discord_utils.ts b/src/helpers/discord_utils.ts index 9dcf187b1..c668431c3 100644 --- a/src/helpers/discord_utils.ts +++ b/src/helpers/discord_utils.ts @@ -54,7 +54,7 @@ import dbContext from "../database_context"; import fs from "fs"; import i18n from "./localization_manager"; import type { EmbedGenerator, GuildTextableMessage } from "../types"; -import type { GuildTextableChannel, Message, TextChannel } from "eris"; +import type { GuildTextableChannel } from "eris"; import type AutocompleteEntry from "../interfaces/autocomplete_entry"; import type BookmarkedSong from "../interfaces/bookmarked_song"; import type EmbedPayload from "../interfaces/embed_payload"; @@ -476,19 +476,13 @@ export async function sendMessage( ): Promise { // test bot request, reply with same run ID if (!interaction && messageContent.messageReference) { - let message: Message | undefined; + const testRunnerChannel = State.client.getChannel(textChannelID!) as + | Eris.TextChannel + | undefined; - try { - message = await ( - State.client.getChannel(textChannelID!) as - | Eris.TextChannel - | undefined - )?.getMessage(messageContent.messageReference.messageID); - } catch (e) { - logger.warn( - `Error fetching channel ${textChannelID} for test runner response`, - ); - } + const message = testRunnerChannel?.messages.get( + messageContent.messageReference.messageID, + ); if ( message && diff --git a/src/kmq_worker.ts b/src/kmq_worker.ts index f058515ac..0885a20cd 100644 --- a/src/kmq_worker.ts +++ b/src/kmq_worker.ts @@ -50,6 +50,7 @@ import voiceChannelJoinHandler from "./events/client/voiceChannelJoin"; import voiceChannelLeaveHandler from "./events/client/voiceChannelLeave"; import voiceChannelSwitchHandler from "./events/client/voiceChannelSwitch"; import warnHandler from "./events/client/warn"; +import type * as Eris from "eris"; import type { Setup } from "eris-fleet/dist/clusters/BaseClusterWorker"; import type KmqClient from "./kmq_client"; @@ -390,5 +391,14 @@ export default class BotWorker extends BaseClusterWorker { logger.info(`${this.logHeader()} | Dry run finished successfully.`); State.ipc.totalShutdown(); } + + // test runner needs to fetch messages from cache + const testRunnerChannel = State.client.getChannel( + process.env.END_TO_END_TEST_BOT_CHANNEL!, + ) as Eris.TextChannel | undefined; + + if (testRunnerChannel) { + testRunnerChannel.messages.limit = 10; + } } }