Skip to content

Commit

Permalink
Avoid using process.env when not available, remove default offset on …
Browse files Browse the repository at this point in the history
…interaction token expiry
  • Loading branch information
ssMMiles committed Sep 4, 2024
1 parent f50eef5 commit 381e953
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/core/src/app/contexts/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import { InteractionResponseAlreadySent, InteractionStateExpired } from "../../u
import { DiscordApplication, ResponseCallback } from "../DiscordApplication.js";
import { WebhookClient } from "../WebhookClient.js";

// 15 minute token, minus 250ms to account for latency
const TokenExpiryOffset = isNaN(Number(process.env.TOKEN_EXPIRY_OFFSET))
? 250
: Number(process.env.TOKEN_EXPIRY_OFFSET);
// Date functions return a fixed time in workers so doesn't apply there
// Can be used to make up for the latency to Discord when calculating expiry times.
const TokenExpiryOffset =
process === undefined || isNaN(Number(process.env.TOKEN_EXPIRY_OFFSET)) ? 0 : Number(process.env.TOKEN_EXPIRY_OFFSET);

const InteractionTokenExpiryTime = 15 * 60 * 1000 - TokenExpiryOffset;

export class BaseInteractionContext<
Expand Down

0 comments on commit 381e953

Please sign in to comment.