CloudyAPI is the central backend service for CloudyAI, built with NestJS. It handles guild configurations, moderation logic, message evaluation, and coordinates between all microservices.
- Guild Configuration Management: Store and retrieve server settings
- Moderation Engine: Evaluate messages and determine sanctions
- Escalation System: Progressive sanctions based on user history
- WebSocket Support: Real-time updates for dashboard
- MongoDB Integration: Persistent storage for configs, logs, and samples
- JWT Authentication: Secure API endpoints
cd CloudyAPI
npm installCreate .env file:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/cloudydb
JWT_SECRET=your-super-secret-jwt-key-change-this
BOT_API_TOKEN=your-bot-api-token-here
# Microservices
CLOUDYMOD_URL=http://localhost:8001
CLOUDYMOD_API_TOKEN=your-cloudymod-token
CLOUDYTRAD_URL=http://localhost:5001
CLOUDYTRAD_API_TOKEN=your-cloudytrad-token# Development
npm run start:dev
# Production
npm run build
npm run start:prodEvaluate a message for violations.
Headers:
Authorization: Bearer your-bot-api-token
Content-Type: application/json
Request:
{
"guildId": "123456789",
"channelId": "987654321",
"messageId": "111222333",
"userId": "444555666",
"username": "User#1234",
"content": "Message text",
"metadata": {
"mentions": 0,
"mentionsEveryone": false,
"roles": 0,
"hasLinks": false
}
}Response:
{
"decision": "WARN",
"violations": [
{
"rule": "AI: toxicity",
"severity": "medium",
"matched": "score: 0.75"
}
],
"reason": "Medium-severity violation",
"confidence": 0.85
}Get guild configuration.
Create/update guild configuration.
Update guild language.
Get sanctions for a guild.
Get sanctions for a specific user.
Health check endpoint.
{
guildId: string;
language: 'en' | 'fr' | 'es' | 'de';
moderation: {
enabled: boolean;
autoDelete: boolean;
mode: 'active' | 'shadow';
filterLinks: boolean;
};
ai: {
enabled: boolean;
provider: 'cloudymod';
threshold: number;
};
escalation: {
enabled: boolean;
};
rules: Array<{
name: string;
type: 'keyword' | 'regex';
value: string;
severity: 'low' | 'medium' | 'high';
active: boolean;
}>;
}{
guildId: string;
userId: string;
action: 'WARN' | 'TIMEOUT' | 'KICK' | 'BAN';
reason: string;
messageId: string;
messageContent: string;
channelId: string;
violations: Array<Violation>;
source: 'automated' | 'manual';
timestamp: Date;
}- Check Configuration: Return early if guild not configured
- AI Analysis: Call CloudyMod if AI enabled
- Custom Rules: Check keyword/regex patterns
- Spam Detection: Detect rapid-fire, repeat, and character spam
- Basic Checks: Links, caps abuse, mention spam
- Escalation: Determine action based on violations + user history
High Severity:
- First offense: KICK
- Repeat offense: BAN
Medium Severity:
- 0-1 offenses: TIMEOUT
- 2-3 offenses: TIMEOUT (longer)
- 4+ offenses: BAN
Low Severity:
- 0-2 offenses: WARN
- 3-4 offenses: TIMEOUT
- 5+ offenses: KICK
- JWT Authentication: User endpoints require JWT tokens
- Bot API Token: Bot requests require
BOT_API_TOKEN - Service Tokens: Calls to CloudyMod/CloudyTrad include API tokens
| Variable | Description | Required |
|---|---|---|
PORT |
Server port | No (default: 3000) |
MONGODB_URI |
MongoDB connection string | Yes |
JWT_SECRET |
JWT signing secret | Yes |
BOT_API_TOKEN |
Bot authentication token | Yes |
CLOUDYMOD_URL |
CloudyMod service URL | Yes |
CLOUDYMOD_API_TOKEN |
CloudyMod API token | Yes |
CLOUDYTRAD_URL |
CloudyTrad service URL | No |
CLOUDYTRAD_API_TOKEN |
CloudyTrad API token | No |
- Verify MongoDB is running
- Check
MONGODB_URIformat - Ensure network connectivity
- Verify services are running
- Check API tokens match
- Test service health endpoints
- Check
escalation.enabledin guild config - Verify logs are being saved to database
- Review past sanctions count