SuperAPI AI 工具集

configure-discord

办公与效率

查看项目

更新于 10-16 04:23

技能介绍

用途

configure-discord 用于为 OMX(oh-my-codex)配置 Discord 通知,使 OMX 能够在会话结束、需要用户输入或完成后台任务时向用户发送 Discord 消息提醒。该技能以交互式、自然语言的方式引导用户完成设置,最终将配置写入 ~/.codex/.omx-config.json。

主要能力

  • 检测已有配置:读取 ~/.codex/.omx-config.json,检查是否已存在 discord 或 discord-bot 配置,并展示当前配置内容,询问用户是否更新或重新配置。
  • 选择通知方式:支持 Webhook(推荐,无需机器人,直接粘贴 URL)和 Bot API(使用机器人 Token + 频道 ID,更灵活但需要创建机器人应用)两种方式。
  • 配置提及(ping):可选择提及某个用户(格式 <@USER_ID>)、提及某个角色(格式 <@&ROLE_ID>)或不提及任何人。
  • 配置触发事件:支持多选,包括会话结束(推荐)、需要输入、会话开始、会话持续;默认选中会话结束与需要输入。
  • 可选自定义机器人显示名称:默认 OMX,也可选择 Codex CLI 或自定义名称。
  • 写入配置:读取现有配置并合并新的 Discord 设置,使用 jq 写回 ~/.codex/.omx-config.json。
  • 测试配置:写入后可选择发送测试通知,通过 curl 请求 Webhook 验证是否成功,失败时协助排查 URL、权限等问题。
  • 环境变量替代:用户可跳过向导,直接在 shell 配置文件中设置环境变量,通知系统会自动检测,无需 .omx-config.json。

使用方式

该技能通过 AskUserQuestion 逐步提问完成配置,主要流程为:检测现有配置 → 选择 Discord 方式 → 填写 Webhook URL 或 Bot Token 与频道 ID → 配置提及对象 → 选择触发事件 → 可选自定义用户名 → 写入配置 → 可选测试 → 显示最终配置摘要。

Webhook URL 需以 https://discord.com/api/webhooks/ 或 https://discordapp.com/api/webhooks/ 开头,否则会提示格式错误并要求重新输入。

配置写入示例(Webhook 方式):

CONFIG_FILE="$HOME/.codex/.omx-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"

echo "$EXISTING" | jq \
  --arg url "$WEBHOOK_URL" \
  --arg mention "$MENTION" \
  --arg username "$USERNAME" \
  '.notifications = (.notifications // {enabled: true}) |
   .notifications.enabled = true |
   .notifications.discord = {
     enabled: true,
     webhookUrl: $url,
     mention: (if $mention == "" then null else $mention end),
     username: (if $username == "" then null else $username end)
   }' > "$CONFIG_FILE"

Bot API 方式写入示例:

echo "$EXISTING" | jq \
  --arg token "$BOT_TOKEN" \
  --arg channel "$CHANNEL_ID" \
  --arg mention "$MENTION" \
  '.notifications = (.notifications // {enabled: true}) |
   .notifications.enabled = true |
   .notifications["discord-bot"] = {
     enabled: true,
     botToken: $token,
     channelId: $channel,
     mention: (if $mention == "" then null else $mention end)
   }' > "$CONFIG_FILE"

测试通知示例:

curl -s -o /dev/null -w "%{http_code}" \
  -H "Content-Type: application/json" \
  -d "{\"content\": \"${MENTION:+$MENTION\\n}OMX test notification - Discord is configured!\"}" \
  "$WEBHOOK_URL"

环境变量替代方式:

Webhook 方式:

export OMX_DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
export OMX_DISCORD_MENTION="<@1465264645320474637>"  # optional

Bot API 方式:

export OMX_DISCORD_NOTIFIER_BOT_TOKEN="your-bot-token"
export OMX_DISCORD_NOTIFIER_CHANNEL="your-channel-id"
export OMX_DISCORD_MENTION="<@1465264645320474637>"  # optional

重新配置可再次运行 /configure-discord;配置 Telegram 可使用 /configure-telegram。

适用场景

  • 希望 Codex 会话结束时收到 Discord 提醒。
  • 长时间运行的任务需要用户输入时,通过 Discord 及时获知。
  • 需要监控会话开始或持续状态。
  • 团队协作中通过提及用户或角色确保关键通知被看到。

限制

  • 需要用户自行创建 Discord Webhook 或机器人应用,并获取相应 URL、Token、频道 ID。
  • 提及用户或角色需要开启 Discord 开发者模式以复制 ID。
  • 配置依赖 jq 命令进行 JSON 合并与写入。
  • 资料未提供该技能的具体收费、价格或平台支持范围信息。