docs(discord-control): add runnable examples and smoke script
This commit is contained in:
5
Makefile
5
Makefile
@@ -1,4 +1,4 @@
|
||||
.PHONY: check check-rules test-api up down smoke render-config package-plugin discord-control-up
|
||||
.PHONY: check check-rules test-api up down smoke render-config package-plugin discord-control-up smoke-discord-control
|
||||
|
||||
check:
|
||||
cd plugin && npm run check
|
||||
@@ -26,3 +26,6 @@ package-plugin:
|
||||
|
||||
discord-control-up:
|
||||
cd discord-control-api && node server.mjs
|
||||
|
||||
smoke-discord-control:
|
||||
./scripts/smoke-discord-control.sh
|
||||
|
||||
@@ -22,7 +22,7 @@ The no-reply provider returns `NO_REPLY` for any input.
|
||||
- `discord-control-api/` — Discord 管理扩展 API(私密频道 + 成员列表)
|
||||
- `docs/` — rollout, integration, run-mode notes
|
||||
- `scripts/` — smoke/dev/helper checks
|
||||
- `Makefile` — common dev commands (`make check`, `make check-rules`, `make test-api`, `make up`)
|
||||
- `Makefile` — common dev commands (`make check`, `make check-rules`, `make test-api`, `make smoke-discord-control`, `make up`)
|
||||
- `CHANGELOG.md` — milestone summary
|
||||
|
||||
## Quick start (no Docker)
|
||||
|
||||
@@ -119,6 +119,18 @@ curl -sS http://127.0.0.1:8790/health
|
||||
|
||||
---
|
||||
|
||||
## Curl examples
|
||||
|
||||
示例文件:`docs/EXAMPLES.discord-control.json`
|
||||
|
||||
快速检查脚本:
|
||||
|
||||
```bash
|
||||
./scripts/smoke-discord-control.sh
|
||||
# with env
|
||||
# AUTH_TOKEN=xxx CALLER_ID=agent-main GUILD_ID=123 CHANNEL_ID=456 ./scripts/smoke-discord-control.sh
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
鉴权与内置风格对齐(简化版):
|
||||
|
||||
68
docs/EXAMPLES.discord-control.json
Normal file
68
docs/EXAMPLES.discord-control.json
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"channel-private-create": {
|
||||
"action": "channel-private-create",
|
||||
"guildId": "123456789012345678",
|
||||
"name": "ops-private",
|
||||
"type": 0,
|
||||
"parentId": "234567890123456789",
|
||||
"topic": "ops only",
|
||||
"position": 3,
|
||||
"nsfw": false,
|
||||
"allowedUserIds": [
|
||||
"345678901234567890",
|
||||
"456789012345678901"
|
||||
],
|
||||
"allowedRoleIds": [
|
||||
"567890123456789012"
|
||||
],
|
||||
"allowMask": "67648",
|
||||
"denyEveryoneMask": "1024",
|
||||
"dryRun": true
|
||||
},
|
||||
"channel-private-update-merge": {
|
||||
"action": "channel-private-update",
|
||||
"guildId": "123456789012345678",
|
||||
"channelId": "678901234567890123",
|
||||
"mode": "merge",
|
||||
"addUserIds": [
|
||||
"345678901234567890"
|
||||
],
|
||||
"addRoleIds": [
|
||||
"567890123456789012"
|
||||
],
|
||||
"removeTargetIds": [
|
||||
"456789012345678901"
|
||||
],
|
||||
"allowMask": "67648",
|
||||
"denyMask": "0",
|
||||
"dryRun": true
|
||||
},
|
||||
"channel-private-update-replace": {
|
||||
"action": "channel-private-update",
|
||||
"guildId": "123456789012345678",
|
||||
"channelId": "678901234567890123",
|
||||
"mode": "replace",
|
||||
"addUserIds": [
|
||||
"345678901234567890"
|
||||
],
|
||||
"addRoleIds": [
|
||||
"567890123456789012"
|
||||
],
|
||||
"allowMask": "67648",
|
||||
"denyMask": "0",
|
||||
"dryRun": true
|
||||
},
|
||||
"member-list": {
|
||||
"action": "member-list",
|
||||
"guildId": "123456789012345678",
|
||||
"limit": 100,
|
||||
"after": "0",
|
||||
"fields": [
|
||||
"user.id",
|
||||
"user.username",
|
||||
"nick",
|
||||
"roles",
|
||||
"joined_at"
|
||||
]
|
||||
}
|
||||
}
|
||||
52
scripts/smoke-discord-control.sh
Executable file
52
scripts/smoke-discord-control.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${BASE_URL:-http://127.0.0.1:8790}"
|
||||
AUTH_TOKEN="${AUTH_TOKEN:-}"
|
||||
CALLER_ID="${CALLER_ID:-}"
|
||||
|
||||
AUTH_HEADER=()
|
||||
if [[ -n "$AUTH_TOKEN" ]]; then
|
||||
AUTH_HEADER=(-H "Authorization: Bearer ${AUTH_TOKEN}")
|
||||
fi
|
||||
|
||||
CALLER_HEADER=()
|
||||
if [[ -n "$CALLER_ID" ]]; then
|
||||
CALLER_HEADER=(-H "X-OpenClaw-Caller-Id: ${CALLER_ID}")
|
||||
fi
|
||||
|
||||
echo "[1] health"
|
||||
curl -sS "${BASE_URL}/health" | sed -n '1,20p'
|
||||
|
||||
if [[ -z "${GUILD_ID:-}" ]]; then
|
||||
echo "skip action checks: set GUILD_ID (and optional CHANNEL_ID) to run dryRun actions"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[2] dry-run private create"
|
||||
curl -sS -X POST "${BASE_URL}/v1/discord/action" \
|
||||
-H 'Content-Type: application/json' \
|
||||
"${AUTH_HEADER[@]}" \
|
||||
"${CALLER_HEADER[@]}" \
|
||||
-d "{\"action\":\"channel-private-create\",\"guildId\":\"${GUILD_ID}\",\"name\":\"wg-dryrun\",\"dryRun\":true}" \
|
||||
| sed -n '1,80p'
|
||||
|
||||
if [[ -n "${CHANNEL_ID:-}" ]]; then
|
||||
echo "[3] dry-run private update"
|
||||
curl -sS -X POST "${BASE_URL}/v1/discord/action" \
|
||||
-H 'Content-Type: application/json' \
|
||||
"${AUTH_HEADER[@]}" \
|
||||
"${CALLER_HEADER[@]}" \
|
||||
-d "{\"action\":\"channel-private-update\",\"guildId\":\"${GUILD_ID}\",\"channelId\":\"${CHANNEL_ID}\",\"mode\":\"merge\",\"dryRun\":true}" \
|
||||
| sed -n '1,100p'
|
||||
fi
|
||||
|
||||
echo "[4] member-list (limit=1)"
|
||||
curl -sS -X POST "${BASE_URL}/v1/discord/action" \
|
||||
-H 'Content-Type: application/json' \
|
||||
"${AUTH_HEADER[@]}" \
|
||||
"${CALLER_HEADER[@]}" \
|
||||
-d "{\"action\":\"member-list\",\"guildId\":\"${GUILD_ID}\",\"limit\":1,\"fields\":[\"user.id\",\"user.username\"]}" \
|
||||
| sed -n '1,120p'
|
||||
|
||||
echo "smoke-discord-control: done"
|
||||
Reference in New Issue
Block a user