31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { discordSnowflake } from '../../discord.js';
|
|
|
|
/** Credentials belong to the deployment environment and never to browser settings. */
|
|
export function discordCredentials() {
|
|
return {
|
|
applicationId: (process.env.EC_DISCORD_APPLICATION_ID ?? '').trim(),
|
|
publicKey: (process.env.EC_DISCORD_PUBLIC_KEY ?? '').trim(),
|
|
botToken: (process.env.EC_DISCORD_BOT_TOKEN ?? '').trim()
|
|
};
|
|
}
|
|
|
|
export function discordCredentialStatus() {
|
|
const credentials = discordCredentials();
|
|
return {
|
|
applicationId: credentials.applicationId,
|
|
publicKeyConfigured: /^[a-fA-F0-9]{64}$/.test(credentials.publicKey),
|
|
botTokenConfigured: !!credentials.botToken
|
|
};
|
|
}
|
|
|
|
export function requireDiscordCredentials(): ReturnType<typeof discordCredentials> {
|
|
const credentials = discordCredentials();
|
|
if (
|
|
!discordSnowflake(credentials.applicationId) ||
|
|
!/^[a-fA-F0-9]{64}$/.test(credentials.publicKey) ||
|
|
!credentials.botToken
|
|
)
|
|
throw new Error('Configure the Discord application ID, public key and bot token first.');
|
|
return credentials;
|
|
}
|