on:
  release:
    types: [published]

jobs:
  github-releases-to-discord:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Extract Release Version
        id: extract_version
        run: |
          # Extract version from the release tag or name
          VERSION=$(echo "${{ github.ref }}" | sed 's/refs\/tags\///')
          echo "VERSION=${VERSION}" >> $GITHUB_ENV

      - name: Set Content Based on Version
        id: set_content
        run: |
          # Set default content
          CONTENT="<@&1251712605001875537> RELEASE VERSION ${VERSION} IS OUT! Check it out!"

          # Check if the version number follows a specific pattern and adjust content
          if [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+$ ]]; then
            MAJOR_MINOR_VERSION=$(echo "${VERSION}" | cut -d '.' -f1,2)
            if [[ "${MAJOR_MINOR_VERSION}" == "1.0" ]]; then
              CONTENT="<@&1251712605001875537> NEW RELEASE YIPPEE <:yippee:1253914424293593200> (press the ver number to go to the release)"
            elif [[ "${MAJOR_MINOR_VERSION}" == "2.0" ]]; then
              CONTENT="<@&1251712605001875537> BIG UPDATE ALERT <:yippee:1253914424293593200> (check out the details!)"
            else
              CONTENT="<@&1251712605001875537> RELEASE VERSION ${VERSION} IS OUT! Check it out! (press the ver number to go to the release)"
            fi
          fi
          echo "CONTENT=${CONTENT}" >> $GITHUB_ENV

      - name: Github Releases To Discord
        uses: SethCohen/github-releases-to-discord@v1.13.1
        with:
          webhook_url: ${{ secrets.WEBHOOK_URL }}
          color: "2105893"
          username: "Stossy11"
          avatar_url: "https://cdn.discordapp.com/icons/1112269891903422535/ed95087179918095a41779afe33d126c.webp?size=240"
          content: ${{ env.CONTENT }}
          footer_title: "Changelog"
          footer_icon_url: "https://cdn.discordapp.com/icons/1112269891903422535/ed95087179918095a41779afe33d126c.webp?size=240"
          footer_timestamp: true

