Skip to content

Commit

Permalink
fix: parkour command and interaction server issues (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobk999 authored Aug 21, 2024
1 parent 6d36a8a commit e3c1880
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion apps/discord-bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ await Promise.all(
[I18nLoaderService, FontLoaderService].map((service) => Container.get(service).init())
);

const rest = new RestClient({ token: config("discordBot.token") });
const rest = new RestClient({ token: config("discordBot.token"), timeout: 60 * 1000 });
Container.set(RestClient, rest);

const commands = await CommandLoader.load(join(__dirname, "./commands"));
Expand Down
23 changes: 6 additions & 17 deletions packages/discord/src/command/abstract-command.listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import type {
WebsocketShard,
} from "tiny-discord";

const COMMAND_INTERACTION_RESPONSE = {};
type CommandInteractionResponse = typeof COMMAND_INTERACTION_RESPONSE;

export type InteractionHook = (
interaction: Interaction
) => InteractionServer.InteractionReply | undefined | Promise<any>;
Expand Down Expand Up @@ -269,17 +266,10 @@ export abstract class AbstractCommandListener {
};
}

private async onInteraction(
interaction: Interaction
): Promise<InteractionServer.InteractionReply | CommandInteractionResponse> {
private async onInteraction(interaction: Interaction): Promise<InteractionServer.InteractionReply> {
if (interaction.isCommandInteraction()) {
await interaction.reply({
type: InteractionResponseType.DeferredChannelMessageWithSource,
});

this.onCommand(interaction);

return COMMAND_INTERACTION_RESPONSE;
return { type: InteractionResponseType.DeferredChannelMessageWithSource };
}

if (interaction.isAutocompleteInteraction()) return this.onAutocomplete(interaction);
Expand All @@ -296,9 +286,10 @@ export abstract class AbstractCommandListener {
});

// @ts-ignore Discord supports sending a blank object as a response
client.on("interaction", (event) => {
client.on("interaction", async (event) => {
const interaction = new Interaction(this.rest, event.interaction, this.applicationId);
return this.onInteraction(interaction);
const response = await this.onInteraction(interaction);
interaction.reply(response);
});
}

Expand All @@ -323,9 +314,7 @@ export abstract class AbstractCommandListener {
);

const response = await this.onInteraction(interaction);
if (response === COMMAND_INTERACTION_RESPONSE) return;

interaction.reply(response as InteractionServer.InteractionReply);
interaction.reply(response);
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/schemas/src/player/gamemodes/parkour/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class Parkour {
leaderboard: { ...fieldOptions, name: `${FormattedGame.WOOLGAMES} Lobby` },
historical,
})
public WOOLWARS: number;
public WOOLGAMES: number;

public constructor(data: APIData) {
const getTime = (key: string): number =>
Expand All @@ -151,6 +151,6 @@ export class Parkour {
this.TOURNAMENT_LOBBY = getTime("Tourney");
this.UHC = getTime("uhc");
this.WARLORDS = getTime("Warlords");
this.WOOLWARS = getTime("WoolGames");
this.WOOLGAMES = getTime("WoolGames");
}
}

0 comments on commit e3c1880

Please sign in to comment.