generated from nhcarrigan/template
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 85a982c03e | |||
| a9c7ebf74d | |||
|
0b19d91444
|
|||
|
74bccd903d
|
|||
|
402acffb5c
|
|||
| a8a58faf3c | |||
| 579dfe96f5 | |||
| 47dd385f05 | |||
| 2851693a70 | |||
| 6ee8189edd | |||
| aaa710eba4 | |||
|
e6112f57cb
|
|||
|
72b7571b92
|
|||
| 6e35d49a34 | |||
|
9c53c22130
|
|||
|
9d9d0809d7
|
|||
|
53274ec38c
|
|||
| 9ada4b9cbe | |||
| 34d71c73aa | |||
| 532461202a | |||
| 50e46368ed |
+14
-5
@@ -8,22 +8,31 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
ci:
|
||||||
name: Lint and Test
|
name: CI
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Source Files
|
- name: Checkout Source Files
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Use Node.js v22
|
- name: Use Node.js v24
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 22
|
node-version: 24
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v2
|
uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
|
- name: Ensure Dependencies are Pinned
|
||||||
|
uses: naomi-lgbt/dependency-pin-check@main
|
||||||
|
with:
|
||||||
|
language: javascript
|
||||||
|
dev-dependencies: true
|
||||||
|
peer-dependencies: true
|
||||||
|
optional-dependencies: true
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
name: Security Scan and Upload
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * 1'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security-audit:
|
||||||
|
name: Security & DefectDojo Upload
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# --- AUTO-SETUP PROJECT ---
|
||||||
|
- name: Ensure DefectDojo Product Exists
|
||||||
|
env:
|
||||||
|
DD_URL: ${{ secrets.DD_URL }}
|
||||||
|
DD_TOKEN: ${{ secrets.DD_TOKEN }}
|
||||||
|
PRODUCT_NAME: ${{ github.repository }}
|
||||||
|
PRODUCT_TYPE_ID: 1
|
||||||
|
run: |
|
||||||
|
sudo apt-get install jq -y > /dev/null
|
||||||
|
|
||||||
|
echo "Checking connection to $DD_URL..."
|
||||||
|
|
||||||
|
# Check if product exists - capture HTTP code to debug connection issues
|
||||||
|
RESPONSE=$(curl --write-out "%{http_code}" --silent --output /tmp/response.json \
|
||||||
|
-H "Authorization: Token $DD_TOKEN" \
|
||||||
|
"$DD_URL/api/v2/products/?name=$PRODUCT_NAME")
|
||||||
|
|
||||||
|
# If response is not 200, print error
|
||||||
|
if [ "$RESPONSE" != "200" ]; then
|
||||||
|
echo "::error::Failed to query DefectDojo. HTTP Code: $RESPONSE"
|
||||||
|
cat /tmp/response.json
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
COUNT=$(cat /tmp/response.json | jq -r '.count')
|
||||||
|
|
||||||
|
if [ "$COUNT" = "0" ]; then
|
||||||
|
echo "Creating product '$PRODUCT_NAME'..."
|
||||||
|
curl -s -X POST "$DD_URL/api/v2/products/" \
|
||||||
|
-H "Authorization: Token $DD_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{ "name": "'"$PRODUCT_NAME"'", "description": "Auto-created by Gitea Actions", "prod_type": '$PRODUCT_TYPE_ID' }'
|
||||||
|
else
|
||||||
|
echo "Product '$PRODUCT_NAME' already exists."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- 1. TRIVY (Dependencies & Misconfig) ---
|
||||||
|
- name: Install Trivy
|
||||||
|
run: |
|
||||||
|
sudo apt-get install wget apt-transport-https gnupg lsb-release -y
|
||||||
|
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
|
||||||
|
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
|
||||||
|
sudo apt-get update && sudo apt-get install trivy -y
|
||||||
|
|
||||||
|
- name: Run Trivy (FS Scan)
|
||||||
|
run: |
|
||||||
|
trivy fs . --scanners vuln,misconfig --format json --output trivy-results.json --exit-code 0
|
||||||
|
|
||||||
|
- name: Upload Trivy to DefectDojo
|
||||||
|
env:
|
||||||
|
DD_URL: ${{ secrets.DD_URL }}
|
||||||
|
DD_TOKEN: ${{ secrets.DD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
echo "Uploading Trivy results..."
|
||||||
|
# Generate today's date in YYYY-MM-DD format
|
||||||
|
TODAY=$(date +%Y-%m-%d)
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl --write-out "%{http_code}" --output response.txt --silent -X POST "$DD_URL/api/v2/import-scan/" \
|
||||||
|
-H "Authorization: Token $DD_TOKEN" \
|
||||||
|
-F "active=true" \
|
||||||
|
-F "verified=true" \
|
||||||
|
-F "scan_type=Trivy Scan" \
|
||||||
|
-F "engagement_name=CI/CD Pipeline" \
|
||||||
|
-F "product_name=${{ github.repository }}" \
|
||||||
|
-F "scan_date=$TODAY" \
|
||||||
|
-F "auto_create_context=true" \
|
||||||
|
-F "file=@trivy-results.json")
|
||||||
|
|
||||||
|
if [[ "$HTTP_CODE" != "200" && "$HTTP_CODE" != "201" ]]; then
|
||||||
|
echo "::error::Upload Failed with HTTP $HTTP_CODE"
|
||||||
|
echo "--- SERVER RESPONSE ---"
|
||||||
|
cat response.txt
|
||||||
|
echo "-----------------------"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Upload Success!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- 2. GITLEAKS (Secrets) ---
|
||||||
|
- name: Install Gitleaks
|
||||||
|
run: |
|
||||||
|
wget -qO gitleaks.tar.gz https://github.com/gitleaks/gitleaks/releases/download/v8.18.0/gitleaks_8.18.0_linux_x64.tar.gz
|
||||||
|
tar -xzf gitleaks.tar.gz
|
||||||
|
sudo mv gitleaks /usr/local/bin/ && chmod +x /usr/local/bin/gitleaks
|
||||||
|
|
||||||
|
- name: Run Gitleaks
|
||||||
|
run: gitleaks detect --source . -v --report-path gitleaks-results.json --report-format json --no-git || true
|
||||||
|
|
||||||
|
- name: Upload Gitleaks to DefectDojo
|
||||||
|
env:
|
||||||
|
DD_URL: ${{ secrets.DD_URL }}
|
||||||
|
DD_TOKEN: ${{ secrets.DD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
echo "Uploading Gitleaks results..."
|
||||||
|
TODAY=$(date +%Y-%m-%d)
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl --write-out "%{http_code}" --output response.txt --silent -X POST "$DD_URL/api/v2/import-scan/" \
|
||||||
|
-H "Authorization: Token $DD_TOKEN" \
|
||||||
|
-F "active=true" \
|
||||||
|
-F "verified=true" \
|
||||||
|
-F "scan_type=Gitleaks Scan" \
|
||||||
|
-F "engagement_name=CI/CD Pipeline" \
|
||||||
|
-F "product_name=${{ github.repository }}" \
|
||||||
|
-F "scan_date=$TODAY" \
|
||||||
|
-F "auto_create_context=true" \
|
||||||
|
-F "file=@gitleaks-results.json")
|
||||||
|
|
||||||
|
if [[ "$HTTP_CODE" != "200" && "$HTTP_CODE" != "201" ]]; then
|
||||||
|
echo "::error::Upload Failed with HTTP $HTTP_CODE"
|
||||||
|
echo "--- SERVER RESPONSE ---"
|
||||||
|
cat response.txt
|
||||||
|
echo "-----------------------"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Upload Success!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- 3. SEMGREP (SAST) ---
|
||||||
|
- name: Install Semgrep (via pipx)
|
||||||
|
run: |
|
||||||
|
sudo apt-get install pipx -y
|
||||||
|
pipx install semgrep
|
||||||
|
# Add pipx binary path to GITHUB_PATH so next steps can see 'semgrep'
|
||||||
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Run Semgrep
|
||||||
|
run: semgrep scan --config=p/security-audit --config=p/owasp-top-ten --json --output semgrep-results.json . || true
|
||||||
|
|
||||||
|
- name: Upload Semgrep to DefectDojo
|
||||||
|
env:
|
||||||
|
DD_URL: ${{ secrets.DD_URL }}
|
||||||
|
DD_TOKEN: ${{ secrets.DD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
echo "Uploading Semgrep results..."
|
||||||
|
TODAY=$(date +%Y-%m-%d)
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl --write-out "%{http_code}" --output response.txt --silent -X POST "$DD_URL/api/v2/import-scan/" \
|
||||||
|
-H "Authorization: Token $DD_TOKEN" \
|
||||||
|
-F "active=true" \
|
||||||
|
-F "verified=true" \
|
||||||
|
-F "scan_type=Semgrep JSON Report" \
|
||||||
|
-F "engagement_name=CI/CD Pipeline" \
|
||||||
|
-F "product_name=${{ github.repository }}" \
|
||||||
|
-F "scan_date=$TODAY" \
|
||||||
|
-F "auto_create_context=true" \
|
||||||
|
-F "file=@semgrep-results.json")
|
||||||
|
|
||||||
|
if [[ "$HTTP_CODE" != "200" && "$HTTP_CODE" != "201" ]]; then
|
||||||
|
echo "::error::Upload Failed with HTTP $HTTP_CODE"
|
||||||
|
echo "--- SERVER RESPONSE ---"
|
||||||
|
cat response.txt
|
||||||
|
echo "-----------------------"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Upload Success!"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Package Manager Configuration
|
||||||
|
# Force pnpm usage - breaks npm/yarn intentionally
|
||||||
|
node-linker=pnpm
|
||||||
|
|
||||||
|
# Security: Disable all lifecycle scripts
|
||||||
|
ignore-scripts=true
|
||||||
|
enable-pre-post-scripts=false
|
||||||
|
|
||||||
|
# Security: Require packages to be 10+ days old before installation
|
||||||
|
minimum-release-age=14400
|
||||||
|
|
||||||
|
# Security: Verify package integrity hashes
|
||||||
|
verify-store-integrity=true
|
||||||
|
|
||||||
|
# Security: Enforce strict trust policies
|
||||||
|
trust-policy=strict
|
||||||
|
|
||||||
|
# Security: Strict peer dependency resolution
|
||||||
|
strict-peer-dependencies=true
|
||||||
|
|
||||||
|
# Performance: Use symlinks for node_modules
|
||||||
|
symlink=true
|
||||||
|
|
||||||
|
# Lockfile: Ensure lockfile is not modified during install
|
||||||
|
frozen-lockfile=false
|
||||||
@@ -18,7 +18,7 @@ This page is currently deployed. [View the live website.]
|
|||||||
|
|
||||||
## Feedback and Bugs
|
## Feedback and Bugs
|
||||||
|
|
||||||
If you have feedback or a bug report, please feel free to open a GitHub issue!
|
If you have feedback or a bug report, please [log a ticket on our forum](https://support.nhcarrigan.com).
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@
|
|||||||
"@nhcarrigan/discord-analytics": "0.0.6",
|
"@nhcarrigan/discord-analytics": "0.0.6",
|
||||||
"@nhcarrigan/logger": "1.1.1",
|
"@nhcarrigan/logger": "1.1.1",
|
||||||
"@retroachievements/api": "2.6.0",
|
"@retroachievements/api": "2.6.0",
|
||||||
"discord.js": "14.22.0",
|
"discord.js": "14.25.1",
|
||||||
"fastify": "5.5.0",
|
"fastify": "5.5.0",
|
||||||
"node-schedule": "2.1.1",
|
"node-schedule": "2.1.1",
|
||||||
"octokit": "5.0.3",
|
"octokit": "5.0.3",
|
||||||
|
|||||||
Generated
+34
-32
@@ -10,7 +10,7 @@ importers:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@nhcarrigan/discord-analytics':
|
'@nhcarrigan/discord-analytics':
|
||||||
specifier: 0.0.6
|
specifier: 0.0.6
|
||||||
version: 0.0.6(@nhcarrigan/logger@1.1.1)(discord.js@14.22.0)
|
version: 0.0.6(@nhcarrigan/logger@1.1.1)(discord.js@14.25.1)
|
||||||
'@nhcarrigan/logger':
|
'@nhcarrigan/logger':
|
||||||
specifier: 1.1.1
|
specifier: 1.1.1
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
@@ -18,8 +18,8 @@ importers:
|
|||||||
specifier: 2.6.0
|
specifier: 2.6.0
|
||||||
version: 2.6.0
|
version: 2.6.0
|
||||||
discord.js:
|
discord.js:
|
||||||
specifier: 14.22.0
|
specifier: 14.25.1
|
||||||
version: 14.22.0
|
version: 14.25.1
|
||||||
fastify:
|
fastify:
|
||||||
specifier: 5.5.0
|
specifier: 5.5.0
|
||||||
version: 5.5.0
|
version: 5.5.0
|
||||||
@@ -62,8 +62,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==}
|
resolution: {integrity: sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
|
|
||||||
'@discordjs/builders@1.11.3':
|
'@discordjs/builders@1.13.1':
|
||||||
resolution: {integrity: sha512-p3kf5eV49CJiRTfhtutUCeivSyQ/l2JlKodW1ZquRwwvlOWmG9+6jFShX6x8rUiYhnP6wKI96rgN/SXMy5e5aw==}
|
resolution: {integrity: sha512-cOU0UDHc3lp/5nKByDxkmRiNZBpdp0kx55aarbiAfakfKJHlxv/yFW1zmIqCAmwH5CRlrH9iMFKJMpvW4DPB+w==}
|
||||||
engines: {node: '>=16.11.0'}
|
engines: {node: '>=16.11.0'}
|
||||||
|
|
||||||
'@discordjs/collection@1.5.3':
|
'@discordjs/collection@1.5.3':
|
||||||
@@ -74,16 +74,16 @@ packages:
|
|||||||
resolution: {integrity: sha512-LiSusze9Tc7qF03sLCujF5iZp7K+vRNEDBZ86FT9aQAv3vxMLihUvKvpsCWiQ2DJq1tVckopKm1rxomgNUc9hg==}
|
resolution: {integrity: sha512-LiSusze9Tc7qF03sLCujF5iZp7K+vRNEDBZ86FT9aQAv3vxMLihUvKvpsCWiQ2DJq1tVckopKm1rxomgNUc9hg==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
'@discordjs/formatters@0.6.1':
|
'@discordjs/formatters@0.6.2':
|
||||||
resolution: {integrity: sha512-5cnX+tASiPCqCWtFcFslxBVUaCetB0thvM/JyavhbXInP1HJIEU+Qv/zMrnuwSsX3yWH2lVXNJZeDK3EiP4HHg==}
|
resolution: {integrity: sha512-y4UPwWhH6vChKRkGdMB4odasUbHOUwy7KL+OVwF86PvT6QVOwElx+TiI1/6kcmcEe+g5YRXJFiXSXUdabqZOvQ==}
|
||||||
engines: {node: '>=16.11.0'}
|
engines: {node: '>=16.11.0'}
|
||||||
|
|
||||||
'@discordjs/rest@2.6.0':
|
'@discordjs/rest@2.6.0':
|
||||||
resolution: {integrity: sha512-RDYrhmpB7mTvmCKcpj+pc5k7POKszS4E2O9TYc+U+Y4iaCP+r910QdO43qmpOja8LRr1RJ0b3U+CqVsnPqzf4w==}
|
resolution: {integrity: sha512-RDYrhmpB7mTvmCKcpj+pc5k7POKszS4E2O9TYc+U+Y4iaCP+r910QdO43qmpOja8LRr1RJ0b3U+CqVsnPqzf4w==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
'@discordjs/util@1.1.1':
|
'@discordjs/util@1.2.0':
|
||||||
resolution: {integrity: sha512-eddz6UnOBEB1oITPinyrB2Pttej49M9FZQY8NxgEvc3tq6ZICZ19m70RsmzRdDHk80O9NoYN/25AqJl8vPVf/g==}
|
resolution: {integrity: sha512-3LKP7F2+atl9vJFhaBjn4nOaSWahZ/yWjOvA4e5pnXkt2qyXRCHLxoBQy81GFtLGCq7K9lPm9R517M1U+/90Qg==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
'@discordjs/ws@1.2.3':
|
'@discordjs/ws@1.2.3':
|
||||||
@@ -1062,11 +1062,11 @@ packages:
|
|||||||
resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==}
|
resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
discord-api-types@0.38.20:
|
discord-api-types@0.38.38:
|
||||||
resolution: {integrity: sha512-wJSmFFi8eoFL/jIosUQLoXeCv7YK+l7joKmFCsnkx7HWSFt5xScNQdhvILLxC0oU6J5bK0ppR7GZ1d4NJScSNQ==}
|
resolution: {integrity: sha512-7qcM5IeZrfb+LXW07HvoI5L+j4PQeMZXEkSm1htHAHh4Y9JSMXBWjy/r7zmUCOj4F7zNjMcm7IMWr131MT2h0Q==}
|
||||||
|
|
||||||
discord.js@14.22.0:
|
discord.js@14.25.1:
|
||||||
resolution: {integrity: sha512-IDSeDdWSEA4DoOyspekbetcFKkEonJO09cxR+kqQQlTWd5CTm/3Z48I4Te+EL8uxn52s718FZ0rI2dLxRkTpwg==}
|
resolution: {integrity: sha512-2l0gsPOLPs5t6GFZfQZKnL1OJNYFcuC/ETWsW4VtKVD/tg4ICa9x+jb9bkPffkMdRpRpuUaO/fKkHCBeiCKh8g==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
doctrine@2.1.0:
|
doctrine@2.1.0:
|
||||||
@@ -2400,12 +2400,12 @@ snapshots:
|
|||||||
|
|
||||||
'@babel/helper-validator-identifier@7.27.1': {}
|
'@babel/helper-validator-identifier@7.27.1': {}
|
||||||
|
|
||||||
'@discordjs/builders@1.11.3':
|
'@discordjs/builders@1.13.1':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@discordjs/formatters': 0.6.1
|
'@discordjs/formatters': 0.6.2
|
||||||
'@discordjs/util': 1.1.1
|
'@discordjs/util': 1.2.0
|
||||||
'@sapphire/shapeshift': 4.0.0
|
'@sapphire/shapeshift': 4.0.0
|
||||||
discord-api-types: 0.38.20
|
discord-api-types: 0.38.38
|
||||||
fast-deep-equal: 3.1.3
|
fast-deep-equal: 3.1.3
|
||||||
ts-mixer: 6.0.4
|
ts-mixer: 6.0.4
|
||||||
tslib: 2.8.1
|
tslib: 2.8.1
|
||||||
@@ -2414,33 +2414,35 @@ snapshots:
|
|||||||
|
|
||||||
'@discordjs/collection@2.1.1': {}
|
'@discordjs/collection@2.1.1': {}
|
||||||
|
|
||||||
'@discordjs/formatters@0.6.1':
|
'@discordjs/formatters@0.6.2':
|
||||||
dependencies:
|
dependencies:
|
||||||
discord-api-types: 0.38.20
|
discord-api-types: 0.38.38
|
||||||
|
|
||||||
'@discordjs/rest@2.6.0':
|
'@discordjs/rest@2.6.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@discordjs/collection': 2.1.1
|
'@discordjs/collection': 2.1.1
|
||||||
'@discordjs/util': 1.1.1
|
'@discordjs/util': 1.2.0
|
||||||
'@sapphire/async-queue': 1.5.5
|
'@sapphire/async-queue': 1.5.5
|
||||||
'@sapphire/snowflake': 3.5.3
|
'@sapphire/snowflake': 3.5.3
|
||||||
'@vladfrangu/async_event_emitter': 2.4.6
|
'@vladfrangu/async_event_emitter': 2.4.6
|
||||||
discord-api-types: 0.38.20
|
discord-api-types: 0.38.38
|
||||||
magic-bytes.js: 1.12.1
|
magic-bytes.js: 1.12.1
|
||||||
tslib: 2.8.1
|
tslib: 2.8.1
|
||||||
undici: 6.21.3
|
undici: 6.21.3
|
||||||
|
|
||||||
'@discordjs/util@1.1.1': {}
|
'@discordjs/util@1.2.0':
|
||||||
|
dependencies:
|
||||||
|
discord-api-types: 0.38.38
|
||||||
|
|
||||||
'@discordjs/ws@1.2.3':
|
'@discordjs/ws@1.2.3':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@discordjs/collection': 2.1.1
|
'@discordjs/collection': 2.1.1
|
||||||
'@discordjs/rest': 2.6.0
|
'@discordjs/rest': 2.6.0
|
||||||
'@discordjs/util': 1.1.1
|
'@discordjs/util': 1.2.0
|
||||||
'@sapphire/async-queue': 1.5.5
|
'@sapphire/async-queue': 1.5.5
|
||||||
'@types/ws': 8.18.1
|
'@types/ws': 8.18.1
|
||||||
'@vladfrangu/async_event_emitter': 2.4.6
|
'@vladfrangu/async_event_emitter': 2.4.6
|
||||||
discord-api-types: 0.38.20
|
discord-api-types: 0.38.38
|
||||||
tslib: 2.8.1
|
tslib: 2.8.1
|
||||||
ws: 8.18.3
|
ws: 8.18.3
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
@@ -2639,10 +2641,10 @@ snapshots:
|
|||||||
|
|
||||||
'@jridgewell/sourcemap-codec@1.5.5': {}
|
'@jridgewell/sourcemap-codec@1.5.5': {}
|
||||||
|
|
||||||
'@nhcarrigan/discord-analytics@0.0.6(@nhcarrigan/logger@1.1.1)(discord.js@14.22.0)':
|
'@nhcarrigan/discord-analytics@0.0.6(@nhcarrigan/logger@1.1.1)(discord.js@14.25.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nhcarrigan/logger': 1.1.1
|
'@nhcarrigan/logger': 1.1.1
|
||||||
discord.js: 14.22.0
|
discord.js: 14.25.1
|
||||||
node-schedule: 2.1.1
|
node-schedule: 2.1.1
|
||||||
|
|
||||||
'@nhcarrigan/eslint-config@5.2.0(@typescript-eslint/utils@8.40.0(eslint@9.33.0)(typescript@5.9.2))(eslint@9.33.0)(playwright@1.54.2)(react@19.1.1)(typescript@5.9.2)(vitest@3.2.4(@types/node@24.3.0))':
|
'@nhcarrigan/eslint-config@5.2.0(@typescript-eslint/utils@8.40.0(eslint@9.33.0)(typescript@5.9.2))(eslint@9.33.0)(playwright@1.54.2)(react@19.1.1)(typescript@5.9.2)(vitest@3.2.4(@types/node@24.3.0))':
|
||||||
@@ -3443,18 +3445,18 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
path-type: 4.0.0
|
path-type: 4.0.0
|
||||||
|
|
||||||
discord-api-types@0.38.20: {}
|
discord-api-types@0.38.38: {}
|
||||||
|
|
||||||
discord.js@14.22.0:
|
discord.js@14.25.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@discordjs/builders': 1.11.3
|
'@discordjs/builders': 1.13.1
|
||||||
'@discordjs/collection': 1.5.3
|
'@discordjs/collection': 1.5.3
|
||||||
'@discordjs/formatters': 0.6.1
|
'@discordjs/formatters': 0.6.2
|
||||||
'@discordjs/rest': 2.6.0
|
'@discordjs/rest': 2.6.0
|
||||||
'@discordjs/util': 1.1.1
|
'@discordjs/util': 1.2.0
|
||||||
'@discordjs/ws': 1.2.3
|
'@discordjs/ws': 1.2.3
|
||||||
'@sapphire/snowflake': 3.5.3
|
'@sapphire/snowflake': 3.5.3
|
||||||
discord-api-types: 0.38.20
|
discord-api-types: 0.38.38
|
||||||
fast-deep-equal: 3.1.3
|
fast-deep-equal: 3.1.3
|
||||||
lodash.snakecase: 4.1.1
|
lodash.snakecase: 4.1.1
|
||||||
magic-bytes.js: 1.12.1
|
magic-bytes.js: 1.12.1
|
||||||
|
|||||||
+25
-1
@@ -6,15 +6,26 @@
|
|||||||
|
|
||||||
export const ids = {
|
export const ids = {
|
||||||
channels: {
|
channels: {
|
||||||
formSubmissions: "1410435042898874471",
|
accessibilityForum: "1451006622838030509",
|
||||||
|
billingQuestions: "1451010972771811480",
|
||||||
|
bugReports: "1447723804330823763",
|
||||||
|
communityFeedback: "1447726591189975210",
|
||||||
|
featureRequests: "1447726510369931295",
|
||||||
|
formSubmissions: "1448445144071147520",
|
||||||
gaming: "1385797656307175468",
|
gaming: "1385797656307175468",
|
||||||
general: "1385797320389431336",
|
general: "1385797320389431336",
|
||||||
|
legalNotices: "1451009920479793254",
|
||||||
|
marketingProposals: "1451012386327756902",
|
||||||
menteeChat: "1400589073613062204",
|
menteeChat: "1400589073613062204",
|
||||||
mentorshipGoalForum: "1400629118110011526",
|
mentorshipGoalForum: "1400629118110011526",
|
||||||
mentorshipProjectForum: "1400616702265266186",
|
mentorshipProjectForum: "1400616702265266186",
|
||||||
naomiDiscussionForum: "1408154690121633917",
|
naomiDiscussionForum: "1408154690121633917",
|
||||||
news: "1407804798677418198",
|
news: "1407804798677418198",
|
||||||
|
partnershipRequests: "1451009066355654829",
|
||||||
|
policyIdeation: "1417294974046965842",
|
||||||
|
pressInquiries: "1451011543482368163",
|
||||||
resumeReviewForum: "1407807555266154496",
|
resumeReviewForum: "1407807555266154496",
|
||||||
|
technicalSupport: "1451014823440678972",
|
||||||
},
|
},
|
||||||
guilds: {
|
guilds: {
|
||||||
nhcarrigan: "1354624415861833870",
|
nhcarrigan: "1354624415861833870",
|
||||||
@@ -41,6 +52,19 @@ export const ids = {
|
|||||||
member: "1407807699718111292",
|
member: "1407807699718111292",
|
||||||
naomi: "1407807752549699727",
|
naomi: "1407807752549699727",
|
||||||
},
|
},
|
||||||
|
unanswered: {
|
||||||
|
accessibilityForum: "1451008476779122869",
|
||||||
|
billingQuestions: "1451011252301205524",
|
||||||
|
bugReports: "1447726213446500555",
|
||||||
|
communityFeedback: "1447726807595094036",
|
||||||
|
featureRequests: "1447726899919978677",
|
||||||
|
legalNotices: "1451010521687130313",
|
||||||
|
marketingProposals: "1451012664858906720",
|
||||||
|
partnershipRequests: "1451009530459586650",
|
||||||
|
policyIdeation: "1447755602318196828",
|
||||||
|
pressInquiries: "1451012067841544223",
|
||||||
|
technicalSupport: "1451015143646298132",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
amari: "1406431359345496255",
|
amari: "1406431359345496255",
|
||||||
|
|||||||
@@ -3,25 +3,47 @@
|
|||||||
* @license Naomi's Public License
|
* @license Naomi's Public License
|
||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
|
import type { ProgressReminder } from "../interfaces/reminder.js";
|
||||||
|
|
||||||
interface Channel {
|
const nhcarriganMentorshipChannels: Array<ProgressReminder> = [
|
||||||
channelId: string;
|
{
|
||||||
roleId: string;
|
channelId: "1400630073010163792",
|
||||||
name: string;
|
createThread: true,
|
||||||
createThread: boolean;
|
name: "accountability",
|
||||||
}
|
roleId: "1400588705273745550",
|
||||||
|
},
|
||||||
const nhcarriganMentorshipChannels: Array<Channel> = [
|
|
||||||
|
|
||||||
];
|
];
|
||||||
const freeCodeCampSprintChannels: Array<Channel> = [
|
const freeCodeCampSprintChannels: Array<ProgressReminder> = [
|
||||||
|
{
|
||||||
|
channelId: "1424801426160488520",
|
||||||
|
createThread: true,
|
||||||
|
name: "JS Objects/Arrays/Loops",
|
||||||
|
roleId: "1425506225453273224",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
channelId: "1424801426160488520",
|
||||||
|
createThread: true,
|
||||||
|
name: "Python Basics",
|
||||||
|
roleId: "1450187499912695838",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
channelId: "1424801426160488520",
|
||||||
|
createThread: true,
|
||||||
|
name: "Miscellaneous Sprints",
|
||||||
|
roleId: "1450672361291513916",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
channelId: "1442575112384811158",
|
||||||
|
createThread: false,
|
||||||
|
name: "Alpha and Omega",
|
||||||
|
roleId: "1458984977101230196",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The channels to post progress reminders in.
|
* The channels to post progress reminders in.
|
||||||
*/
|
*/
|
||||||
export const progressReminders: Array<Channel> = [
|
export const progressReminders: Array<ProgressReminder> = [
|
||||||
...nhcarriganMentorshipChannels,
|
...nhcarriganMentorshipChannels,
|
||||||
...freeCodeCampSprintChannels,
|
...freeCodeCampSprintChannels,
|
||||||
];
|
];
|
||||||
|
|||||||
+49
-17
@@ -5,23 +5,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
||||||
import { Client,
|
import {
|
||||||
|
Client,
|
||||||
GatewayIntentBits,
|
GatewayIntentBits,
|
||||||
Events,
|
Events,
|
||||||
Partials,
|
Partials,
|
||||||
MessageFlags } from "discord.js";
|
MessageFlags,
|
||||||
|
} from "discord.js";
|
||||||
import { scheduleJob } from "node-schedule";
|
import { scheduleJob } from "node-schedule";
|
||||||
import { App } from "octokit";
|
import { App } from "octokit";
|
||||||
import { ids } from "./config/ids.js";
|
import { ids } from "./config/ids.js";
|
||||||
import { handleMessageCreate } from "./events/handleMessageCreate.js";
|
import { handleMessageCreate } from "./events/handleMessageCreate.js";
|
||||||
import { cacheData } from "./modules/cacheData.js";
|
import { cacheData } from "./modules/cacheData.js";
|
||||||
import { checkRetroAchievements } from "./modules/checkAchievements.js";
|
import { checkRetroAchievements } from "./modules/checkAchievements.js";
|
||||||
|
import { getForumTagId } from "./modules/getForumTagId.js";
|
||||||
import { logMenteeJoin } from "./modules/logMenteeJoin.js";
|
import { logMenteeJoin } from "./modules/logMenteeJoin.js";
|
||||||
import { logMenteeLeave } from "./modules/logMenteeLeave.js";
|
import { logMenteeLeave } from "./modules/logMenteeLeave.js";
|
||||||
import {
|
import { postFreeCodeCampNews, postHackerNews } from "./modules/postNews.js";
|
||||||
postFreeCodeCampNews,
|
|
||||||
postHackerNews,
|
|
||||||
} from "./modules/postNews.js";
|
|
||||||
import { postProgressReminders } from "./modules/postProgressReminders.js";
|
import { postProgressReminders } from "./modules/postProgressReminders.js";
|
||||||
import { processMentorshipRole } from "./modules/processMentorshipRole.js";
|
import { processMentorshipRole } from "./modules/processMentorshipRole.js";
|
||||||
import { processUserGuildTag } from "./modules/processUserGuildTag.js";
|
import { processUserGuildTag } from "./modules/processUserGuildTag.js";
|
||||||
@@ -30,8 +30,10 @@ import { instantiateServer } from "./server/serve.js";
|
|||||||
import { logger } from "./utils/logger.js";
|
import { logger } from "./utils/logger.js";
|
||||||
import type { Amari } from "./interfaces/amari.js";
|
import type { Amari } from "./interfaces/amari.js";
|
||||||
|
|
||||||
if (process.env.GH_CLIENT_ID === undefined
|
if (
|
||||||
|| process.env.GH_PRIVATE_KEY === undefined) {
|
process.env.GH_CLIENT_ID === undefined
|
||||||
|
|| process.env.GH_PRIVATE_KEY === undefined
|
||||||
|
) {
|
||||||
throw new Error("Cannot initialise GitHub!");
|
throw new Error("Cannot initialise GitHub!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,17 +43,22 @@ const githubApp = new App({
|
|||||||
});
|
});
|
||||||
const octokit = await githubApp.getInstallationOctokit(83_119_105);
|
const octokit = await githubApp.getInstallationOctokit(83_119_105);
|
||||||
const { data } = await octokit.rest.apps.getAuthenticated();
|
const { data } = await octokit.rest.apps.getAuthenticated();
|
||||||
await logger.log("debug", `Authenticated to GitHub as ${data?.name ?? "unknown"}`);
|
await logger.log(
|
||||||
|
"debug",
|
||||||
|
`Authenticated to GitHub as ${data?.name ?? "unknown"}`,
|
||||||
|
);
|
||||||
|
|
||||||
const amari: Amari = {
|
const amari: Amari = {
|
||||||
discord: new Client({ intents: [
|
discord: new Client({
|
||||||
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
GatewayIntentBits.GuildMessages,
|
GatewayIntentBits.GuildMessages,
|
||||||
GatewayIntentBits.MessageContent,
|
GatewayIntentBits.MessageContent,
|
||||||
GatewayIntentBits.GuildMembers,
|
GatewayIntentBits.GuildMembers,
|
||||||
GatewayIntentBits.DirectMessages,
|
GatewayIntentBits.DirectMessages,
|
||||||
],
|
],
|
||||||
partials: [ Partials.Channel ] }),
|
partials: [ Partials.Channel ],
|
||||||
|
}),
|
||||||
github: octokit,
|
github: octokit,
|
||||||
lastRssItems: {
|
lastRssItems: {
|
||||||
freeCodeCamp: null,
|
freeCodeCamp: null,
|
||||||
@@ -63,8 +70,10 @@ const amari: Amari = {
|
|||||||
const analytics = new DiscordAnalytics(amari.discord, logger);
|
const analytics = new DiscordAnalytics(amari.discord, logger);
|
||||||
|
|
||||||
amari.discord.once(Events.ClientReady, () => {
|
amari.discord.once(Events.ClientReady, () => {
|
||||||
void logger.log("debug",
|
void logger.log(
|
||||||
`Authenticated to Discord as ${amari.discord.user?.username ?? "unknown"}`);
|
"debug",
|
||||||
|
`Authenticated to Discord as ${amari.discord.user?.username ?? "unknown"}`,
|
||||||
|
);
|
||||||
void cacheData(amari);
|
void cacheData(amari);
|
||||||
analytics.startCron();
|
analytics.startCron();
|
||||||
scheduleJob("post news", "0 * * * *", async() => {
|
scheduleJob("post news", "0 * * * *", async() => {
|
||||||
@@ -98,10 +107,10 @@ amari.discord.on(Events.InteractionCreate, (interaction) => {
|
|||||||
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
|
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
|
||||||
if (interaction.isButton() && interaction.customId === "resolve") {
|
if (interaction.isButton() && interaction.customId === "resolve") {
|
||||||
if (interaction.user.id !== ids.users.naomi) {
|
if (interaction.user.id !== ids.users.naomi) {
|
||||||
return void interaction.reply(
|
return void interaction.reply({
|
||||||
{ content: "Who are you????",
|
content: "Who are you????",
|
||||||
flags: [ MessageFlags.Ephemeral ] },
|
flags: [ MessageFlags.Ephemeral ],
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
return void interaction.message.delete();
|
return void interaction.message.delete();
|
||||||
}
|
}
|
||||||
@@ -114,6 +123,29 @@ amari.discord.on(Events.InteractionCreate, (interaction) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
amari.discord.on(Events.ThreadCreate, (thread) => {
|
||||||
|
if (thread.parent?.isThreadOnly() !== true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { bugReports, communityFeedback, featureRequests, policyIdeation }
|
||||||
|
= ids.channels;
|
||||||
|
if (
|
||||||
|
![ bugReports,
|
||||||
|
communityFeedback,
|
||||||
|
featureRequests,
|
||||||
|
policyIdeation ].includes(
|
||||||
|
thread.parent.id,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const tagId = getForumTagId(thread.parent.id);
|
||||||
|
if (tagId === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void thread.setAppliedTags([ tagId ]);
|
||||||
|
});
|
||||||
|
|
||||||
amari.discord.on(Events.UserUpdate, (_oldUser, updatedUser) => {
|
amari.discord.on(Events.UserUpdate, (_oldUser, updatedUser) => {
|
||||||
void processUserGuildTag(amari, updatedUser);
|
void processUserGuildTag(amari, updatedUser);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,8 @@
|
|||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/naming-convention -- Baserow uses snake case */
|
|
||||||
|
|
||||||
export interface FormSubmission {
|
export interface FormSubmission {
|
||||||
table_id: number;
|
[key: string]: unknown;
|
||||||
items: Array<{ id: number }>;
|
id: number;
|
||||||
|
manualSort: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @copyright nhcarrigan
|
||||||
|
* @license Naomi's Public License
|
||||||
|
* @author Naomi Carrigan
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface ProgressReminder {
|
||||||
|
channelId: string;
|
||||||
|
roleId: string;
|
||||||
|
name: string;
|
||||||
|
createThread: boolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* @copyright NHCarrigan
|
||||||
|
* @license Naomi's Public License
|
||||||
|
* @author Naomi Carrigan
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ids } from "../config/ids.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grabs the "unanswered" tag ID for a given forum channel ID.
|
||||||
|
* @param id - The ID of the forum channel.
|
||||||
|
* @returns The ID of the "unanswered" tag, or null if not found.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line complexity -- This is less complex than trying to narrow the type...
|
||||||
|
export const getForumTagId = (id: string): string | null => {
|
||||||
|
switch (id) {
|
||||||
|
case ids.channels.bugReports:
|
||||||
|
return ids.tags.unanswered.bugReports;
|
||||||
|
case ids.channels.communityFeedback:
|
||||||
|
return ids.tags.unanswered.communityFeedback;
|
||||||
|
case ids.channels.featureRequests:
|
||||||
|
return ids.tags.unanswered.featureRequests;
|
||||||
|
case ids.channels.policyIdeation:
|
||||||
|
return ids.tags.unanswered.policyIdeation;
|
||||||
|
case ids.channels.accessibilityForum:
|
||||||
|
return ids.tags.unanswered.accessibilityForum;
|
||||||
|
case ids.channels.marketingProposals:
|
||||||
|
return ids.tags.unanswered.marketingProposals;
|
||||||
|
case ids.channels.technicalSupport:
|
||||||
|
return ids.tags.unanswered.technicalSupport;
|
||||||
|
case ids.channels.billingQuestions:
|
||||||
|
return ids.tags.unanswered.billingQuestions;
|
||||||
|
case ids.channels.pressInquiries:
|
||||||
|
return ids.tags.unanswered.pressInquiries;
|
||||||
|
case ids.channels.partnershipRequests:
|
||||||
|
return ids.tags.unanswered.partnershipRequests;
|
||||||
|
case ids.channels.legalNotices:
|
||||||
|
return ids.tags.unanswered.legalNotices;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -40,13 +40,5 @@ export const logMenteeJoin = async(
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await channel.send({
|
|
||||||
content: `Hey <@${member.id}>~!
|
|
||||||
|
|
||||||
Welcome to our community! It looks like you may have applied for our mentorship programme!
|
|
||||||
|
|
||||||
If that is correct, you should ping Naomi to grant your role and begin onboarding! <a:love:1364089736557494353>`,
|
|
||||||
});
|
|
||||||
await logger.metric("processed_mentee_join", 1, { user: member.id });
|
await logger.metric("processed_mentee_join", 1, { user: member.id });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -123,6 +123,13 @@ const postHackerNews = async(amari: Amari): Promise<void> => {
|
|||||||
}
|
}
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
latestPosts.map(async(post) => {
|
latestPosts.map(async(post) => {
|
||||||
|
if (
|
||||||
|
hasNaughtyWords(post.title)
|
||||||
|
|| hasNaughtyWords(post.contentSnippet)
|
||||||
|
|| hasNaughtyWords(post.content)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const sent = await channel.send(post.link);
|
const sent = await channel.send(post.link);
|
||||||
if (channel.type === ChannelType.GuildAnnouncement) {
|
if (channel.type === ChannelType.GuildAnnouncement) {
|
||||||
await sent.crosspost();
|
await sent.crosspost();
|
||||||
|
|||||||
@@ -3,70 +3,79 @@
|
|||||||
* @license Naomi's Public License
|
* @license Naomi's Public License
|
||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
import { ChannelType } from "discord.js";
|
import { ChannelType, type TextChannel } from "discord.js";
|
||||||
import { progressReminders } from "../config/progressReminders.js";
|
import { progressReminders } from "../config/progressReminders.js";
|
||||||
import { logger } from "../utils/logger.js";
|
import { logger } from "../utils/logger.js";
|
||||||
import type { Amari } from "../interfaces/amari.js";
|
import type { Amari } from "../interfaces/amari.js";
|
||||||
|
import type { ProgressReminder } from "../interfaces/reminder.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts a daily progress check-in reminder in configured channels.
|
* Posts a daily progress check-in reminder in configured channels.
|
||||||
* @param amari - Amari's instance.
|
* @param amari - Amari's instance.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line max-lines-per-function -- shut up
|
// eslint-disable-next-line max-lines-per-function -- shut up
|
||||||
export const postProgressReminders = async(
|
export const postProgressReminders = async(amari: Amari): Promise<void> => {
|
||||||
amari: Amari,
|
|
||||||
): Promise<void> => {
|
|
||||||
try {
|
try {
|
||||||
const mapped = await Promise.all(
|
const mapped = await Promise.all(
|
||||||
progressReminders.map(async(channel) => {
|
progressReminders.map(async(reminder) => {
|
||||||
const fetched = await amari.discord.channels.
|
const fetched = await amari.discord.channels.
|
||||||
fetch(channel.channelId).
|
fetch(reminder.channelId).
|
||||||
catch(() => {
|
catch(() => {
|
||||||
void logger.log("warn", `Failed to fetch channel ${channel.name}.`);
|
void logger.log(
|
||||||
|
"warn",
|
||||||
|
`Failed to fetch channel ${reminder.name}.`,
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
if (!fetched) {
|
if (!fetched) {
|
||||||
await logger.log("warn", `Channel ${channel.name} not found.`);
|
await logger.log("warn", `Channel ${reminder.name} not found.`);
|
||||||
return null;
|
return { channel: null, reminder: reminder };
|
||||||
}
|
}
|
||||||
if (fetched.type !== ChannelType.GuildText) {
|
if (fetched.type !== ChannelType.GuildText) {
|
||||||
await logger.log(
|
await logger.log(
|
||||||
"warn",
|
"warn",
|
||||||
`Channel ${channel.name} is not a text channel.`,
|
`Channel ${reminder.name} is not a text channel.`,
|
||||||
);
|
);
|
||||||
return null;
|
return { channel: null, reminder: reminder };
|
||||||
}
|
}
|
||||||
return fetched;
|
return { channel: fetched, reminder: reminder };
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const filtered = mapped.filter((channel) => {
|
const filtered: Array<{
|
||||||
|
channel: TextChannel;
|
||||||
|
reminder: ProgressReminder;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Filter is dumb.
|
||||||
|
}> = mapped.filter(({ channel }) => {
|
||||||
return channel !== null;
|
return channel !== null;
|
||||||
});
|
}) as Array<{
|
||||||
|
channel: TextChannel;
|
||||||
|
reminder: ProgressReminder;
|
||||||
|
}>;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
filtered.map(async(channel) => {
|
filtered.map(async(reminder) => {
|
||||||
const isThread = progressReminders.find((c) => {
|
const isThread
|
||||||
return c.channelId === channel.id;
|
= progressReminders.find((c) => {
|
||||||
|
return c.channelId === reminder.channel.id;
|
||||||
})?.createThread ?? false;
|
})?.createThread ?? false;
|
||||||
const sent = await channel.
|
const sent = await reminder.channel.
|
||||||
send({ allowedMentions: {
|
send({
|
||||||
|
allowedMentions: {
|
||||||
parse: [ "roles" ],
|
parse: [ "roles" ],
|
||||||
},
|
},
|
||||||
content:
|
content: `Good morning <@&${reminder.reminder.roleId}> It is time for your daily progress update. Please share the following in ${
|
||||||
`Good morning <@&${
|
isThread
|
||||||
progressReminders.find((c) => {
|
|
||||||
return c.channelId === channel.id;
|
|
||||||
})?.roleId ?? channel.guildId
|
|
||||||
}> It is time for your daily progress update. Please share the following in ${isThread
|
|
||||||
? "the thread attached to this message"
|
? "the thread attached to this message"
|
||||||
: "this channel"}:
|
: "this channel"
|
||||||
|
}:
|
||||||
|
|
||||||
1️⃣ What did you accomplish yesterday?
|
1️⃣ What did you accomplish yesterday?
|
||||||
2️⃣ What are you working on today?
|
2️⃣ What are you working on today?
|
||||||
3️⃣ Are there any blockers or issues you need help with?` }).
|
3️⃣ Are there any blockers or issues you need help with?`,
|
||||||
|
}).
|
||||||
catch(() => {
|
catch(() => {
|
||||||
void logger.log(
|
void logger.log(
|
||||||
"warn",
|
"warn",
|
||||||
`Failed to send progress reminder in channel ${channel.name}.`,
|
`Failed to send progress reminder in channel ${reminder.channel.name}.`,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -79,7 +88,7 @@ export const postProgressReminders = async(
|
|||||||
catch(() => {
|
catch(() => {
|
||||||
void logger.log(
|
void logger.log(
|
||||||
"warn",
|
"warn",
|
||||||
`Failed to start thread in channel ${channel.name}.`,
|
`Failed to start thread in channel ${reminder.channel.name}.`,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { MessageFlags } from "discord.js";
|
import { MessageFlags } from "discord.js";
|
||||||
import { formIds } from "../config/forms.js";
|
|
||||||
import { ids } from "../config/ids.js";
|
import { ids } from "../config/ids.js";
|
||||||
import { logger } from "../utils/logger.js";
|
import { logger } from "../utils/logger.js";
|
||||||
import type { Amari } from "../interfaces/amari.js";
|
import type { Amari } from "../interfaces/amari.js";
|
||||||
@@ -21,18 +20,26 @@ import type { FastifyRequest, FastifyReply } from "fastify";
|
|||||||
// eslint-disable-next-line max-lines-per-function -- only long because of analytics.
|
// eslint-disable-next-line max-lines-per-function -- only long because of analytics.
|
||||||
export const processFormSubmission = async(
|
export const processFormSubmission = async(
|
||||||
amari: Amari,
|
amari: Amari,
|
||||||
|
request: FastifyRequest<{
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Fastify standard.
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- Fastify standard.
|
||||||
request: FastifyRequest<{ Body: FormSubmission }>,
|
Body: Array<FormSubmission>;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- Fastify standard.
|
||||||
|
Querystring: { form?: string };
|
||||||
|
}>,
|
||||||
response: FastifyReply,
|
response: FastifyReply,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const { secret } = request.headers;
|
const { authorization: secret } = request.headers;
|
||||||
if (secret !== process.env.BASEROW_SECRET
|
if (
|
||||||
|| process.env.BASEROW_SECRET === undefined) {
|
secret !== process.env.BASEROW_SECRET
|
||||||
|
|| secret === undefined
|
||||||
|
) {
|
||||||
await response.status(403).send({ message: "Invalid Secret Provided." });
|
await response.status(403).send({ message: "Invalid Secret Provided." });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const { form } = request.query;
|
||||||
await response.status(204).send();
|
await response.status(204).send();
|
||||||
const channel = amari.discord.channels.cache.get(ids.channels.formSubmissions)
|
const channel
|
||||||
|
= amari.discord.channels.cache.get(ids.channels.formSubmissions)
|
||||||
?? await amari.discord.channels.fetch(ids.channels.formSubmissions);
|
?? await amari.discord.channels.fetch(ids.channels.formSubmissions);
|
||||||
if (channel?.isSendable() !== true) {
|
if (channel?.isSendable() !== true) {
|
||||||
await logger.log(
|
await logger.log(
|
||||||
@@ -41,15 +48,15 @@ export const processFormSubmission = async(
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { table_id: table, items } = request.body;
|
const submissionIds = request.body.map((item) => {
|
||||||
const rowIds = items.map((item) => {
|
return `${item.id.toString()} (${item.manualSort.toString()})`;
|
||||||
return item.id;
|
});
|
||||||
}).join(", ");
|
|
||||||
const tableName = formIds[table];
|
|
||||||
await channel.send({
|
await channel.send({
|
||||||
components: [
|
components: [
|
||||||
{
|
{
|
||||||
content: `${tableName ?? "Unknown Form"} Submission Received!\n\nRow ID(s): ${rowIds}`,
|
content: `${
|
||||||
|
form ?? "Unknown Form"
|
||||||
|
} Submission Received!\n\nRow ID(s): ${submissionIds.join(", ")}`,
|
||||||
type: 10,
|
type: 10,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -68,5 +75,7 @@ export const processFormSubmission = async(
|
|||||||
],
|
],
|
||||||
flags: [ MessageFlags.IsComponentsV2 ],
|
flags: [ MessageFlags.IsComponentsV2 ],
|
||||||
});
|
});
|
||||||
await logger.metric("processed_form_submission", 1, { table: String(table) });
|
await logger.metric("processed_form_submission", 1, {
|
||||||
|
table: String(request.body),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,11 +46,11 @@ export const processMentorshipRole = async(
|
|||||||
|
|
||||||
Welcome to our mentorship programme! We are excited to have you here and help you grow and reach success.
|
Welcome to our mentorship programme! We are excited to have you here and help you grow and reach success.
|
||||||
|
|
||||||
To get started, please make sure you have accepted the GitHub invite for your dedicated repository under the [NHCarrigan Mentorship organsation](<https://github.com/nhcarrigan-mentorship>).
|
To get started, please ping Naomi with your GitHub username and your first and last name. She will invite you to your dedicated repository in the [NHCarrigan Mentorship organsation](<https://github.com/nhcarrigan-mentorship>) where you can work on your flagship project.
|
||||||
|
|
||||||
Once you have done this, your next step is to read our [wiki](<https://nhcarrigan.notion.site/mentorship-wiki>). Then, create your post in <#1400629118110011526> as outlined in the wiki.
|
Once you have done this, your next step is to read our [wiki](<https://docs.nhcarrigan.com/mentorship/00-faq/>). Then, create your goal-setting post in <#1400629118110011526> and your project-planning post in <#1400616702265266186> as outlined in the wiki.
|
||||||
|
|
||||||
Naomi will follow up with you from there! Best of luck on your journey~! <a:love:1364089736557494353>`,
|
If at any time you need some guidance, support, or review, please ping Naomi! She's always happy to help you succeed in your mentorship! Best of luck on your journey~! <a:love:1364089736557494353>`,
|
||||||
});
|
});
|
||||||
await logger.metric("processed_mentorship_role", 1, {
|
await logger.metric("processed_mentorship_role", 1, {
|
||||||
user: updatedMember.id,
|
user: updatedMember.id,
|
||||||
|
|||||||
+5
-2
@@ -87,7 +87,9 @@ export const instantiateServer = (amari: Amari): void => {
|
|||||||
|
|
||||||
server.
|
server.
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Fastify standard.
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- Fastify standard.
|
||||||
post<{ Body: FormSubmission }>("/form", async(request, response) => {
|
post<{ Body: Array<FormSubmission>; Querystring: { form: string } }>(
|
||||||
|
"/form",
|
||||||
|
async(request, response) => {
|
||||||
try {
|
try {
|
||||||
await processFormSubmission(amari, request, response);
|
await processFormSubmission(amari, request, response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -96,7 +98,8 @@ export const instantiateServer = (amari: Amari): void => {
|
|||||||
}
|
}
|
||||||
await logger.error("/form route", error);
|
await logger.error("/form route", error);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
server.listen({ port: 7044 }, (error) => {
|
server.listen({ port: 7044 }, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user