-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
59 lines (50 loc) · 2.14 KB
/
Copy pathconfig.ts
File metadata and controls
59 lines (50 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { logger } from './logger';
/**
* Read a required environment variable, exiting the process if it is missing.
*/
function requireEnv(name: string): string {
const value = process.env[name];
if (!value || value.trim() === '') {
logger.error(`Missing required environment variable: ${name}`);
process.exit(1);
}
return value.trim();
}
/**
* Read an integer environment variable, falling back to a default when unset or
* not a valid number.
*/
function intFromEnv(name: string, fallback: number): number {
const raw = process.env[name];
if (raw === undefined) return fallback;
const parsed = Number.parseInt(raw, 10);
return Number.isNaN(parsed) ? fallback : parsed;
}
/**
* Read a boolean-ish environment variable ('1', 'true', 'yes').
*/
function boolFromEnv(name: string): boolean {
const raw = process.env[name]?.trim().toLowerCase();
return raw === '1' || raw === 'true' || raw === 'yes';
}
/**
* Bot configuration, read once at startup. Required Discord credentials cause an
* early exit if missing; everything else has a sensible default so the bot keeps
* working against the public MDN MCP server out of the box.
*/
export const config = {
discordToken: requireEnv('DISCORD_TOKEN'),
discordClientId: requireEnv('DISCORD_CLIENT_ID'),
// When set, commands deploy to this single guild (instant updates) instead of
// globally (which can take up to an hour to propagate). Ideal for development.
guildId: process.env.DISCORD_GUILD_ID?.trim() || undefined,
// The MDN MCP endpoint. Overridable for local development against mdn/mcp.
mcpUrl: process.env.MDN_MCP_URL?.trim() || 'https://mcp.mdn.mozilla.net/',
// Optional prefix applied to every generated command name, e.g. 'mdn-' turns
// the 'search' tool into '/mdn-search'. Useful to avoid clashes with other bots.
commandPrefix: process.env.COMMAND_PREFIX?.trim() || '',
// Send the documented opt-out header so MDN does not log query analytics.
optOutAnalytics: boolFromEnv('MDN_OPT_OUT'),
// How often to re-poll the MCP tool list and re-deploy commands if it changed.
refreshIntervalMs: intFromEnv('REFRESH_INTERVAL_MS', 15 * 60 * 1000),
} as const;