name: AI Issue Moderator

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

permissions:
  issues: write
  contents: read
  models: read

jobs:
  moderate:
    runs-on: ubuntu-latest
    steps:
      - name: Check Content
        uses: actions/ai-inference@v1
        id: check
        with:
          model: 'gpt-4o-mini'
          system-prompt: |
            你是一个内容审查助手。
            检查内容是否包含：
            1. 垃圾信息或广告
            2. 恶意或攻击性内容
            3. 与项目完全无关的内容

            只返回 "SPAM" 或 "OK"，不要其他内容。
          prompt: |
            标题：${{ github.event.issue.title || github.event.comment.body }}

            内容：
            ${{ github.event.issue.body || github.event.comment.body }}

      - name: Mark as Spam
        if: contains(steps.check.outputs.response, 'SPAM')
        uses: actions/github-script@v7
        with:
          script: |
            // 添加 spam 标签
            github.rest.issues.addLabels({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              labels: ['spam']
            });

            // 添加评论
            github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: '🤖 这个内容被 AI 检测为可能的垃圾内容。如果这是误判，请联系维护者。\n\n🤖 This content was detected as potential spam by AI. If this is a false positive, please contact the maintainers.'
            });
