fix: gate discord slash commands
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
- UI: add optional `ui.seamColor` accent to tint the Talk Mode side bubble (macOS/iOS/Android).
|
- UI: add optional `ui.seamColor` accent to tint the Talk Mode side bubble (macOS/iOS/Android).
|
||||||
- Nix mode: opt-in declarative config + read-only settings UI when `CLAWDIS_NIX_MODE=1` (thanks @joshp123 for the persistence — earned my trust; I'll merge these going forward).
|
- Nix mode: opt-in declarative config + read-only settings UI when `CLAWDIS_NIX_MODE=1` (thanks @joshp123 for the persistence — earned my trust; I'll merge these going forward).
|
||||||
- Agent runtime: accept legacy `Z_AI_API_KEY` for Z.AI provider auth (maps to `ZAI_API_KEY`).
|
- Agent runtime: accept legacy `Z_AI_API_KEY` for Z.AI provider auth (maps to `ZAI_API_KEY`).
|
||||||
|
- Discord: add user-installed slash command handling with per-user sessions and auto-registration (#94) — thanks @thewilloftheshadow.
|
||||||
- Discord: add DM enable/allowlist plus guild channel/user/guild allowlists with id/name matching.
|
- Discord: add DM enable/allowlist plus guild channel/user/guild allowlists with id/name matching.
|
||||||
- Signal: add `signal-cli` JSON-RPC support for send/receive via the Signal provider.
|
- Signal: add `signal-cli` JSON-RPC support for send/receive via the Signal provider.
|
||||||
- iMessage: add imsg JSON-RPC integration (stdio), chat_id routing, and group chat support.
|
- iMessage: add imsg JSON-RPC integration (stdio), chat_id routing, and group chat support.
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ Minimal `~/.clawdis/clawdis.json`:
|
|||||||
### Discord
|
### Discord
|
||||||
|
|
||||||
- Set `DISCORD_BOT_TOKEN` or `discord.token` (env wins).
|
- Set `DISCORD_BOT_TOKEN` or `discord.token` (env wins).
|
||||||
- Optional: set `discord.requireMention`, `discord.slashCommand`, `discord.allowFrom`, or `discord.mediaMaxMb` as needed.
|
- Optional: set `discord.slashCommand`, `discord.dm.allowFrom`, `discord.guilds`, or `discord.mediaMaxMb` as needed.
|
||||||
|
|
||||||
```json5
|
```json5
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -844,58 +844,6 @@ function resolveSlashPrompt(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureSlashCommand(
|
|
||||||
client: Client,
|
|
||||||
slashCommand: Required<DiscordSlashCommandConfig>,
|
|
||||||
runtime: RuntimeEnv,
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
const appCommands = client.application?.commands;
|
|
||||||
if (!appCommands) {
|
|
||||||
runtime.error?.(danger("discord slash commands unavailable"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const existing = await appCommands.fetch();
|
|
||||||
let hasCommand = false;
|
|
||||||
for (const entry of existing.values()) {
|
|
||||||
if (entry.name === slashCommand.name) {
|
|
||||||
hasCommand = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
await entry.delete();
|
|
||||||
}
|
|
||||||
if (hasCommand) return;
|
|
||||||
await appCommands.create({
|
|
||||||
name: slashCommand.name,
|
|
||||||
description: "Ask Clawdis a question",
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: "prompt",
|
|
||||||
description: "What should Clawdis help with?",
|
|
||||||
type: ApplicationCommandOptionType.String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
runtime.log?.(`registered discord slash command /${slashCommand.name}`);
|
|
||||||
} catch (err) {
|
|
||||||
const status = (err as { status?: number | string })?.status;
|
|
||||||
const code = (err as { code?: number | string })?.code;
|
|
||||||
const message = String(err);
|
|
||||||
const isRateLimit =
|
|
||||||
status === 429 ||
|
|
||||||
code === 429 ||
|
|
||||||
/rate ?limit/i.test(message);
|
|
||||||
const text = `discord slash command setup failed: ${message}`;
|
|
||||||
if (isRateLimit) {
|
|
||||||
logVerbose(text);
|
|
||||||
runtime.error?.(warn(text));
|
|
||||||
} else {
|
|
||||||
runtime.error?.(danger(text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function findFirstStringOption(
|
function findFirstStringOption(
|
||||||
options: readonly CommandInteractionOption[],
|
options: readonly CommandInteractionOption[],
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
|
|||||||
Reference in New Issue
Block a user