416 lines
13 KiB
Markdown
416 lines
13 KiB
Markdown
|
|
# 📋 DeltaBot Implementation Plan
|
||
|
|
|
||
|
|
**Generated:** October 8, 2025
|
||
|
|
**Based on:** ROADMAP.md analysis and codebase review
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🎯 **Executive Summary**
|
||
|
|
|
||
|
|
This implementation plan addresses the 9 open Alpha issues and provides a structured approach to complete DeltaBot's core functionality. The plan prioritizes immediate blockers, foundational improvements, and then advanced features.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🔥 **Phase 1: Critical Fixes & Foundations**
|
||
|
|
*Estimated Time: 2-3 weeks*
|
||
|
|
|
||
|
|
### **Issue #10 — Post "Reply" (HIGH PRIORITY)**
|
||
|
|
**Problem:** Bot posts new messages instead of replies, breaking conversation flow
|
||
|
|
**Solution:** Implement Discord reply functionality
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
1. **Modify `scheduler/simple.py`:**
|
||
|
|
```python
|
||
|
|
# Instead of: await channel.send(message)
|
||
|
|
# Get recent message and reply to it
|
||
|
|
recent_msgs = [msg async for msg in channel.history(limit=3) if not msg.author.bot]
|
||
|
|
if recent_msgs:
|
||
|
|
await recent_msgs[0].reply(message)
|
||
|
|
else:
|
||
|
|
await channel.send(message)
|
||
|
|
```
|
||
|
|
|
||
|
|
2. **Update `autochat.py`:**
|
||
|
|
```python
|
||
|
|
# In generate_auto_reply function, return reply object instead of string
|
||
|
|
return {"content": reply, "reference": message}
|
||
|
|
```
|
||
|
|
|
||
|
|
3. **Modify `bot.py` message handling:**
|
||
|
|
```python
|
||
|
|
# Handle reply objects properly
|
||
|
|
if isinstance(reply, dict) and reply.get("reference"):
|
||
|
|
await reply["reference"].reply(reply["content"])
|
||
|
|
else:
|
||
|
|
await message.channel.send(reply)
|
||
|
|
```
|
||
|
|
|
||
|
|
**Acceptance Criteria:**
|
||
|
|
- [ ] Scheduled messages reply to recent user messages
|
||
|
|
- [ ] Auto-replies properly thread conversations
|
||
|
|
- [ ] Fallback to regular message when no recent messages exist
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### **Issue #36 — Memory Persistence (HIGH PRIORITY)**
|
||
|
|
**Problem:** No persistent context beyond immediate messages
|
||
|
|
**Solution:** Implement SQLite-based conversation memory
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
1. **Create `memory.py` module:**
|
||
|
|
```python
|
||
|
|
import sqlite3
|
||
|
|
from datetime import datetime, timedelta
|
||
|
|
|
||
|
|
class ConversationMemory:
|
||
|
|
def __init__(self, db_path="data/memory.db"):
|
||
|
|
self.db_path = db_path
|
||
|
|
self.init_db()
|
||
|
|
|
||
|
|
def store_message(self, channel_id, user_id, content, timestamp):
|
||
|
|
# Store message with sentiment analysis
|
||
|
|
|
||
|
|
def get_context(self, channel_id, hours=24, max_messages=50):
|
||
|
|
# Retrieve relevant context
|
||
|
|
|
||
|
|
def get_user_context(self, user_id, days=7):
|
||
|
|
# Get user-specific conversation history
|
||
|
|
```
|
||
|
|
|
||
|
|
2. **Integrate with existing context system:**
|
||
|
|
- Replace `context.py` JSON approach with database queries
|
||
|
|
- Add memory cleanup for old conversations (>30 days)
|
||
|
|
- Include user interaction patterns in memory
|
||
|
|
|
||
|
|
3. **Database Schema:**
|
||
|
|
```sql
|
||
|
|
CREATE TABLE conversations (
|
||
|
|
id INTEGER PRIMARY KEY,
|
||
|
|
channel_id TEXT,
|
||
|
|
user_id TEXT,
|
||
|
|
username TEXT,
|
||
|
|
content TEXT,
|
||
|
|
timestamp DATETIME,
|
||
|
|
sentiment REAL,
|
||
|
|
importance_score REAL
|
||
|
|
);
|
||
|
|
```
|
||
|
|
|
||
|
|
**Acceptance Criteria:**
|
||
|
|
- [ ] Messages stored in SQLite database
|
||
|
|
- [ ] Context retrieval includes conversation history
|
||
|
|
- [ ] Memory cleanup prevents database bloat
|
||
|
|
- [ ] User-specific context tracking
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### **Issue #25 — Enable Modelfile Support (MEDIUM PRIORITY)**
|
||
|
|
**Problem:** Modelfile system partially implemented but not fully functional
|
||
|
|
**Solution:** Complete modelfile integration and testing
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
1. **Fix modelfile loading issues:**
|
||
|
|
- Debug why personality switching doesn't work
|
||
|
|
- Ensure `MODFILE` global variable updates properly
|
||
|
|
- Add validation for modelfile syntax
|
||
|
|
|
||
|
|
2. **Enhance `modelfile.py`:**
|
||
|
|
```python
|
||
|
|
def validate_modfile(modfile_dict):
|
||
|
|
"""Validate modfile has required fields"""
|
||
|
|
required = ['name', 'base_model']
|
||
|
|
return all(key in modfile_dict for key in required)
|
||
|
|
|
||
|
|
def apply_modfile_to_persona(modfile):
|
||
|
|
"""Convert modfile to persona format for compatibility"""
|
||
|
|
return {
|
||
|
|
'name': modfile.get('name'),
|
||
|
|
'prompt_inject': modfile.get('system', ''),
|
||
|
|
'emoji': '🤖', # Default or extract from system prompt
|
||
|
|
'style_prefix': f"{modfile.get('name', 'Bot')}:"
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
3. **Add runtime switching:**
|
||
|
|
- Complete `!modfile switch` command implementation
|
||
|
|
- Add validation and error handling
|
||
|
|
- Test with existing examples (gojo.mod, delta.mod)
|
||
|
|
|
||
|
|
**Acceptance Criteria:**
|
||
|
|
- [ ] Modelfile personality switching works in real-time
|
||
|
|
- [ ] `!modfile info` shows current active modelfile
|
||
|
|
- [ ] Error handling for invalid modelfiles
|
||
|
|
- [ ] Backward compatibility with persona.json
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🚀 **Phase 2: Core Features Enhancement**
|
||
|
|
*Estimated Time: 3-4 weeks*
|
||
|
|
|
||
|
|
### **Issue #17 — Image Generation (HIGH PRIORITY)**
|
||
|
|
**Problem:** No image generation capability
|
||
|
|
**Solution:** Integrate with local Stable Diffusion or external API
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
1. **Create `image_gen.py` module:**
|
||
|
|
```python
|
||
|
|
import requests
|
||
|
|
from io import BytesIO
|
||
|
|
|
||
|
|
class ImageGenerator:
|
||
|
|
def __init__(self):
|
||
|
|
self.api_url = os.getenv("SD_API_URL", "http://localhost:7860")
|
||
|
|
|
||
|
|
async def generate_image(self, prompt, style="anime"):
|
||
|
|
"""Generate image using Stable Diffusion API"""
|
||
|
|
# Implementation for local SD or external service
|
||
|
|
|
||
|
|
def enhance_prompt(self, user_prompt, persona):
|
||
|
|
"""Add persona-specific style to prompts"""
|
||
|
|
return f"{user_prompt}, {persona.get('image_style', 'digital art')}"
|
||
|
|
```
|
||
|
|
|
||
|
|
2. **Add Discord command:**
|
||
|
|
```python
|
||
|
|
@bot.command(name="generate", aliases=["img", "draw"])
|
||
|
|
async def generate_image(ctx, *, prompt):
|
||
|
|
async with ctx.typing():
|
||
|
|
image_data = await image_generator.generate_image(prompt)
|
||
|
|
if image_data:
|
||
|
|
file = discord.File(BytesIO(image_data), "generated.png")
|
||
|
|
await ctx.send(file=file)
|
||
|
|
```
|
||
|
|
|
||
|
|
3. **Integration options:**
|
||
|
|
- **Option A:** Local Stable Diffusion WebUI API
|
||
|
|
- **Option B:** External service (Replicate, HuggingFace)
|
||
|
|
- **Option C:** Simple DALL-E API integration
|
||
|
|
|
||
|
|
**Acceptance Criteria:**
|
||
|
|
- [ ] `!generate <prompt>` command works
|
||
|
|
- [ ] Images posted directly to Discord
|
||
|
|
- [ ] Persona-aware prompt enhancement
|
||
|
|
- [ ] Error handling for generation failures
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### **Issue #16 — Image Interpretation (MEDIUM PRIORITY)**
|
||
|
|
**Problem:** Bot cannot analyze or respond to images
|
||
|
|
**Solution:** Integrate vision model for image understanding
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
1. **Add vision capability to `ai.py`:**
|
||
|
|
```python
|
||
|
|
async def analyze_image(image_url, prompt="Describe this image"):
|
||
|
|
"""Use vision model to analyze images"""
|
||
|
|
# Options: LLaVA, BLIP, or multimodal API
|
||
|
|
|
||
|
|
async def generate_image_response(image_url, context=""):
|
||
|
|
"""Generate contextual response to images"""
|
||
|
|
analysis = await analyze_image(image_url)
|
||
|
|
return get_ai_response(f"Image shows: {analysis}. {context}")
|
||
|
|
```
|
||
|
|
|
||
|
|
2. **Extend message handling in `bot.py`:**
|
||
|
|
```python
|
||
|
|
@bot.event
|
||
|
|
async def on_message(message):
|
||
|
|
# Existing logic...
|
||
|
|
|
||
|
|
# Handle image attachments
|
||
|
|
if message.attachments:
|
||
|
|
for attachment in message.attachments:
|
||
|
|
if attachment.content_type.startswith('image/'):
|
||
|
|
response = await generate_image_response(
|
||
|
|
attachment.url,
|
||
|
|
f"User {message.author.display_name} shared this image"
|
||
|
|
)
|
||
|
|
await message.reply(response)
|
||
|
|
```
|
||
|
|
|
||
|
|
**Acceptance Criteria:**
|
||
|
|
- [ ] Bot responds to image uploads
|
||
|
|
- [ ] Accurate image description capability
|
||
|
|
- [ ] Integration with existing personality system
|
||
|
|
- [ ] Support for memes and screenshots
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### **Issue #22 — Remote Admin Panel (MEDIUM-LOW PRIORITY)**
|
||
|
|
**Problem:** No web interface for bot management
|
||
|
|
**Solution:** Create simple web dashboard
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
1. **Create `admin_panel.py`:**
|
||
|
|
```python
|
||
|
|
from flask import Flask, render_template, request, jsonify
|
||
|
|
import json
|
||
|
|
|
||
|
|
app = Flask(__name__)
|
||
|
|
|
||
|
|
@app.route("/")
|
||
|
|
def dashboard():
|
||
|
|
return render_template("dashboard.html")
|
||
|
|
|
||
|
|
@app.route("/api/settings", methods=["GET", "POST"])
|
||
|
|
def settings_api():
|
||
|
|
# Handle settings updates
|
||
|
|
|
||
|
|
@app.route("/api/users")
|
||
|
|
def users_api():
|
||
|
|
# Return user profiles data
|
||
|
|
```
|
||
|
|
|
||
|
|
2. **Basic dashboard features:**
|
||
|
|
- View active users and interaction stats
|
||
|
|
- Modify bot settings (cooldowns, scheduling)
|
||
|
|
- Switch personalities/modelfiles
|
||
|
|
- View recent conversations
|
||
|
|
- Basic moderation controls
|
||
|
|
|
||
|
|
**Acceptance Criteria:**
|
||
|
|
- [ ] Web interface accessible on local network
|
||
|
|
- [ ] Real-time bot statistics
|
||
|
|
- [ ] Settings modification capability
|
||
|
|
- [ ] Authentication/security for admin access
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🧪 **Phase 3: Advanced Features**
|
||
|
|
*Estimated Time: 4-5 weeks*
|
||
|
|
|
||
|
|
### **Issue #37 — LoRA Support (LOW PRIORITY)**
|
||
|
|
**Problem:** No fine-tuning capability for model behavior
|
||
|
|
**Solution:** Research and implement LoRA model fine-tuning
|
||
|
|
|
||
|
|
**Implementation Notes:**
|
||
|
|
- This is highly technical and may require external tools
|
||
|
|
- Consider if it's necessary for core functionality
|
||
|
|
- Could be postponed to future releases
|
||
|
|
|
||
|
|
### **Issue #26 — Web Usage (MEDIUM PRIORITY)**
|
||
|
|
**Problem:** Bot cannot access web content
|
||
|
|
**Solution:** Add web scraping and API integration
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
1. **Create `web_tools.py`:**
|
||
|
|
```python
|
||
|
|
import requests
|
||
|
|
from bs4 import BeautifulSoup
|
||
|
|
|
||
|
|
class WebTools:
|
||
|
|
async def search_reddit(self, query, subreddit="memes"):
|
||
|
|
"""Search Reddit for content"""
|
||
|
|
|
||
|
|
async def get_news_headlines(self):
|
||
|
|
"""Fetch trending news"""
|
||
|
|
|
||
|
|
async def search_web(self, query):
|
||
|
|
"""DuckDuckGo search integration"""
|
||
|
|
```
|
||
|
|
|
||
|
|
2. **Add web-aware commands:**
|
||
|
|
- `!news` - Get current headlines
|
||
|
|
- `!meme` - Fetch random meme from Reddit
|
||
|
|
- `!search <query>` - Web search with summarized results
|
||
|
|
|
||
|
|
### **Issue #24 — Monetization Setup (LOW PRIORITY)**
|
||
|
|
**Problem:** No monetization framework
|
||
|
|
**Solution:** Add subscription/donation infrastructure
|
||
|
|
|
||
|
|
**Implementation Steps:**
|
||
|
|
- Integration with payment processors
|
||
|
|
- Feature gating for premium users
|
||
|
|
- Usage analytics and billing
|
||
|
|
- **Note:** This should be implemented last after core features are stable
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 📊 **Implementation Priority Matrix**
|
||
|
|
|
||
|
|
| Issue | Priority | Complexity | User Impact | Timeline |
|
||
|
|
|-------|----------|------------|-------------|----------|
|
||
|
|
| #10 Reply Posts | 🔴 High | Low | High | Week 1 |
|
||
|
|
| #36 Memory | 🔴 High | Medium | High | Week 2-3 |
|
||
|
|
| #25 Modelfile | 🟡 Medium | Medium | Medium | Week 4 |
|
||
|
|
| #17 Image Gen | 🟡 Medium | High | High | Week 5-6 |
|
||
|
|
| #16 Image Vision | 🟡 Medium | High | Medium | Week 7-8 |
|
||
|
|
| #22 Admin Panel | 🟢 Low | Medium | Low | Week 9-10 |
|
||
|
|
| #26 Web Usage | 🟢 Low | Medium | Medium | Week 11-12 |
|
||
|
|
| #37 LoRA | 🟢 Low | Very High | Low | Future |
|
||
|
|
| #24 Monetization | 🟢 Low | High | Low | Future |
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🛠 **Technical Recommendations**
|
||
|
|
|
||
|
|
### **Code Quality Improvements:**
|
||
|
|
1. **Add type hints throughout codebase**
|
||
|
|
2. **Implement proper error handling and logging**
|
||
|
|
3. **Create unit tests for core functions**
|
||
|
|
4. **Add configuration validation**
|
||
|
|
5. **Implement proper database migrations**
|
||
|
|
|
||
|
|
### **Infrastructure:**
|
||
|
|
1. **Set up proper logging and monitoring**
|
||
|
|
2. **Add health check endpoints**
|
||
|
|
3. **Implement graceful shutdown handling**
|
||
|
|
4. **Add backup/restore functionality**
|
||
|
|
|
||
|
|
### **Security:**
|
||
|
|
1. **Sanitize user inputs**
|
||
|
|
2. **Add rate limiting**
|
||
|
|
3. **Implement proper secret management**
|
||
|
|
4. **Add CORS and authentication for admin panel**
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 📈 **Success Metrics**
|
||
|
|
|
||
|
|
### **Phase 1 Success Criteria:**
|
||
|
|
- [ ] Bot reliably replies to messages (not new posts)
|
||
|
|
- [ ] Persistent conversation memory working
|
||
|
|
- [ ] Modelfile switching functional
|
||
|
|
- [ ] Zero critical bugs in core functionality
|
||
|
|
|
||
|
|
### **Phase 2 Success Criteria:**
|
||
|
|
- [ ] Image generation and analysis working
|
||
|
|
- [ ] Admin panel accessible and functional
|
||
|
|
- [ ] User engagement increased by 20%
|
||
|
|
- [ ] System stable with multiple concurrent users
|
||
|
|
|
||
|
|
### **Phase 3 Success Criteria:**
|
||
|
|
- [ ] Web integration providing value
|
||
|
|
- [ ] Advanced features enhance user experience
|
||
|
|
- [ ] Bot ready for production deployment
|
||
|
|
- [ ] Documentation complete for self-hosting
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 🚦 **Next Actions**
|
||
|
|
|
||
|
|
### **Week 1 - Immediate Steps:**
|
||
|
|
1. **Fix Issue #10** - Implement reply functionality
|
||
|
|
2. **Start Issue #36** - Set up memory database schema
|
||
|
|
3. **Test current modelfile system** - Identify specific issues with #25
|
||
|
|
4. **Set up development environment** with proper logging and debugging
|
||
|
|
|
||
|
|
### **Week 2 - Foundation Building:**
|
||
|
|
1. **Complete memory system implementation**
|
||
|
|
2. **Fix modelfile personality switching**
|
||
|
|
3. **Add comprehensive error handling**
|
||
|
|
4. **Create basic test suite**
|
||
|
|
|
||
|
|
### **Beyond Week 2:**
|
||
|
|
- Follow the priority matrix above
|
||
|
|
- Regular testing and user feedback integration
|
||
|
|
- Incremental feature rollouts
|
||
|
|
- Performance optimization as needed
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
**📝 Note:** This plan assumes development time of 10-15 hours per week. Adjust timelines based on actual availability and complexity discovered during implementation.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
*Last updated: October 8, 2025*
|