This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user