Skip to content

Commit

Permalink
Fetch test-runner messages from cache (#2068)
Browse files Browse the repository at this point in the history
* Fetch test-runner messages from cache

* lint
  • Loading branch information
Brainicism authored Apr 6, 2024
1 parent f569c06 commit ce93f9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/helpers/discord_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -476,19 +476,13 @@ export async function sendMessage(
): Promise<Eris.Message | null> {
// test bot request, reply with same run ID
if (!interaction && messageContent.messageReference) {
let message: Message<TextChannel> | 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 &&
Expand Down
10 changes: 10 additions & 0 deletions src/kmq_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit ce93f9e

Please sign in to comment.