calabasas 0.8.1 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +23 -0
- package/dist/index.js +103 -24
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -32,7 +32,29 @@ export type CommandDefinition = {
|
|
|
32
32
|
dmPermission?: boolean;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
export type IntentName =
|
|
36
|
+
| "Guilds"
|
|
37
|
+
| "GuildMembers"
|
|
38
|
+
| "GuildModeration"
|
|
39
|
+
| "GuildEmojis"
|
|
40
|
+
| "GuildIntegrations"
|
|
41
|
+
| "GuildWebhooks"
|
|
42
|
+
| "GuildInvites"
|
|
43
|
+
| "GuildVoiceStates"
|
|
44
|
+
| "GuildPresences"
|
|
45
|
+
| "GuildMessages"
|
|
46
|
+
| "GuildMessageReactions"
|
|
47
|
+
| "GuildMessageTyping"
|
|
48
|
+
| "DirectMessages"
|
|
49
|
+
| "DirectMessageReactions"
|
|
50
|
+
| "DirectMessageTyping"
|
|
51
|
+
| "MessageContent"
|
|
52
|
+
| "GuildScheduledEvents"
|
|
53
|
+
| "AutoModerationConfig"
|
|
54
|
+
| "AutoModerationExecution";
|
|
55
|
+
|
|
35
56
|
export type CalabasasConfig = {
|
|
57
|
+
intents?: IntentName[];
|
|
36
58
|
sync?: SyncConfig;
|
|
37
59
|
events?: EventConfig;
|
|
38
60
|
commands?: Record<string, CommandDefinition>;
|
|
@@ -46,6 +68,7 @@ export type CalabasasConfig = {
|
|
|
46
68
|
* import { defineCalabasas } from "calabasas";
|
|
47
69
|
*
|
|
48
70
|
* export default defineCalabasas({
|
|
71
|
+
* intents: ["Guilds", "GuildMessages"],
|
|
49
72
|
* sync: {
|
|
50
73
|
* guilds: true,
|
|
51
74
|
* channels: true,
|
package/dist/index.js
CHANGED
|
@@ -2191,6 +2191,9 @@ var CONFIG_TEMPLATE = `// Calabasas configuration
|
|
|
2191
2191
|
import { defineCalabasas } from "calabasas";
|
|
2192
2192
|
|
|
2193
2193
|
export default defineCalabasas({
|
|
2194
|
+
// Gateway intents - which events Discord sends to your bot
|
|
2195
|
+
// intents: ["Guilds", "GuildMessages"],
|
|
2196
|
+
|
|
2194
2197
|
// Managed sync - Discord data synced automatically to your tables
|
|
2195
2198
|
sync: {
|
|
2196
2199
|
guilds: true, // Sync server info (calabasasGuilds table)
|
|
@@ -2264,6 +2267,58 @@ async function parseConfigFile(configPath) {
|
|
|
2264
2267
|
return config;
|
|
2265
2268
|
}
|
|
2266
2269
|
|
|
2270
|
+
// src/lib/intents.ts
|
|
2271
|
+
var INTENT_MAP = {
|
|
2272
|
+
Guilds: 1 << 0,
|
|
2273
|
+
GuildMembers: 1 << 1,
|
|
2274
|
+
GuildModeration: 1 << 2,
|
|
2275
|
+
GuildEmojis: 1 << 3,
|
|
2276
|
+
GuildIntegrations: 1 << 4,
|
|
2277
|
+
GuildWebhooks: 1 << 5,
|
|
2278
|
+
GuildInvites: 1 << 6,
|
|
2279
|
+
GuildVoiceStates: 1 << 7,
|
|
2280
|
+
GuildPresences: 1 << 8,
|
|
2281
|
+
GuildMessages: 1 << 9,
|
|
2282
|
+
GuildMessageReactions: 1 << 10,
|
|
2283
|
+
GuildMessageTyping: 1 << 11,
|
|
2284
|
+
DirectMessages: 1 << 12,
|
|
2285
|
+
DirectMessageReactions: 1 << 13,
|
|
2286
|
+
DirectMessageTyping: 1 << 14,
|
|
2287
|
+
MessageContent: 1 << 15,
|
|
2288
|
+
GuildScheduledEvents: 1 << 16,
|
|
2289
|
+
AutoModerationConfig: 1 << 20,
|
|
2290
|
+
AutoModerationExecution: 1 << 21
|
|
2291
|
+
};
|
|
2292
|
+
var PRIVILEGED_INTENTS = new Set([
|
|
2293
|
+
"GuildMembers",
|
|
2294
|
+
"GuildPresences",
|
|
2295
|
+
"MessageContent"
|
|
2296
|
+
]);
|
|
2297
|
+
var INTENT_DESCRIPTIONS = {
|
|
2298
|
+
Guilds: "Guild create/update/delete, roles, channels",
|
|
2299
|
+
GuildMembers: "Member add/remove/update (Privileged)",
|
|
2300
|
+
GuildModeration: "Bans, audit log",
|
|
2301
|
+
GuildEmojis: "Emoji/sticker updates",
|
|
2302
|
+
GuildIntegrations: "Integration updates",
|
|
2303
|
+
GuildWebhooks: "Webhook updates",
|
|
2304
|
+
GuildInvites: "Invite create/delete",
|
|
2305
|
+
GuildVoiceStates: "Voice state updates",
|
|
2306
|
+
GuildPresences: "Presence updates (Privileged)",
|
|
2307
|
+
GuildMessages: "Message create/update/delete in guilds",
|
|
2308
|
+
GuildMessageReactions: "Reaction add/remove in guilds",
|
|
2309
|
+
GuildMessageTyping: "Typing start in guilds",
|
|
2310
|
+
DirectMessages: "DM create/update/delete",
|
|
2311
|
+
DirectMessageReactions: "Reaction add/remove in DMs",
|
|
2312
|
+
DirectMessageTyping: "Typing start in DMs",
|
|
2313
|
+
MessageContent: "Access message content (Privileged)",
|
|
2314
|
+
GuildScheduledEvents: "Scheduled event updates",
|
|
2315
|
+
AutoModerationConfig: "Auto mod rule changes",
|
|
2316
|
+
AutoModerationExecution: "Auto mod action execution"
|
|
2317
|
+
};
|
|
2318
|
+
function intentsToBitfield(names) {
|
|
2319
|
+
return names.reduce((bits, name) => bits | INTENT_MAP[name], 0);
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2267
2322
|
// src/commands/push.ts
|
|
2268
2323
|
async function push(options) {
|
|
2269
2324
|
const env = resolveEnv(options);
|
|
@@ -2329,6 +2384,35 @@ async function push(options) {
|
|
|
2329
2384
|
process.exit(1);
|
|
2330
2385
|
}
|
|
2331
2386
|
}
|
|
2387
|
+
const intents = calabasasConfig.intents;
|
|
2388
|
+
if (intents && intents.length > 0) {
|
|
2389
|
+
const validNames = Object.keys(INTENT_MAP);
|
|
2390
|
+
const invalid = intents.filter((name) => !validNames.includes(name));
|
|
2391
|
+
if (invalid.length > 0) {
|
|
2392
|
+
s.stop("Invalid intents");
|
|
2393
|
+
p4.cancel(`Unknown intent names: ${invalid.join(", ")}`);
|
|
2394
|
+
process.exit(1);
|
|
2395
|
+
}
|
|
2396
|
+
const privilegedUsed = intents.filter((name) => PRIVILEGED_INTENTS.has(name));
|
|
2397
|
+
if (privilegedUsed.length > 0) {
|
|
2398
|
+
p4.log.warn(`Privileged intents: ${privilegedUsed.join(", ")} — make sure these are enabled in the Discord Developer Portal.`);
|
|
2399
|
+
}
|
|
2400
|
+
const bitfield = intentsToBitfield(intents);
|
|
2401
|
+
const intentsResponse = await fetch(`${apiUrl}/api/cli/bots`, {
|
|
2402
|
+
method: "PATCH",
|
|
2403
|
+
headers: {
|
|
2404
|
+
"Content-Type": "application/json",
|
|
2405
|
+
Authorization: `Bearer ${apiKey}`
|
|
2406
|
+
},
|
|
2407
|
+
body: JSON.stringify({ botId, intents: bitfield })
|
|
2408
|
+
});
|
|
2409
|
+
if (!intentsResponse.ok) {
|
|
2410
|
+
const error = await intentsResponse.text();
|
|
2411
|
+
s.stop("Intents push failed");
|
|
2412
|
+
p4.cancel(`Error: ${error}`);
|
|
2413
|
+
process.exit(1);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2332
2416
|
s.stop("Config pushed!");
|
|
2333
2417
|
const syncSummary = [
|
|
2334
2418
|
`Guilds: ${calabasasConfig.sync?.guilds ? "enabled" : "disabled"}`,
|
|
@@ -2350,7 +2434,12 @@ No event handlers configured.`;
|
|
|
2350
2434
|
Commands: ${commandNames.length} configured
|
|
2351
2435
|
${commandNames.map((name) => ` - /${name}`).join(`
|
|
2352
2436
|
`)}` : "";
|
|
2353
|
-
|
|
2437
|
+
const intentsSummary = intents && intents.length > 0 ? `
|
|
2438
|
+
|
|
2439
|
+
Intents: ${intents.length} configured
|
|
2440
|
+
${intents.map((name) => ` - ${name}`).join(`
|
|
2441
|
+
`)}` : "";
|
|
2442
|
+
p4.note(syncSummary + eventSummary + commandSummary + intentsSummary, "Sync settings");
|
|
2354
2443
|
p4.outro("Config pushed successfully!");
|
|
2355
2444
|
}
|
|
2356
2445
|
|
|
@@ -3456,6 +3545,11 @@ export const discord = {
|
|
|
3456
3545
|
return callProxy("getMessage", { channelId, messageId });
|
|
3457
3546
|
},
|
|
3458
3547
|
|
|
3548
|
+
/** Get messages from a channel (max 100 per call) */
|
|
3549
|
+
getMessages(channelId: string, options?: { limit?: number; before?: string; after?: string; around?: string }): Promise<unknown> {
|
|
3550
|
+
return callProxy("getMessages", { channelId, ...options });
|
|
3551
|
+
},
|
|
3552
|
+
|
|
3459
3553
|
/** Add a reaction to a message */
|
|
3460
3554
|
addReaction(channelId: string, messageId: string, emoji: string): Promise<unknown> {
|
|
3461
3555
|
return callProxy("addReaction", { channelId, messageId, emoji });
|
|
@@ -6190,27 +6284,12 @@ Run a migration with: calabasas migrate <name>`);
|
|
|
6190
6284
|
// src/commands/bot.ts
|
|
6191
6285
|
import * as p10 from "@clack/prompts";
|
|
6192
6286
|
import pc from "picocolors";
|
|
6193
|
-
var
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
{ name: "Guild Webhooks", value: 1 << 5, description: "Webhook updates" },
|
|
6200
|
-
{ name: "Guild Invites", value: 1 << 6, description: "Invite create/delete" },
|
|
6201
|
-
{ name: "Guild Voice States", value: 1 << 7, description: "Voice state updates" },
|
|
6202
|
-
{ name: "Guild Presences", value: 1 << 8, description: "Presence updates (Privileged)", privileged: true },
|
|
6203
|
-
{ name: "Guild Messages", value: 1 << 9, description: "Message create/update/delete in guilds" },
|
|
6204
|
-
{ name: "Guild Message Reactions", value: 1 << 10, description: "Reaction add/remove in guilds" },
|
|
6205
|
-
{ name: "Guild Message Typing", value: 1 << 11, description: "Typing start in guilds" },
|
|
6206
|
-
{ name: "Direct Messages", value: 1 << 12, description: "DM create/update/delete" },
|
|
6207
|
-
{ name: "Direct Message Reactions", value: 1 << 13, description: "Reaction add/remove in DMs" },
|
|
6208
|
-
{ name: "Direct Message Typing", value: 1 << 14, description: "Typing start in DMs" },
|
|
6209
|
-
{ name: "Message Content", value: 1 << 15, description: "Access message content (Privileged)", privileged: true },
|
|
6210
|
-
{ name: "Guild Scheduled Events", value: 1 << 16, description: "Scheduled event updates" },
|
|
6211
|
-
{ name: "Auto Moderation Config", value: 1 << 20, description: "Auto mod rule changes" },
|
|
6212
|
-
{ name: "Auto Moderation Execution", value: 1 << 21, description: "Auto mod action execution" }
|
|
6213
|
-
];
|
|
6287
|
+
var INTENT_ENTRIES = Object.keys(INTENT_MAP).map((name) => ({
|
|
6288
|
+
name,
|
|
6289
|
+
value: INTENT_MAP[name],
|
|
6290
|
+
description: INTENT_DESCRIPTIONS[name],
|
|
6291
|
+
privileged: PRIVILEGED_INTENTS.has(name)
|
|
6292
|
+
}));
|
|
6214
6293
|
async function apiRequest(method, path8, body, env) {
|
|
6215
6294
|
const config = getConfig(env);
|
|
6216
6295
|
const url = `${getApiUrlForEnv(env)}${path8}`;
|
|
@@ -6296,7 +6375,7 @@ async function botAdd(options) {
|
|
|
6296
6375
|
} else {
|
|
6297
6376
|
const selectedIntents = await p10.multiselect({
|
|
6298
6377
|
message: "Select Gateway Intents",
|
|
6299
|
-
options:
|
|
6378
|
+
options: INTENT_ENTRIES.map((intent, i) => ({
|
|
6300
6379
|
value: i,
|
|
6301
6380
|
label: intent.privileged ? pc.yellow(intent.name + " (Privileged)") : intent.name,
|
|
6302
6381
|
hint: intent.description
|
|
@@ -6308,7 +6387,7 @@ async function botAdd(options) {
|
|
|
6308
6387
|
p10.cancel("Cancelled.");
|
|
6309
6388
|
return;
|
|
6310
6389
|
}
|
|
6311
|
-
intents = selectedIntents.reduce((sum, i) => sum +
|
|
6390
|
+
intents = selectedIntents.reduce((sum, i) => sum + INTENT_ENTRIES[i].value, 0);
|
|
6312
6391
|
}
|
|
6313
6392
|
const s = p10.spinner();
|
|
6314
6393
|
s.start("Creating bot...");
|