Paint [C6] #FF00FF #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Paint Pixel | |
| on: | |
| issues: | |
| types: [opened] | |
| permissions: | |
| contents: write | |
| issues: write | |
| jobs: | |
| paint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install jq | |
| run: sudo apt-get install jq | |
| - name: Process Issue | |
| env: | |
| ISSUE_BODY: ${{ github.event.issue.title }} | |
| USERNAME: ${{ github.event.issue.user.login }} | |
| ISSUE_NUMBER: ${{ github.event.issue.number }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| NOW=$(date +%s) | |
| echo "Processing: $ISSUE_BODY" | |
| # Validate format | |
| if [[ ! "$ISSUE_BODY" =~ ^Paint\ \[([A-H][1-8])\]\ \#([A-Fa-f0-9]{6})$ ]]; then | |
| gh issue comment $ISSUE_NUMBER --body "❌ Invalid format. Use: Paint [A5] #FF5733" | |
| gh issue edit $ISSUE_NUMBER --add-label "Invalid" | |
| exit 0 | |
| fi | |
| COORD=$(echo "$ISSUE_BODY" | sed -E 's/^Paint \[([A-H][1-8])\] .*/\1/') | |
| COLOR=$(echo "$ISSUE_BODY" | sed -E 's/^Paint \[[A-H][1-8]\] (#.*)/\1/') | |
| # Load state | |
| STATE=$(cat data/state.json) | |
| USER_COOLDOWN=$(echo $STATE | jq -r ".users[\"$USERNAME\"] // 0") | |
| TILE_LOCK=$(echo "$STATE" | jq -r ".tiles[\"$COORD\"]?.lock_until // 0") | |
| # Check user cooldown | |
| if [ "$NOW" -lt "$USER_COOLDOWN" ]; then | |
| SECONDS_LEFT=$((USER_COOLDOWN - NOW)) | |
| HOURS_LEFT=$(( (SECONDS_LEFT + 3599) / 3600 )) | |
| gh issue comment $ISSUE_NUMBER --body "⏳ You may paint again in approximately ${HOURS_LEFT}h." | |
| exit 0 | |
| fi | |
| # Check tile lock | |
| if [ "$NOW" -lt "$TILE_LOCK" ]; then | |
| gh issue comment $ISSUE_NUMBER --body "🔒 Tile $COORD is locked for another hour." | |
| exit 0 | |
| fi | |
| # Update SVG | |
| sed -i "/id=\"$COORD\"/s/fill=\"#[A-Fa-f0-9]\{6\}\"/fill=\"$COLOR\"/" map.svg | |
| grep "$COORD" map.svg | |
| # Update state | |
| NEW_USER_COOLDOWN=$((NOW + 86400)) | |
| NEW_TILE_LOCK=$((NOW + 3600)) | |
| UPDATED_STATE=$(echo $STATE | jq \ | |
| --arg user "$USERNAME" \ | |
| --arg coord "$COORD" \ | |
| --arg color "$COLOR" \ | |
| --argjson now $NOW \ | |
| --argjson user_cd $NEW_USER_COOLDOWN \ | |
| --argjson tile_lock $NEW_TILE_LOCK \ | |
| ' | |
| .users[$user] = $user_cd | | |
| .tiles[$coord].last_user = $user | | |
| .tiles[$coord].last_painted = $now | | |
| .tiles[$coord].paint_count = (.tiles[$coord].paint_count // 0) + 1 | | |
| .tiles[$coord].lock_until = $tile_lock | | |
| .history += [{ | |
| user: $user, | |
| coord: $coord, | |
| color: $color, | |
| timestamp: $now | |
| }] | |
| ') | |
| echo "$UPDATED_STATE" > data/state.json | |
| git config user.name "commit-art-bot" | |
| git config user.email "actions@github.com" | |
| git add map.svg data/state.json | |
| git commit -m "🎨 $USERNAME painted $COORD $COLOR" | |
| git push | |
| gh issue comment $ISSUE_NUMBER --body "✅ Painted $COORD $COLOR" | |
| gh issue edit $ISSUE_NUMBER --add-label "Completed" |