spearkit 0.3.0 → 0.4.0

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/docs/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # spearkit documentation
2
+
3
+ **discord.js++** — a developer-experience-first layer over discord.js. spearkit
4
+ re-exports all of discord.js (so it's a drop-in replacement) and adds an
5
+ ergonomic, fully type-safe API for events, slash commands and interactive
6
+ components.
7
+
8
+ ## Contents
9
+
10
+ 1. [Getting started](./getting-started.md) — install, first bot, project layout.
11
+ 2. [Client](./client.md) — `SpearClient`, intents, `register`, `start`, deployment.
12
+ 3. [Commands](./commands.md) — slash commands, subcommands, permissions, deployment.
13
+ 4. [Options](./options.md) — typed option builders, choices, autocomplete.
14
+ 5. [Components](./components.md) — buttons, selects, modals, custom-id routing.
15
+ 6. [Context menus](./context-menus.md) — user and message "Apps" commands.
16
+ 7. [Events](./events.md) — the `event()` helper and the event registry.
17
+ 8. [Contexts](./context.md) — reply helpers shared by every handler.
18
+ 9. [Guards](./guards.md) — role/permission/owner/guild preconditions.
19
+ 10. [Auto-defer](./auto-defer.md) — beat the 3-second `Unknown interaction` error.
20
+ 11. [Permissions & hierarchy](./permissions.md) — moderation preflight checks.
21
+ 12. [Discord API errors](./errors.md) — recognise and recover from `DiscordAPIError`.
22
+ 13. [Cooldowns](./cooldown.md) — per-user/role/guild rate limiting.
23
+ 14. [Scheduled tasks](./scheduler.md) — cron and interval jobs.
24
+ 15. [Prefix commands](./prefix.md) — classic `!text` commands.
25
+ 16. [Collectors](./collectors.md) — await messages, modals and component clicks.
26
+ 17. [Key-value store & settings](./store.md) — persist per-guild config + dynamic prefix.
27
+ 18. [Messages & limits](./messages.md) — split long output, truncate text.
28
+ 19. [Logging](./logging.md) — structured, leveled, scoped logging.
29
+ 20. [Usage tracking](./usage.md) — record who used what (store + Discord channel).
30
+ 21. [Environment & dotenv](./env.md) — load `.env` and read typed env vars.
31
+ 22. [Graceful shutdown](./shutdown.md) — close cleanly on `SIGINT`/`SIGTERM`.
32
+ 23. [Plugins](./plugins.md) — bundling features into reusable units.
33
+ 24. [File-based loading](./loading.md) — one file per command/event/component.
34
+ 25. [Migrating from discord.js](./migration.md) — the drop-in path.
35
+ 26. [API reference](./api-reference.md) — every exported symbol.
36
+
37
+ ## Why spearkit
38
+
39
+ - **Drop-in.** `import { Client, EmbedBuilder } from "spearkit"` — every discord.js
40
+ export is available, so you can migrate one file at a time.
41
+ - **Fully type-safe.** No `any` or `unknown` leaks into your handlers. Option
42
+ values, custom-id params and modal fields are all inferred from your
43
+ definitions.
44
+ - **Co-located.** A command's options and handler, a button's appearance and
45
+ click logic, a modal's fields and submit logic — each lives in one place.
46
+ - **No boilerplate.** No `interactionCreate` switch statements; spearkit routes
47
+ commands, autocomplete, buttons, selects and modals for you.
48
+
49
+ ## Thirty-second tour
50
+
51
+ ```ts
52
+ import { SpearClient, Intents, command, option, button, row, event } from "spearkit";
53
+
54
+ const client = new SpearClient({ intents: Intents.default });
55
+
56
+ const greet = command({
57
+ name: "greet",
58
+ description: "Greet someone",
59
+ options: { who: option.user({ description: "Who", required: true }) },
60
+ run: (ctx) => ctx.reply(`Hello ${ctx.options.who}!`), // who: User
61
+ });
62
+
63
+ const ping = button({
64
+ id: "ping:{n}",
65
+ label: "Ping",
66
+ run: (ctx) => ctx.update(`pong #${ctx.params.n}`), // n: string
67
+ });
68
+
69
+ client.register(greet, ping, event("clientReady", (c) => console.log(c.user.tag)));
70
+ await client.start(process.env.DISCORD_TOKEN);
71
+ await client.deployCommands({ guildId: process.env.GUILD_ID });
72
+ ```