generated from nhcarrigan/template
Compare commits
2 Commits
main
..
a82122561a
| Author | SHA1 | Date | |
|---|---|---|---|
| a82122561a | |||
| dcb61d9c5b |
+4
-13
@@ -8,32 +8,23 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
lint:
|
||||||
name: CI
|
name: Lint and Test
|
||||||
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 v24
|
- name: Use Node.js v22
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 22
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v2
|
uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 10
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -1,177 +0,0 @@
|
|||||||
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,34 @@
|
|||||||
|
name: Code Analysis
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sonar:
|
||||||
|
name: SonarQube
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Source Files
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: SonarCube Scan
|
||||||
|
uses: SonarSource/sonarqube-scan-action@v4
|
||||||
|
timeout-minutes: 10
|
||||||
|
env:
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
SONAR_HOST_URL: "https://quality.nhcarrigan.com"
|
||||||
|
with:
|
||||||
|
args: >
|
||||||
|
-Dsonar.sources=.
|
||||||
|
-Dsonar.projectKey=becca-lyria
|
||||||
|
|
||||||
|
- name: SonarQube Quality Gate check
|
||||||
|
uses: sonarsource/sonarqube-quality-gate-action@v1
|
||||||
|
with:
|
||||||
|
pollingTimeoutSec: 600
|
||||||
|
env:
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
SONAR_HOST_URL: "https://quality.nhcarrigan.com"
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
---
|
|
||||||
title: Becca Lyria
|
|
||||||
---
|
|
||||||
|
|
||||||
Becca Lyria (hereinafter the "Application") is an AI-powered Discord bot that provides an interactive text-based role-playing game experience through direct messages. The bot utilizes Anthropic's Claude AI to create dynamic, personalized RPG adventures for users.
|
|
||||||
|
|
||||||
## 1. User Documentation
|
|
||||||
|
|
||||||
This section is for those interacting with a live instance of the Application.
|
|
||||||
|
|
||||||
### Overview
|
|
||||||
|
|
||||||
Becca Lyria is a user-installable Discord bot that transforms your DMs into an immersive text-based RPG experience. Acting as a wise mage named Becca with a cold and calculating personality, the bot serves as your personal dungeon master, weaving interactive stories that adapt to your choices and actions.
|
|
||||||
|
|
||||||
### Getting Started
|
|
||||||
|
|
||||||
1. **Installation**: [Add Becca Lyria to your Discord account](https://discord.com/oauth2/authorize?client_id=1343341112437248041)
|
|
||||||
2. **Subscription**: The bot requires an active subscription to use its features
|
|
||||||
3. **Start Playing**: Use the `/start` command to begin your adventure
|
|
||||||
|
|
||||||
### Available Commands
|
|
||||||
|
|
||||||
- **`/start`** - Start a new RPG scenario. Becca will create a fresh adventure and send it to your DMs
|
|
||||||
- **`/about`** - Learn more about the bot, including version information and useful links
|
|
||||||
- **`/clear`** - Clear your current adventure history to start fresh
|
|
||||||
|
|
||||||
### How to Play
|
|
||||||
|
|
||||||
1. Send Becca a `/start` command to begin a new adventure
|
|
||||||
2. Once the story begins in your DMs, simply respond naturally to continue the narrative
|
|
||||||
3. The bot maintains conversation history (up to 20 messages) to provide context-aware responses
|
|
||||||
4. Use `/clear` to reset your adventure history when you want to start over
|
|
||||||
5. The bot supports free-form text adventures - you can attempt any action you can imagine
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
- **AI-Powered Storytelling**: Powered by Claude 3.5 Sonnet for rich, dynamic narratives
|
|
||||||
- **Conversation Memory**: Maintains context from recent messages for coherent storytelling
|
|
||||||
- **Free-Form Gameplay**: No restrictive multiple choice options - express your actions naturally
|
|
||||||
- **Personalized Experience**: The bot adapts to your playstyle and incorporates your Discord display name
|
|
||||||
- **Privacy-Focused**: All gameplay happens in private DMs
|
|
||||||
|
|
||||||
### Subscription Model
|
|
||||||
|
|
||||||
Becca Lyria operates on a premium subscription model through Discord's monetization system. Users must have an active subscription to access the bot's RPG features.
|
|
||||||
|
|
||||||
## 2. Technical Documentation
|
|
||||||
|
|
||||||
This section is for those interested in running their own instance of the Application.
|
|
||||||
|
|
||||||
### Architecture Overview
|
|
||||||
|
|
||||||
Becca Lyria is built as a modern Discord bot using TypeScript and several key technologies:
|
|
||||||
|
|
||||||
**Core Technologies:**
|
|
||||||
- **Node.js/TypeScript**: Main runtime and development language
|
|
||||||
- **Discord.js**: Discord API interaction library
|
|
||||||
- **Anthropic SDK**: Integration with Claude AI models
|
|
||||||
- **Fastify**: Web server for health monitoring
|
|
||||||
- **PNPM**: Package management
|
|
||||||
|
|
||||||
**AI Integration:**
|
|
||||||
- **Provider**: Anthropic Claude (claude-3-5-sonnet-latest for conversations, claude-sonnet-4-20250514 for story starts)
|
|
||||||
- **Context Management**: Maintains up to 20 messages of conversation history
|
|
||||||
- **Personality System**: Configurable personality traits for consistent character behavior
|
|
||||||
|
|
||||||
### Project Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
src/
|
|
||||||
├── index.ts # Main entry point and Discord client setup
|
|
||||||
├── commands/ # Slash command definitions
|
|
||||||
│ ├── about.ts
|
|
||||||
│ ├── clear.ts
|
|
||||||
│ └── start.ts
|
|
||||||
├── config/
|
|
||||||
│ └── personality.ts # AI personality configuration
|
|
||||||
├── events/
|
|
||||||
│ └── message.ts # Direct message event handling
|
|
||||||
├── modules/ # Command implementation logic
|
|
||||||
│ ├── about.ts
|
|
||||||
│ ├── clear.ts
|
|
||||||
│ └── start.ts
|
|
||||||
├── server/
|
|
||||||
│ └── serve.ts # Health monitoring web server
|
|
||||||
└── utils/ # Utility functions
|
|
||||||
├── ai.ts # Anthropic client configuration
|
|
||||||
├── calculateCost.ts # Usage cost tracking
|
|
||||||
├── isSubscribed.ts # Subscription verification
|
|
||||||
├── logger.ts # Logging utility
|
|
||||||
└── replyToError.ts # Error handling
|
|
||||||
```
|
|
||||||
|
|
||||||
### Environment Variables
|
|
||||||
|
|
||||||
The application requires several environment variables:
|
|
||||||
|
|
||||||
- `DISCORD_TOKEN`: Discord bot token
|
|
||||||
- `AI_TOKEN`: Anthropic API key
|
|
||||||
- `LOG_TOKEN`: Logging service token (optional)
|
|
||||||
|
|
||||||
### Key Features Implementation
|
|
||||||
|
|
||||||
**Subscription System:**
|
|
||||||
- Integrates with Discord's premium features
|
|
||||||
- SKU ID: `1343347225698500744`
|
|
||||||
- Entitlement checking for both interactions and messages
|
|
||||||
- Special bypass for bot owner (ID: `465650873650118659`)
|
|
||||||
|
|
||||||
**Conversation Management:**
|
|
||||||
- Fetches last 20 messages from DM channel
|
|
||||||
- Supports history clearing with special `<Clear History>` marker
|
|
||||||
- Converts message history to Anthropic's message format
|
|
||||||
- Maintains role context (user vs assistant)
|
|
||||||
|
|
||||||
**Error Handling:**
|
|
||||||
- Comprehensive error logging with custom logger
|
|
||||||
- Graceful error responses to users
|
|
||||||
- Unhandled rejection and exception catching
|
|
||||||
|
|
||||||
**Cost Tracking:**
|
|
||||||
- Monitors AI usage with token counting
|
|
||||||
- Calculates costs based on Anthropic pricing (input: $3/1M tokens, output: $15/1M tokens)
|
|
||||||
- Logs usage statistics per user
|
|
||||||
|
|
||||||
### Development Setup
|
|
||||||
|
|
||||||
1. **Prerequisites**: Node.js, PNPM
|
|
||||||
2. **Installation**: `pnpm install`
|
|
||||||
3. **Build**: `pnpm run build`
|
|
||||||
4. **Development**: Configure environment variables in `dev.env`
|
|
||||||
5. **Production**: Configure environment variables in `prod.env`
|
|
||||||
6. **Start**: `pnpm start` (requires 1Password CLI for env injection)
|
|
||||||
|
|
||||||
### Deployment Considerations
|
|
||||||
|
|
||||||
- Web server runs on port 5010 for health checks
|
|
||||||
- Requires Discord bot permissions for DMs and message content
|
|
||||||
- Needs stable Anthropic API access
|
|
||||||
- Logging integration with nhcarrigan logging service
|
|
||||||
|
|
||||||
## 3. Legal Documentation
|
|
||||||
|
|
||||||
:::note
|
|
||||||
This section is coming soon!
|
|
||||||
:::
|
|
||||||
|
|
||||||
This section is for expansions to our legal policies specific to the Application.
|
|
||||||
|
|
||||||
## 4. Contributing Documentation
|
|
||||||
|
|
||||||
This section is for documentation related to contributing to the Application's codebase.
|
|
||||||
|
|
||||||
### Development Standards
|
|
||||||
|
|
||||||
**Code Quality:**
|
|
||||||
- TypeScript with strict configuration
|
|
||||||
- ESLint with @nhcarrigan/eslint-config
|
|
||||||
- Maximum function length limits enforced
|
|
||||||
- Comprehensive JSDoc documentation required
|
|
||||||
|
|
||||||
**Testing:**
|
|
||||||
- Vitest framework configured
|
|
||||||
- Istanbul coverage reporting
|
|
||||||
- Currently no tests implemented (placeholder exists)
|
|
||||||
|
|
||||||
**Licensing:**
|
|
||||||
- Licensed under Naomi's Public License
|
|
||||||
- Copyright held by Naomi Carrigan
|
|
||||||
- See LICENSE.md for full terms
|
|
||||||
|
|
||||||
### Contribution Process
|
|
||||||
|
|
||||||
1. **Issues**: Report bugs and request features through GitHub issues
|
|
||||||
2. **Pull Requests**: Fork, develop, and submit PRs for review
|
|
||||||
3. **Code Review**: All changes require review before merging
|
|
||||||
4. **Guidelines**: Follow established [contributing guidelines](CONTRIBUTING.md)
|
|
||||||
5. **Conduct**: Adhere to [Code of Conduct](CODE_OF_CONDUCT.md)
|
|
||||||
|
|
||||||
### Development Workflow
|
|
||||||
|
|
||||||
**Commands:**
|
|
||||||
- `pnpm run build`: Compile TypeScript to production JavaScript
|
|
||||||
- `pnpm run lint`: Run ESLint with zero warnings tolerance
|
|
||||||
- `pnpm run test`: Run test suite (currently placeholder)
|
|
||||||
- `pnpm start`: Start production build with environment injection
|
|
||||||
|
|
||||||
**Architecture Patterns:**
|
|
||||||
- Event-driven Discord bot architecture
|
|
||||||
- Modular command system with separate definition and implementation
|
|
||||||
- Utility-first approach for common functionality
|
|
||||||
- Separation of concerns between commands, events, and business logic
|
|
||||||
|
|
||||||
### Contact Information
|
|
||||||
|
|
||||||
- **Chat Server**: [http://chat.nhcarrigan.com](http://chat.nhcarrigan.com)
|
|
||||||
- **Email**: contact@nhcarrigan.com
|
|
||||||
- **Source Code**: [https://git.nhcarrigan.com/nhcarrigan/becca-lyria](https://git.nhcarrigan.com/nhcarrigan/becca-lyria)
|
|
||||||
- **Documentation**: [https://docs.nhcarrigan.com/](https://docs.nhcarrigan.com/)
|
|
||||||
@@ -8,7 +8,7 @@ Becca is a user-installable bot that allows you to play a text-based role-playin
|
|||||||
|
|
||||||
## Feedback and Bugs
|
## Feedback and Bugs
|
||||||
|
|
||||||
If you have feedback or a bug report, please [log a ticket on our forum](https://support.nhcarrigan.com).
|
If you have feedback or a bug report, please feel free to open an issue!
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
DISCORD_TOKEN="op://Environment Variables - Development/Naomi Dev Bot/token"
|
|
||||||
AI_TOKEN="op://Environment Variables - Development/Naomi Dev Bot/ai token"
|
|
||||||
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
|
|
||||||
+1
-2
@@ -24,8 +24,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anthropic-ai/sdk": "0.52.0",
|
"@anthropic-ai/sdk": "0.52.0",
|
||||||
"@nhcarrigan/discord-analytics": "0.0.6",
|
"@nhcarrigan/logger": "1.0.0",
|
||||||
"@nhcarrigan/logger": "1.1.1",
|
|
||||||
"discord.js": "14.19.3",
|
"discord.js": "14.19.3",
|
||||||
"fastify": "5.3.3"
|
"fastify": "5.3.3"
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+5
-54
@@ -11,12 +11,9 @@ importers:
|
|||||||
'@anthropic-ai/sdk':
|
'@anthropic-ai/sdk':
|
||||||
specifier: 0.52.0
|
specifier: 0.52.0
|
||||||
version: 0.52.0
|
version: 0.52.0
|
||||||
'@nhcarrigan/discord-analytics':
|
|
||||||
specifier: 0.0.6
|
|
||||||
version: 0.0.6(@nhcarrigan/logger@1.1.1)(discord.js@14.19.3)
|
|
||||||
'@nhcarrigan/logger':
|
'@nhcarrigan/logger':
|
||||||
specifier: 1.1.1
|
specifier: 1.0.0
|
||||||
version: 1.1.1
|
version: 1.0.0
|
||||||
discord.js:
|
discord.js:
|
||||||
specifier: 14.19.3
|
specifier: 14.19.3
|
||||||
version: 14.19.3
|
version: 14.19.3
|
||||||
@@ -426,12 +423,6 @@ packages:
|
|||||||
'@jridgewell/trace-mapping@0.3.25':
|
'@jridgewell/trace-mapping@0.3.25':
|
||||||
resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==}
|
resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==}
|
||||||
|
|
||||||
'@nhcarrigan/discord-analytics@0.0.6':
|
|
||||||
resolution: {integrity: sha512-Mci/zSY2nE24BM2cZx5EiYqwpRTTCBznFfs2BphejzDAaWPt1P12V5ln7OSUbFLGhvTD/Qwi0za3yPv6shQLoA==}
|
|
||||||
peerDependencies:
|
|
||||||
'@nhcarrigan/logger': '>=1.1.0-hotfix'
|
|
||||||
discord.js: ^14.0.0
|
|
||||||
|
|
||||||
'@nhcarrigan/eslint-config@5.2.0':
|
'@nhcarrigan/eslint-config@5.2.0':
|
||||||
resolution: {integrity: sha512-YpTTqhviKMlRwKF+RC/GYiA5i2jTCmg8uftuiufldneNV5HMbGpTfBbV7tpa8++5mpYJc4+eZaf40QbDiz84dQ==}
|
resolution: {integrity: sha512-YpTTqhviKMlRwKF+RC/GYiA5i2jTCmg8uftuiufldneNV5HMbGpTfBbV7tpa8++5mpYJc4+eZaf40QbDiz84dQ==}
|
||||||
engines: {node: '>=22', pnpm: '>=9'}
|
engines: {node: '>=22', pnpm: '>=9'}
|
||||||
@@ -442,8 +433,8 @@ packages:
|
|||||||
typescript: '>=5'
|
typescript: '>=5'
|
||||||
vitest: '>=2'
|
vitest: '>=2'
|
||||||
|
|
||||||
'@nhcarrigan/logger@1.1.1':
|
'@nhcarrigan/logger@1.0.0':
|
||||||
resolution: {integrity: sha512-P6OEQFHDtf6psybYGljuCxkSW6DLQCsx1aZZ3w4YKBXHBFjDbhuvpM9K1kPhVN48hakitx2WPLEoIFr6YZELYw==}
|
resolution: {integrity: sha512-2e19Bie+ZKb6yKPKjhawqsENkhHatYkvBAmFZx9eToOXdOca+CYi51tldRMtejg6e0+4hOOf2bo5zdBQKmH0dw==}
|
||||||
|
|
||||||
'@nhcarrigan/typescript-config@4.0.0':
|
'@nhcarrigan/typescript-config@4.0.0':
|
||||||
resolution: {integrity: sha512-969HVha7A/Sg77fuMwOm6p14a+7C5iE6g55OD71srqwKIgksQl+Ex/hAI/pyzTQFDQ/FBJbpnHlR4Ov25QV/rw==}
|
resolution: {integrity: sha512-969HVha7A/Sg77fuMwOm6p14a+7C5iE6g55OD71srqwKIgksQl+Ex/hAI/pyzTQFDQ/FBJbpnHlR4Ov25QV/rw==}
|
||||||
@@ -957,10 +948,6 @@ packages:
|
|||||||
core-js-compat@3.40.0:
|
core-js-compat@3.40.0:
|
||||||
resolution: {integrity: sha512-0XEDpr5y5mijvw8Lbc6E5AkjrHfp7eEoPlu36SWeAbcL8fn1G1ANe8DBlo2XoNN89oVpxWwOjYIPVzR4ZvsKCQ==}
|
resolution: {integrity: sha512-0XEDpr5y5mijvw8Lbc6E5AkjrHfp7eEoPlu36SWeAbcL8fn1G1ANe8DBlo2XoNN89oVpxWwOjYIPVzR4ZvsKCQ==}
|
||||||
|
|
||||||
cron-parser@4.9.0:
|
|
||||||
resolution: {integrity: sha512-p0SaNjrHOnQeR8/VnfGbmg9te2kfyYSQ7Sc/j/6DtPL3JQvKxmjO9TSjNFpujqV3vEYYBvNNvXSxzyksBWAx1Q==}
|
|
||||||
engines: {node: '>=12.0.0'}
|
|
||||||
|
|
||||||
cross-spawn@7.0.6:
|
cross-spawn@7.0.6:
|
||||||
resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==}
|
resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==}
|
||||||
engines: {node: '>= 8'}
|
engines: {node: '>= 8'}
|
||||||
@@ -1661,9 +1648,6 @@ packages:
|
|||||||
lodash@4.17.21:
|
lodash@4.17.21:
|
||||||
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
|
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
|
||||||
|
|
||||||
long-timeout@0.1.1:
|
|
||||||
resolution: {integrity: sha512-BFRuQUqc7x2NWxfJBCyUrN8iYUYznzL9JROmRz1gZ6KlOIgmoD+njPVbb+VNn2nGMKggMsK79iUNErillsrx7w==}
|
|
||||||
|
|
||||||
loose-envify@1.4.0:
|
loose-envify@1.4.0:
|
||||||
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
|
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@@ -1677,10 +1661,6 @@ packages:
|
|||||||
lru-cache@5.1.1:
|
lru-cache@5.1.1:
|
||||||
resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==}
|
resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==}
|
||||||
|
|
||||||
luxon@3.7.2:
|
|
||||||
resolution: {integrity: sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==}
|
|
||||||
engines: {node: '>=12'}
|
|
||||||
|
|
||||||
magic-bytes.js@1.10.0:
|
magic-bytes.js@1.10.0:
|
||||||
resolution: {integrity: sha512-/k20Lg2q8LE5xiaaSkMXk4sfvI+9EGEykFS4b0CHHGWqDYU0bGUFSwchNOMA56D7TCs9GwVTkqe9als1/ns8UQ==}
|
resolution: {integrity: sha512-/k20Lg2q8LE5xiaaSkMXk4sfvI+9EGEykFS4b0CHHGWqDYU0bGUFSwchNOMA56D7TCs9GwVTkqe9als1/ns8UQ==}
|
||||||
|
|
||||||
@@ -1738,10 +1718,6 @@ packages:
|
|||||||
node-releases@2.0.19:
|
node-releases@2.0.19:
|
||||||
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
|
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
|
||||||
|
|
||||||
node-schedule@2.1.1:
|
|
||||||
resolution: {integrity: sha512-OXdegQq03OmXEjt2hZP33W2YPs/E5BcFQks46+G2gAxs4gHOIVD1u7EqlYLYSKsaIpyKCK9Gbk0ta1/gjRSMRQ==}
|
|
||||||
engines: {node: '>=6'}
|
|
||||||
|
|
||||||
normalize-package-data@2.5.0:
|
normalize-package-data@2.5.0:
|
||||||
resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==}
|
resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==}
|
||||||
|
|
||||||
@@ -2082,9 +2058,6 @@ packages:
|
|||||||
sonic-boom@4.2.0:
|
sonic-boom@4.2.0:
|
||||||
resolution: {integrity: sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==}
|
resolution: {integrity: sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==}
|
||||||
|
|
||||||
sorted-array-functions@1.3.0:
|
|
||||||
resolution: {integrity: sha512-2sqgzeFlid6N4Z2fUQ1cvFmTOLRi/sEDzSQ0OKYchqgoPmQBVyM3959qYx3fpS6Esef80KjmpgPeEr028dP3OA==}
|
|
||||||
|
|
||||||
source-map-js@1.2.1:
|
source-map-js@1.2.1:
|
||||||
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
|
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
@@ -2791,12 +2764,6 @@ snapshots:
|
|||||||
'@jridgewell/resolve-uri': 3.1.2
|
'@jridgewell/resolve-uri': 3.1.2
|
||||||
'@jridgewell/sourcemap-codec': 1.5.0
|
'@jridgewell/sourcemap-codec': 1.5.0
|
||||||
|
|
||||||
'@nhcarrigan/discord-analytics@0.0.6(@nhcarrigan/logger@1.1.1)(discord.js@14.19.3)':
|
|
||||||
dependencies:
|
|
||||||
'@nhcarrigan/logger': 1.1.1
|
|
||||||
discord.js: 14.19.3
|
|
||||||
node-schedule: 2.1.1
|
|
||||||
|
|
||||||
'@nhcarrigan/eslint-config@5.2.0(@typescript-eslint/utils@8.24.0(eslint@9.27.0)(typescript@5.8.3))(eslint@9.27.0)(playwright@1.50.1)(react@19.0.0)(typescript@5.8.3)(vitest@3.1.4(@types/node@22.15.21))':
|
'@nhcarrigan/eslint-config@5.2.0(@typescript-eslint/utils@8.24.0(eslint@9.27.0)(typescript@5.8.3))(eslint@9.27.0)(playwright@1.50.1)(react@19.0.0)(typescript@5.8.3)(vitest@3.1.4(@types/node@22.15.21))':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@eslint-community/eslint-plugin-eslint-comments': 4.4.1(eslint@9.27.0)
|
'@eslint-community/eslint-plugin-eslint-comments': 4.4.1(eslint@9.27.0)
|
||||||
@@ -2826,7 +2793,7 @@ snapshots:
|
|||||||
- eslint-import-resolver-webpack
|
- eslint-import-resolver-webpack
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
'@nhcarrigan/logger@1.1.1': {}
|
'@nhcarrigan/logger@1.0.0': {}
|
||||||
|
|
||||||
'@nhcarrigan/typescript-config@4.0.0(typescript@5.8.3)':
|
'@nhcarrigan/typescript-config@4.0.0(typescript@5.8.3)':
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -3378,10 +3345,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
browserslist: 4.24.4
|
browserslist: 4.24.4
|
||||||
|
|
||||||
cron-parser@4.9.0:
|
|
||||||
dependencies:
|
|
||||||
luxon: 3.7.2
|
|
||||||
|
|
||||||
cross-spawn@7.0.6:
|
cross-spawn@7.0.6:
|
||||||
dependencies:
|
dependencies:
|
||||||
path-key: 3.1.1
|
path-key: 3.1.1
|
||||||
@@ -4291,8 +4254,6 @@ snapshots:
|
|||||||
|
|
||||||
lodash@4.17.21: {}
|
lodash@4.17.21: {}
|
||||||
|
|
||||||
long-timeout@0.1.1: {}
|
|
||||||
|
|
||||||
loose-envify@1.4.0:
|
loose-envify@1.4.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
js-tokens: 4.0.0
|
js-tokens: 4.0.0
|
||||||
@@ -4305,8 +4266,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
yallist: 3.1.1
|
yallist: 3.1.1
|
||||||
|
|
||||||
luxon@3.7.2: {}
|
|
||||||
|
|
||||||
magic-bytes.js@1.10.0: {}
|
magic-bytes.js@1.10.0: {}
|
||||||
|
|
||||||
magic-string@0.30.17:
|
magic-string@0.30.17:
|
||||||
@@ -4354,12 +4313,6 @@ snapshots:
|
|||||||
|
|
||||||
node-releases@2.0.19: {}
|
node-releases@2.0.19: {}
|
||||||
|
|
||||||
node-schedule@2.1.1:
|
|
||||||
dependencies:
|
|
||||||
cron-parser: 4.9.0
|
|
||||||
long-timeout: 0.1.1
|
|
||||||
sorted-array-functions: 1.3.0
|
|
||||||
|
|
||||||
normalize-package-data@2.5.0:
|
normalize-package-data@2.5.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
hosted-git-info: 2.8.9
|
hosted-git-info: 2.8.9
|
||||||
@@ -4741,8 +4694,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
atomic-sleep: 1.0.0
|
atomic-sleep: 1.0.0
|
||||||
|
|
||||||
sorted-array-functions@1.3.0: {}
|
|
||||||
|
|
||||||
source-map-js@1.2.1: {}
|
source-map-js@1.2.1: {}
|
||||||
|
|
||||||
spdx-correct@3.2.0:
|
spdx-correct@3.2.0:
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
# Security
|
|
||||||
|
|
||||||
# Do not execute any scripts of installed packages (project scripts still run)
|
|
||||||
ignoreDepScripts: true
|
|
||||||
# Do not automatically run pre/post scripts (e.g. preinstall, postbuild)
|
|
||||||
enablePrePostScripts: false
|
|
||||||
# Only allow packages published at least 10 days ago (reduces risk of compromised packages)
|
|
||||||
minimumReleaseAge: 14400
|
|
||||||
# Fail if a package's trust level has decreased compared to previous releases
|
|
||||||
trustPolicy: no-downgrade
|
|
||||||
# Ignore trust policy for packages published more than 1 year ago (predates provenance signing)
|
|
||||||
trustPolicyIgnoreAfter: 525960
|
|
||||||
# Fail if there are missing or invalid peer dependencies
|
|
||||||
strictPeerDependencies: true
|
|
||||||
# Prevent transitive dependencies from using exotic sources (git repos, direct tarball URLs)
|
|
||||||
blockExoticSubdeps: true
|
|
||||||
|
|
||||||
# Lockfile
|
|
||||||
|
|
||||||
# Allow the lockfile to be updated during install (set to true in CI for stricter reproducibility)
|
|
||||||
preferFrozenLockfile: false
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* @copyright nhcarrigan
|
|
||||||
* @license Naomi's Public License
|
|
||||||
* @author Naomi Carrigan
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
ApplicationIntegrationType,
|
|
||||||
SlashCommandBuilder,
|
|
||||||
InteractionContextType,
|
|
||||||
} from "discord.js";
|
|
||||||
|
|
||||||
const command = new SlashCommandBuilder().
|
|
||||||
setContexts(
|
|
||||||
InteractionContextType.BotDM,
|
|
||||||
InteractionContextType.Guild,
|
|
||||||
InteractionContextType.PrivateChannel,
|
|
||||||
).
|
|
||||||
setIntegrationTypes(ApplicationIntegrationType.UserInstall).
|
|
||||||
setName("clear").
|
|
||||||
setDescription("Clear your current adventure so you can start a new one!");
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-console -- We don't need our logger here as this never runs in production.
|
|
||||||
console.log(JSON.stringify(command.toJSON()));
|
|
||||||
+13
-34
@@ -14,14 +14,13 @@ import { personality } from "../config/personality.js";
|
|||||||
import { ai } from "../utils/ai.js";
|
import { ai } from "../utils/ai.js";
|
||||||
import { calculateCost } from "../utils/calculateCost.js";
|
import { calculateCost } from "../utils/calculateCost.js";
|
||||||
import { isSubscribedMessage } from "../utils/isSubscribed.js";
|
import { isSubscribedMessage } from "../utils/isSubscribed.js";
|
||||||
import { logger } from "../utils/logger.js";
|
|
||||||
import type { MessageParam } from "@anthropic-ai/sdk/resources/index.js";
|
import type { MessageParam } from "@anthropic-ai/sdk/resources/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the Discord message event.
|
* Handles the Discord message event.
|
||||||
* @param message - The message payload from Discord.
|
* @param message - The message payload from Discord.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line max-lines-per-function, max-statements, complexity -- We're off by one bloody line.
|
// eslint-disable-next-line max-lines-per-function -- We're off by one bloody line.
|
||||||
export const onMessage = async(message: Message): Promise<void> => {
|
export const onMessage = async(message: Message): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
if (message.channel.type !== ChannelType.DM) {
|
if (message.channel.type !== ChannelType.DM) {
|
||||||
@@ -34,34 +33,22 @@ export const onMessage = async(message: Message): Promise<void> => {
|
|||||||
if (!subbed) {
|
if (!subbed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const historyRequest = await message.channel.messages.fetch({ limit: 20 });
|
const history = await message.channel.messages.fetch({ limit: 6 });
|
||||||
const history = [ ...historyRequest.values() ];
|
const context: Array<MessageParam>
|
||||||
const clearMessageIndex = history.findIndex((messageInner) => {
|
= history.reverse().map((messageInner) => {
|
||||||
return (
|
return {
|
||||||
messageInner.content === "<Clear History>"
|
content: messageInner.content,
|
||||||
&& messageInner.author.id === message.client.user.id
|
role:
|
||||||
);
|
messageInner.author.id === message.client.user.id
|
||||||
|
? "assistant"
|
||||||
|
: "user",
|
||||||
|
};
|
||||||
});
|
});
|
||||||
if (clearMessageIndex !== -1) {
|
|
||||||
// Remove the clear message and everything sent before it, which means everything after in the array because the array is backwards
|
|
||||||
history.splice(clearMessageIndex, history.length - clearMessageIndex);
|
|
||||||
}
|
|
||||||
const context: Array<MessageParam> = history.
|
|
||||||
reverse().
|
|
||||||
map((messageInner) => {
|
|
||||||
return {
|
|
||||||
content: messageInner.content,
|
|
||||||
role:
|
|
||||||
messageInner.author.id === message.client.user.id
|
|
||||||
? "assistant"
|
|
||||||
: "user",
|
|
||||||
};
|
|
||||||
});
|
|
||||||
const messages = await ai.messages.create({
|
const messages = await ai.messages.create({
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Required key format for SDK.
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- Required key format for SDK.
|
||||||
max_tokens: 5000,
|
max_tokens: 3000,
|
||||||
messages: context,
|
messages: context,
|
||||||
model: "claude-sonnet-4-20250514",
|
model: "claude-3-5-sonnet-latest",
|
||||||
system: `${personality} Provide a response to the user that continues the story. The user's name is ${message.author.displayName}`,
|
system: `${personality} Provide a response to the user that continues the story. The user's name is ${message.author.displayName}`,
|
||||||
temperature: 1,
|
temperature: 1,
|
||||||
});
|
});
|
||||||
@@ -74,16 +61,8 @@ export const onMessage = async(message: Message): Promise<void> => {
|
|||||||
response?.text ?? "There was an error. Please try again later.",
|
response?.text ?? "There was an error. Please try again later.",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
await logger.log("info", `No response from AI, here's the payload: ${JSON.stringify(messages)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await calculateCost(messages.usage, message.author.username);
|
await calculateCost(messages.usage, message.author.username);
|
||||||
await logger.metric("messages_processed", 1, { user: message.author.id });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await logger.error("message event", error instanceof Error
|
|
||||||
? error
|
|
||||||
: new Error(String(error)));
|
|
||||||
const button = new ButtonBuilder().
|
const button = new ButtonBuilder().
|
||||||
setLabel("Need help?").
|
setLabel("Need help?").
|
||||||
setStyle(ButtonStyle.Link).
|
setStyle(ButtonStyle.Link).
|
||||||
|
|||||||
@@ -3,11 +3,9 @@
|
|||||||
* @license Naomi's Public License
|
* @license Naomi's Public License
|
||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
|
||||||
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
||||||
import { onMessage } from "./events/message.js";
|
import { onMessage } from "./events/message.js";
|
||||||
import { about } from "./modules/about.js";
|
import { about } from "./modules/about.js";
|
||||||
import { clear } from "./modules/clear.js";
|
|
||||||
import { start } from "./modules/start.js";
|
import { start } from "./modules/start.js";
|
||||||
import { instantiateServer } from "./server/serve.js";
|
import { instantiateServer } from "./server/serve.js";
|
||||||
import { logger } from "./utils/logger.js";
|
import { logger } from "./utils/logger.js";
|
||||||
@@ -34,10 +32,7 @@ const client = new Client({
|
|||||||
partials: [ Partials.Channel ],
|
partials: [ Partials.Channel ],
|
||||||
});
|
});
|
||||||
|
|
||||||
const analytics = new DiscordAnalytics(client, logger);
|
|
||||||
|
|
||||||
client.on(Events.InteractionCreate, (interaction) => {
|
client.on(Events.InteractionCreate, (interaction) => {
|
||||||
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
|
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
switch (interaction.commandName) {
|
switch (interaction.commandName) {
|
||||||
case "about":
|
case "about":
|
||||||
@@ -46,9 +41,6 @@ client.on(Events.InteractionCreate, (interaction) => {
|
|||||||
case "start":
|
case "start":
|
||||||
void start(interaction);
|
void start(interaction);
|
||||||
break;
|
break;
|
||||||
case "clear":
|
|
||||||
void clear(interaction);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
void interaction.reply({
|
void interaction.reply({
|
||||||
content: `I'm sorry, I don't know the ${interaction.commandName} command.`,
|
content: `I'm sorry, I don't know the ${interaction.commandName} command.`,
|
||||||
@@ -73,7 +65,6 @@ client.on(Events.EntitlementDelete, (entitlement) => {
|
|||||||
|
|
||||||
client.on(Events.ClientReady, () => {
|
client.on(Events.ClientReady, () => {
|
||||||
void logger.log("debug", "Bot is ready.");
|
void logger.log("debug", "Bot is ready.");
|
||||||
analytics.startCron();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
instantiateServer();
|
instantiateServer();
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
/**
|
|
||||||
* @copyright nhcarrigan
|
|
||||||
* @license Naomi's Public License
|
|
||||||
* @author Naomi Carrigan
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
MessageFlags,
|
|
||||||
type ChatInputCommandInteraction,
|
|
||||||
} from "discord.js";
|
|
||||||
import { isSubscribedInteraction } from "../utils/isSubscribed.js";
|
|
||||||
import { logger } from "../utils/logger.js";
|
|
||||||
import { replyToError } from "../utils/replyToError.js";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a clear message in the DMs.
|
|
||||||
* @param interaction -- The interaction payload from Discord.
|
|
||||||
*/
|
|
||||||
export const clear = async(
|
|
||||||
interaction: ChatInputCommandInteraction,
|
|
||||||
): Promise<void> => {
|
|
||||||
try {
|
|
||||||
await interaction.deferReply({ flags: [ MessageFlags.Ephemeral ] });
|
|
||||||
|
|
||||||
const subbed = await isSubscribedInteraction(interaction);
|
|
||||||
if (!subbed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const sent = await interaction.user.send({
|
|
||||||
content: "<Clear History>",
|
|
||||||
}).catch(() => {
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
await interaction.editReply({
|
|
||||||
content: sent
|
|
||||||
? "I have added a clear history marker to your DMs."
|
|
||||||
// eslint-disable-next-line stylistic/max-len -- This is a long string.
|
|
||||||
: "I was unable to send you a DM. Please ensure your privacy settings allow direct messages.",
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
await replyToError(interaction);
|
|
||||||
if (error instanceof Error) {
|
|
||||||
await logger.error("about command", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -19,12 +19,8 @@ const html = `<!DOCTYPE html>
|
|||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h1>Becca Lyria</h1>
|
<h1>Becca Lyria</h1>
|
||||||
<img src="https://cdn.nhcarrigan.com/new-avatars/becca-full.png" width="250" alt="Becca" />
|
|
||||||
<section>
|
<section>
|
||||||
<p>Bot to play RPGs on Discord!</p>
|
<p>Bot to play RPGs on Discord!</p>
|
||||||
<a href="https://discord.com/oauth2/authorize?client_id=1343341112437248041" class="social-button discord-button" style="display: inline-block; background-color: #5865F2; color: white; padding: 10px 20px; text-decoration: none; border-radius: 4px; margin: 5px;">
|
|
||||||
<i class="fab fa-discord"></i> Add to Discord
|
|
||||||
</a>
|
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>Links</h2>
|
<h2>Links</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user