* Initial plan * Add plugin system core infrastructure with API, examples, and tests Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Integrate plugin system with bot and API server Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Add plugin system to README and configure linting Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Fix type safety in PluginLoader (code review feedback) Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Update backend/plugins/template/index.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> Co-authored-by: ⓪ηηωεε忧世 <onnweexd@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Plugin Template
This is a template for creating SpyWatcher plugins.
Quick Start
-
Copy this template directory to a new plugin directory:
cp -r backend/plugins/template backend/plugins/my-plugin -
Edit
manifest.json:- Change
idto your plugin's unique identifier - Update
name,author, anddescription - Add required
permissions
- Change
-
Edit
index.js:- Implement your plugin logic
- Add hooks for events you want to monitor
- Register API routes if needed
-
Test your plugin:
# Restart SpyWatcher to load the plugin npm run dev:api
Plugin Structure
my-plugin/
├── manifest.json # Plugin metadata and permissions
├── index.js # Plugin implementation
├── README.md # Plugin documentation
└── package.json # Optional: if you need npm dependencies
Available Permissions
Choose the permissions your plugin needs:
discord:client- Access Discord bot clientdiscord:events- Listen to Discord eventsapi:routes- Register API routesapi:middleware- Register Express middlewaredatabase:access- Access Prisma databasecache:access- Access Redis cachewebsocket:access- Access WebSocket servicemonitoring:access- Access monitoring/metricsfs:access- File system access (restricted to plugin data dir)network:access- Make HTTP requests
Plugin Lifecycle
- init() - Plugin is loaded and initialized
- start() - Plugin begins operation (optional)
- running - Plugin is active and processing events
- stop() - Plugin stops operation (optional)
- destroy() - Plugin is unloaded and cleaned up
Hooks
Available event hooks:
Discord Hooks
discord:ready- Bot is readydiscord:presenceUpdate- User presence changeddiscord:messageCreate- New messagediscord:guildMemberAdd- Member joineddiscord:guildMemberRemove- Member left
Analytics Hooks
analytics:beforeCalculate- Before analytics calculationanalytics:afterCalculate- After analytics calculation
API Hooks
api:request- API request receivedapi:response- API response sent
WebSocket Hooks
websocket:connect- Client connectedwebsocket:disconnect- Client disconnected
Testing
Create tests for your plugin:
// test/plugin.test.js
const plugin = require('../index.js');
describe('My Plugin', () => {
it('should initialize', async () => {
const context = createMockContext();
await plugin.init(context);
expect(context.logger.info).toHaveBeenCalled();
});
});
Documentation
Document your plugin:
- What it does
- How to install it
- Configuration options
- API endpoints (if any)
- Example usage
Publishing
To share your plugin:
- Publish to npm or GitHub
- Include installation instructions
- Add examples and documentation
- Test with different SpyWatcher versions
Support
For questions: