Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

517 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Aszune AI Bot (v1.11.0)

CI/CD Codecov Maintainability License Tests

Release Notes | Dashboard Overview | Documentation Wiki

Aszune AI Bot is a professional Discord bot that combines advanced AI conversation capabilities with comprehensive analytics and monitoring features. Built for gaming communities, it provides lore, guides, and advice using the Perplexity API's sonar model while offering real-time performance dashboards and server analytics directly within Discord.

Key Features

  • πŸ€– AI-Powered Conversations - Context-aware chat using Perplexity API's sonar model
  • πŸ“Š Web Dashboard - Real-time monitoring with logs, services, network status, and configuration
  • ⏰ Smart Reminders - Natural language reminder scheduling with Discord notifications
  • πŸ“ˆ Analytics - Server analytics, user engagement metrics, and performance monitoring
  • πŸ“ Raspberry Pi Optimized - Specialized optimizations for resource-constrained devices

Current Status: 1,700+ tests passing – 70%+ coverage thresholds

Table of Contents


Features

  • πŸ•’ Rate Limiting: Prevents users from spamming the bot by enforcing a short cooldown between messages.
  • πŸ“ Help Command: /help - list all available commands and usage
  • 🧾 Conversation Summary: /summary - generate a summary of your current conversation
  • πŸ“ Text Summarisation: /summarise <text> - summarise any provided text
  • πŸ†• Stats Tracking: /stats - view your usage statistics
  • ⏰ Reminder System: /remind, /reminders, /cancelreminder - AI-powered natural language reminders
  • πŸ“Š Analytics: /analytics, /dashboard, /resources, /cache - comprehensive monitoring
  • πŸ‘€ User Info: /userinfo [user] - detailed user information with badges, roles, and activity
  • 🏠 Server Info: /serverinfo - comprehensive server statistics and features
  • πŸ‡¬πŸ‡§ UK English Responses: All bot replies use UK English spelling and phrasing
  • πŸ“‹ Slash Command Support: All commands available as modern Discord slash commands
  • πŸ§ͺ Comprehensive Testing: 1,800+ tests with 70%+ coverage on critical components
  • 🌐 Web Dashboard: Optional Express + Socket.io dashboard with live metrics
  • πŸ’Ύ Persistent Storage: SQLite database for conversation history and user analytics
  • πŸ“ Raspberry Pi Optimised: Specialised performance optimisations for Pi 3 to Pi 5 (primary deployment target: Pi 5)
  • πŸ›‘οΈ Code Quality: QLTY integration with 94.8% ESLint fix rate and systematic complexity reduction

Web Dashboard

The web dashboard provides comprehensive monitoring and management:

  • Real-Time Log Viewer: Live log streaming with filtering, search, and export
  • Service Status: Monitor and control services (PM2 for the bot; systemd where available)
  • Configuration Editor: Safe .env and config.js editing with validation
  • Network Status: Interface monitoring, connectivity checks, public IP detection
  • Reminder Management: Create, view, edit, and manage reminders via web UI

Access: http://localhost:3000 while the bot is running

For detailed API reference and technical specifications, see DASHBOARD-API-REFERENCE-v1.9.0.md.


Installation

Prerequisites

Setup Steps

  1. Clone the repository

    git clone https://github.com/powerfulqa/aszune-ai-bot.git
    cd aszune-ai-bot
  2. Install dependencies

    npm install
  3. Create a .env file

    DISCORD_BOT_TOKEN=your_discord_bot_token_here
    PERPLEXITY_API_KEY=your_perplexity_api_key_here
  4. Database Setup (Automatic)

    The bot automatically creates and manages a SQLite database:

    • Auto-created: Database file created automatically on first run
    • Location: ./data/bot.db (configurable via DB_PATH)
    • No manual setup required: The bot handles all database initialization

Usage

Running the Bot Manually

node src/index.js

You should see:

Discord bot is online!

Your bot should now appear online in your Discord server.

Running on Raspberry Pi (recommended: Pi 5)

For optimal performance on Raspberry Pi, use the provided script:

# Make the script executable
chmod +x start-pi-optimized.sh

# Run with optimisations
./start-pi-optimized.sh

This script applies several performance optimisations:

  • Sets memory limits appropriate for your Pi model
  • Reduces CPU and memory usage
  • Optimises network connections
  • Configures compact mode for responses

For more details on Pi optimisations, see the Raspberry Pi Optimisation Guide.


Running with PM2 (for Production & Raspberry Pi)

PM2 keeps the bot alive in the background and restarts it on crashes or reboots.

Recommended: Using the Pi Optimisation Shell Script

To run the bot with full Raspberry Pi optimisations, use the provided shell script to apply Pi settings and start PM2 using ecosystem.config.js:

sudo ./start-pi-optimized.sh

pm2 startup
pm2 save

This ensures all Pi-specific environment variables and system-level tweaks are applied before starting the bot, and enables automatic restart after a reboot.

Note: Running pm2 start src/index.js will NOT apply Pi optimisations.


Web Dashboard Access

  • Access: http://localhost:3000 while the bot is running
  • Details: see wiki/Dashboard-Features-Complete.md (feature overview) and docs/DASHBOARD-API-REFERENCE-v1.9.0.md (API reference)

Bot Commands

Core Commands

Command Description
/help Shows a list of available commands and usage
/clearhistory Clears your conversation history
/summary Summarises your current conversation in UK English
/summarise <text> Summarises any provided text in UK English
/stats Shows your usage stats (messages sent, summaries requested)

Utility Commands (NEW in v1.11.0)

Command Description
/userinfo Display detailed information about a user
/serverinfo Display detailed information about the current server

Reminder Commands (NEW in v1.7.0)

Command Description
/remind Set a reminder with natural language time parsing
/reminders List all your active reminders
/cancelreminder Cancel a specific reminder by ID

Analytics Commands (NEW in v1.6.0)

Command Description
/analytics Show Discord server analytics and performance insights
/dashboard Display comprehensive performance dashboard with real-time data
/resources View resource optimisation status and recommendations
/cache Display cache statistics and performance metrics (Fixed v1.6.5)

Note: All commands are available as modern Discord slash commands.


Analytics & Monitoring

πŸ“Š Real-time Discord Analytics

Version 1.6.0 introduces comprehensive analytics accessible directly within Discord:

/analytics - Real-time Discord Server Analytics

  • Live Member Data: Real Discord server statistics with timeout protection (v1.6.1)
  • Active User Counts: Live online/idle/dnd member filtering (e.g., "Active Users: 102")
  • Server Statistics: Total members, bot counts, human member ratios
  • Presence Detection: Real-time member activity status from Discord API
  • Fallback Protection: Intelligent estimates when Discord API is slow or unavailable

/dashboard - Synchronized Performance Monitoring

  • Consistent Data: Same Discord member counts as /analytics for reliability (v1.6.1)
  • System Metrics: Real-time CPU, memory, and network utilization
  • Performance Correlation: System load analysis with actual Discord server activity
  • Resource Optimization: Performance recommendations based on real usage patterns
  • Timeout Protection: 5-second response guarantee with graceful fallbacks

/resources - Resource Optimization

  • Resource Analysis: Detailed system resource usage and optimization opportunities
  • Performance Recommendations: Automated suggestions for improving bot performance
  • Capacity Planning: Usage projections and scaling recommendations
  • System Health: Comprehensive health assessments and maintenance guidance

/cache - Cache Statistics (Fixed v1.6.5)

  • Performance Metrics: Hit rate, cache hits/misses, operation counts
  • Memory Usage: Current cache memory usage and limits (e.g., "0 B / 50 MB")
  • Configuration: Eviction strategy and uptime information (e.g., "Strategy: hybrid, Uptime: 28s")
  • Operations Tracking: Sets, deletes, evictions statistics
  • Complete Field Coverage: All statistics display proper values (no more "undefined")

πŸ“ˆ Benefits

  • No External Tools Required: All monitoring accessible within Discord
  • Proactive Management: Early warning system for issues
  • Data-Driven Decisions: Usage analytics for community optimization
  • Cost Reduction: Eliminates need for third-party monitoring services
  • Complete Control: Self-hosted solution with full data ownership

Project Structure

aszune-ai-bot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.js                    # Main entry point
β”‚   β”œβ”€β”€ commands/                   # Command handlers (slash commands only)
β”‚   β”‚   β”œβ”€β”€ index.js               # Unified command handler
β”‚   β”‚   └── reminder.js             # Reminder command handler
β”‚   β”œβ”€β”€ config/                     # Configuration settings
β”‚   β”‚   └── config.js              # Global configuration
β”‚   β”œβ”€β”€ services/                   # API and core services
β”‚   β”‚   β”œβ”€β”€ api-client.js           # HTTP requests and API communication
β”‚   β”‚   β”œβ”€β”€ cache-manager.js        # Response caching and cleanup management
β”‚   β”‚   β”œβ”€β”€ chat.js                 # Chat message handler
β”‚   β”‚   β”œβ”€β”€ database.js             # SQLite database service with reminder support
β”‚   β”‚   β”œβ”€β”€ perplexity-secure.js    # Perplexity API service
β”‚   β”‚   β”œβ”€β”€ reminder-service.js     # Reminder scheduling and management
β”‚   β”‚   β”œβ”€β”€ response-processor.js   # API response processing and formatting
β”‚   β”‚   β”œβ”€β”€ storage.js              # Data storage service
β”‚   β”‚   └── throttling-service.js   # Rate limiting and connection throttling
β”‚   └── utils/                      # Utility functions and helpers
β”‚       β”œβ”€β”€ cache-pruner.js        # Cache cleanup utilities
β”‚       β”œβ”€β”€ connection-throttler.js # Connection throttling
β”‚       β”œβ”€β”€ conversation.js        # Conversation management
β”‚       β”œβ”€β”€ debouncer.js           # Function debouncing
β”‚       β”œβ”€β”€ discord-analytics.js   # Discord analytics utilities
β”‚       β”œβ”€β”€ emoji.js               # Emoji processing
β”‚       β”œβ”€β”€ enhanced-cache.js      # Enhanced caching
β”‚       β”œβ”€β”€ enhanced-conversation-context.js # Conversation context
β”‚       β”œβ”€β”€ error-handler.js       # Error handling utilities
β”‚       β”œβ”€β”€ input-validator.js     # Input validation and sanitization
β”‚       β”œβ”€β”€ lazy-loader.js         # Lazy loading utilities
β”‚       β”œβ”€β”€ logger.js              # Logging utilities
β”‚       β”œβ”€β”€ memory-monitor.js      # Memory monitoring and GC
β”‚       β”œβ”€β”€ message-chunker.js     # Message chunking
β”‚       β”œβ”€β”€ message-chunking/      # Enhanced chunking system
β”‚       β”‚   β”œβ”€β”€ index.js           # Main chunking coordinator
β”‚       β”‚   β”œβ”€β”€ chunk-boundary-handler.js
β”‚       β”‚   β”œβ”€β”€ source-reference-processor.js
β”‚       β”‚   └── url-formatter.js
β”‚       β”œβ”€β”€ message-formatter.js   # Message formatting
β”‚       β”œβ”€β”€ natural-language-reminder.js # AI-powered reminder detection
β”‚       β”œβ”€β”€ performance-dashboard.js # Performance dashboard
β”‚       β”œβ”€β”€ performance-monitor.js # Performance tracking
β”‚       β”œβ”€β”€ performance-tracker.js # Performance metrics
β”‚       β”œβ”€β”€ pi-detector.js         # Raspberry Pi detection
β”‚       β”œβ”€β”€ resource-optimizer.js  # Resource optimization
β”‚       β”œβ”€β”€ security-monitor.js    # Security monitoring
β”‚       β”œβ”€β”€ testUtils.js           # Test utilities
β”‚       └── time-parser.js         # Advanced time parsing for reminders
β”œβ”€β”€ data/                           # Persistent data storage
β”‚   β”œβ”€β”€ bot.db                     # SQLite database (auto-created)
β”‚   β”œβ”€β”€ question_cache.json        # Response cache
β”‚   β”œβ”€β”€ test.db                    # Test database
β”‚   └── user_stats.json            # User statistics (legacy)
β”œβ”€β”€ docs/                          # Version-specific documentation
β”œβ”€β”€ scripts/                       # Development and utility scripts
β”‚   β”œβ”€β”€ check-triggers.js          # Database trigger validation
β”‚   β”œβ”€β”€ fix-line-endings.ps1       # Line ending normalization
β”‚   β”œβ”€β”€ fix-production.bat         # Production fix utilities
β”‚   β”œβ”€β”€ format-code.ps1            # Code formatting scripts
β”‚   β”œβ”€β”€ run-tests.bat              # Test execution scripts
β”‚   β”œβ”€β”€ start-test.bat             # Test environment setup
β”‚   └── README.md                  # Scripts documentation
β”œβ”€β”€ wiki/                          # Comprehensive documentation
β”œβ”€β”€ __tests__/                     # Test suites
β”‚   β”œβ”€β”€ integration/               # Integration tests
β”‚   β”œβ”€β”€ unit/                      # Unit tests
β”‚   └── utils/                     # Test utilities
β”œβ”€β”€ __mocks__/                     # Test mocks
β”œβ”€β”€ coverage/                      # Code coverage reports
β”œβ”€β”€ test-results/                  # Test result outputs
β”œβ”€β”€ logs/                          # Application logs
β”œβ”€β”€ .qlty/                         # Code quality configuration
β”‚   β”œβ”€β”€ qlty.toml                 # Main qlty configuration
β”‚   └── configs/                   # Tool-specific configurations
β”œβ”€β”€ .github/                       # GitHub configuration
β”œβ”€β”€ .cursor/                       # Cursor IDE configuration
β”œβ”€β”€ package.json                   # Project metadata
β”œβ”€β”€ ecosystem.config.js            # PM2 deployment config
β”œβ”€β”€ jest.config.js                 # Jest test configuration
β”œβ”€β”€ jest.setup.js                  # Jest setup file
β”œβ”€β”€ .prettierrc                    # Prettier configuration
β”œβ”€β”€ .eslintrc.json                 # ESLint configuration
β”œβ”€β”€ .env.example                   # Environment variables example
β”œβ”€β”€ SECURITY.md                    # Security policy and guidelines
β”œβ”€β”€ CONTRIBUTING.md                # Contribution guidelines
β”œβ”€β”€ CODE_OF_CONDUCT.md             # Community code of conduct
β”œβ”€β”€ CHANGELOG.md                   # Project changelog
β”œβ”€β”€ LICENSE                        # License file
└── .env                           # Environment secrets (not committed)

Code Quality

This project maintains high code quality standards using qlty for unified linting, formatting, security scanning, and maintainability analysis.

Quality Standards

  • Test Coverage: 1,708+ tests passing – dual thresholds: β‰₯80% critical files / β‰₯65% global baseline
  • Code Quality: 94.8% reduction in ESLint issues with systematic complexity reduction
  • Security: Zero tolerance for secrets, timing-safe authentication, vulnerability scanning
  • Code Complexity: Max 15 complexity per file, 10 per function
  • Formatting: Consistent code style with Prettier

Running Quality Checks

npm run quality:check    # Quick quality check
npm run quality:fix      # Auto-fix formatting and linting
npm run quality:metrics  # View code metrics and complexity
npm run quality:smells   # Detect code smells and duplication
npm run security:all     # Full security scanning

For detailed information, see docs/qlty/README.md.


Testing & Coverage

npm test                    # Run all tests
npm run coverage            # Run tests with coverage report
npm run test:branch-coverage # Run branch coverage tests

The test suite includes:

  • Unit tests for all service modules
  • Integration tests for bot functionality
  • Database integration tests
  • Branch coverage tests for critical components

For detailed testing information, see Testing Guide.

Live coverage metrics are maintained in docs/COVERAGE-STATUS.md.


CI/CD Pipeline

The project uses GitHub Actions for continuous integration and deployment. The pipeline:

  1. Builds the application
  2. Runs all tests with coverage reporting
  3. Performs security checks using npm audit
  4. Uploads coverage data to Codecov and QLTY
  5. Prepares for deployment when merging to main branch

View the CI/CD workflow in .github/workflows/unified-ci.yml


Troubleshooting

πŸ”΄ Bot Offline or Invalid Token

  • Double-check your DISCORD_BOT_TOKEN in .env
  • Confirm the token has not been regenerated or revoked
  • Ensure your bot has permission to join and read messages in your server

πŸ”΄ Perplexity API Errors (400 / 401)

  • Validate your API key is current and supports the chat/completions endpoint
  • Ensure model name is "sonar" and the format of your payload is correct
  • Test the same key using a tool like Postman or curl

Future Enhancements

  • Add clickable sources and reference links from Perplexity results
  • Enhance error handling with retry/backoff logic for API rate limits
  • Implement AI-powered content moderation for safer interactions

Contributing

Pull requests and ideas are always welcome! Please:

  1. Fork the repository
  2. Create a new branch
  3. Submit a PR with your changes

License

Source Available - All Rights Reserved

What this means:

  • βœ… View & Learn β€” You can read, study, and learn from this code
  • ❌ No Copying β€” You cannot clone, fork, or download this repository
  • ❌ No Use β€” You cannot use this code in your own projects
  • ❌ No Distribution β€” You cannot share or redistribute this code
  • ❌ No Running β€” You cannot deploy or run this software

Want to use this code?

All uses beyond viewing require explicit written permission. To request permission:

  1. Open an issue on GitHub
  2. Describe your intended use
  3. Wait for approval from the copyright holder

Permission is granted at my sole discretion.

πŸ“„ View Full License Terms


Made for the Aszune community. Powered by Discord, Perplexity, and Node.js.

Changelog

See CHANGELOG.md for full version history.

For detailed release notes:

  • v1.11.0 - Enhanced Utility Commands (/userinfo, /serverinfo)
  • v1.10.0 - Code Quality & Documentation Cleanup
  • v1.9.0 - Dashboard Enhancements
  • v1.8.0 - Web Dashboard
  • v1.7.0 - Database & Reminders

About

Aszai is an AI chat bot that utilises Perplexity as its AI driver and discord as its output.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages