Skip to content

Commit

Permalink
Defer interactions from Global buttons (oldschoolgg#5897)
Browse files Browse the repository at this point in the history
* Defer interactions from Global buttons

* Check cooldowns first
  • Loading branch information
themrrobert authored Jun 18, 2024
1 parent 627e68f commit 73f4b88
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/lib/util/globalInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { toaHelpCommand } from '../simulation/toa';
import { ItemBank } from '../types';
import { formatDuration, stringMatches } from '../util';
import { updateGiveawayMessage } from './giveaway';
import { interactionReply } from './interactionReply';
import { deferInteraction, interactionReply } from './interactionReply';
import { minionIsBusy } from './minionIsBusy';
import { fetchRepeatTrips, repeatTrip } from './repeatStoredTrip';

Expand Down Expand Up @@ -325,6 +325,16 @@ export async function interactionHook(interaction: Interaction) {
const id = interaction.customId;
const userID = interaction.user.id;

const cd = Cooldowns.get(userID, 'button', Time.Second * 3);
if (cd !== null) {
return interactionReply(interaction, {
content: `You're on cooldown from clicking buttons, please wait: ${formatDuration(cd, true)}.`,
ephemeral: true
});
}

await deferInteraction(interaction);

const user = await mUserFetch(userID);
if (id.includes('GIVEAWAY_')) return giveawayButtonHandler(user, id, interaction);
if (id.includes('REPEAT_TRIP')) return repeatTripHandler(user, interaction);
Expand Down Expand Up @@ -353,14 +363,6 @@ export async function interactionHook(interaction: Interaction) {
continueDeltaMillis: null
};

const cd = Cooldowns.get(userID, 'button', Time.Second * 3);
if (cd !== null) {
return interactionReply(interaction, {
content: `You're on cooldown from clicking buttons, please wait: ${formatDuration(cd, true)}.`,
ephemeral: true
});
}

const timeSinceMessage = Date.now() - new Date(interaction.message.createdTimestamp).getTime();
const timeLimit = reactionTimeLimit(user.perkTier());
if (timeSinceMessage > Time.Day) {
Expand Down

0 comments on commit 73f4b88

Please sign in to comment.