Skip to content

Commit 5bd4ace

Browse files
authored
Merge pull request #5 from musarrat950/debugbranch
Fixing major and critical bugs, adding more support to the plug-in system, and improving a lot of ways to introduce a much more centralized way of developing plugins
2 parents 35ff513 + c300190 commit 5bd4ace

42 files changed

Lines changed: 4447 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Holo Bridge - Environment Variables
1+
# HoloBridge - Environment Configuration
22

33
# Discord Bot Token (required)
44
# Get this from https://discord.com/developers/applications
@@ -8,5 +8,18 @@ DISCORD_TOKEN=your_discord_bot_token_here
88
PORT=3000
99
API_KEY=your_secure_api_key_here
1010

11-
# Optional: Enable debug logging
11+
# Optional: Multiple API keys with scopes (JSON array)
12+
# API_KEYS=[{"id":"key1","name":"Read Only","key":"readonly_key","scopes":["read:guilds","read:messages"]}]
13+
14+
# Plugin System
15+
PLUGINS_ENABLED=true
16+
PLUGINS_DIR=plugins
17+
18+
# Rate Limiting
19+
RATE_LIMIT_ENABLED=true
20+
RATE_LIMIT_WINDOW_MS=60000
21+
RATE_LIMIT_MAX=100
22+
23+
# Debug Mode
1224
DEBUG=false
25+

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Stage 1: Build
2+
FROM node:18-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy package files
7+
COPY package*.json ./
8+
9+
# Install all dependencies (including dev for building)
10+
RUN npm ci
11+
12+
# Copy source code
13+
COPY . .
14+
15+
# Build TypeScript
16+
RUN npm run build
17+
18+
# Stage 2: Production
19+
FROM node:18-alpine
20+
21+
WORKDIR /app
22+
23+
# Copy built files from builder
24+
COPY --from=builder /app/dist ./dist
25+
COPY --from=builder /app/package*.json ./
26+
27+
# Install production dependencies only
28+
RUN npm ci --production
29+
30+
# Create plugins directory
31+
RUN mkdir -p plugins
32+
33+
# Install wget for healthcheck
34+
RUN apk add --no-cache wget
35+
36+
# Expose API port
37+
EXPOSE 3000
38+
39+
# Health check
40+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
41+
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
42+
43+
# Run the application
44+
CMD ["npm", "start"]

README.md

Lines changed: 132 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,127 @@
1-
# Holo Bridge
1+
# HoloBridge
22

3-
A type-safe TypeScript bridge between websites and Discord bots. Provides a REST API and WebSocket interface for full Discord bot capabilities.
3+
A type-safe TypeScript bridge between websites and Discord bots. Provides a REST API, WebSocket interface, and plugin system for full Discord bot capabilities.
44

55
## Features
66

77
- **REST API** for all Discord operations
88
- **WebSocket** real-time event streaming
9+
- **Plugin System** for extensibility
10+
- **Granular API Scopes** for secure access control
11+
- **Rate Limiting** for API protection
12+
- **CLI Tool** for easy management
13+
- **Docker Ready** for easy deployment
914
- **Type-safe** with Zod validation
10-
- **Full Discord.js coverage**:
11-
- Guilds, Channels, Roles
12-
- Members, Bans, Timeouts
13-
- Messages, Reactions, Pins
14-
- Voice state tracking
15-
- And more...
1615

1716
## Quick Start
1817

19-
### 1. Install Dependencies
18+
### Option 1: Using the CLI
2019

2120
```bash
21+
# Install globally
22+
npm install -g holobridge
23+
24+
# Initialize configuration
25+
holo init
26+
27+
# Check your setup
28+
holo doctor
29+
30+
# Start the server
31+
holo start
32+
```
33+
34+
### Option 2: Manual Setup
35+
36+
```bash
37+
# Install dependencies
2238
npm install
39+
40+
# Copy environment file
41+
cp .env.example .env
42+
# Edit .env with your Discord token and API key
43+
44+
# Build and run
45+
npm run build
46+
npm start
47+
```
48+
49+
### Option 3: Docker
50+
51+
```bash
52+
# Using Docker Compose
53+
docker-compose up -d
54+
55+
# Or build manually
56+
docker build -t holobridge .
57+
docker run -p 3000:3000 --env-file .env holobridge
2358
```
2459

25-
### 2. Configure Environment
60+
## Configuration
2661

27-
Copy `.env.example` to `.env` and fill in your values:
62+
Copy `.env.example` to `.env` and configure:
2863

2964
```env
65+
# Required
3066
DISCORD_TOKEN=your_discord_bot_token
3167
API_KEY=your_secure_api_key
68+
69+
# Optional
3270
PORT=3000
71+
DEBUG=false
72+
PLUGINS_ENABLED=true
73+
RATE_LIMIT_ENABLED=true
74+
RATE_LIMIT_MAX=100
3375
```
3476

35-
### 3. Run
77+
### Multiple API Keys with Scopes
3678

37-
```bash
38-
# Development
39-
npm run dev
79+
For granular access control, use the `API_KEYS` environment variable:
4080

41-
# Production
42-
npm run build
43-
npm start
81+
```env
82+
API_KEYS=[{"id":"readonly","name":"Dashboard","key":"dash_xxx","scopes":["read:guilds","read:messages"]}]
83+
```
84+
85+
**Available Scopes:**
86+
- `read:guilds`, `read:channels`, `read:members`, `read:messages`
87+
- `write:messages`, `write:members`, `write:channels`, `write:roles`
88+
- `events` (WebSocket access)
89+
- `admin` (full access)
90+
91+
## Plugin System
92+
93+
Extend HoloBridge with custom plugins. Create `.js` files in the `plugins/` directory:
94+
95+
```javascript
96+
export default {
97+
metadata: {
98+
name: 'my-plugin',
99+
version: '1.0.0',
100+
},
101+
102+
onLoad(ctx) {
103+
ctx.log('Plugin loaded!');
104+
// ctx.client - Discord.js Client
105+
// ctx.io - Socket.IO Server
106+
},
107+
108+
onEvent(eventName, data) {
109+
if (eventName === 'messageCreate') {
110+
// React to messages
111+
}
112+
},
113+
};
114+
```
115+
116+
See [plugins/README.md](plugins/README.md) for full documentation.
117+
118+
## CLI Commands
119+
120+
```bash
121+
holo start # Start the server
122+
holo start --watch # Development mode with hot reload
123+
holo doctor # Check configuration and environment
124+
holo init # Interactive setup wizard
44125
```
45126

46127
## API Reference
@@ -53,6 +134,13 @@ All API requests require the `X-API-Key` header:
53134
curl -H "X-API-Key: your_key" http://localhost:3000/api/guilds
54135
```
55136

137+
### Rate Limiting
138+
139+
Responses include rate limit headers:
140+
- `X-RateLimit-Limit` - Max requests per window
141+
- `X-RateLimit-Remaining` - Requests remaining
142+
- `X-RateLimit-Reset` - Unix timestamp when limit resets
143+
56144
### REST Endpoints
57145

58146
| Method | Endpoint | Description |
@@ -68,6 +156,7 @@ curl -H "X-API-Key: your_key" http://localhost:3000/api/guilds
68156
| `POST` | `/api/channels/:id/messages` | Send message |
69157
| `PATCH` | `/api/channels/:id/messages/:msgId` | Edit message |
70158
| `DELETE` | `/api/channels/:id/messages/:msgId` | Delete message |
159+
| `GET` | `/health` | Health check (no auth) |
71160

72161
### WebSocket Events
73162

@@ -80,33 +169,48 @@ const socket = io('http://localhost:3000', {
80169
auth: { apiKey: 'your_key' }
81170
});
82171

83-
// Subscribe to guild events
84172
socket.emit('subscribe', { guildIds: ['123456789'] });
85173

86-
// Listen for Discord events
87174
socket.on('discord', (event) => {
88175
console.log(event.event, event.data);
89176
});
90177
```
91178

92-
**Events:** `messageCreate`, `messageUpdate`, `messageDelete`, `guildMemberAdd`, `guildMemberRemove`, `voiceStateUpdate`, and more.
179+
**Supported Events (45+):** Messages, Reactions, Members, Channels, Threads, Roles, Guilds, Emojis, Voice, Scheduled Events, AutoMod, Invites, Interactions, and more.
93180

94181
## Discord Bot Setup
95182

96183
1. Go to [Discord Developer Portal](https://discord.com/developers/applications)
97-
2. Create a new application
98-
3. Go to Bot section and create a bot
99-
4. Enable these **Privileged Gateway Intents**:
184+
2. Create a new application and bot
185+
3. Enable **ALL Privileged Gateway Intents**:
100186
- Presence Intent
101187
- Server Members Intent
102188
- Message Content Intent
103-
5. Copy the token to your `.env` file
104-
6. Invite the bot to your server with appropriate permissions
189+
4. Copy the token to your `.env` file
190+
5. Invite the bot with `Administrator` permissions
105191

106-
## Documentation
192+
## Project Structure
107193

108-
Visit the [documentation](https://holodocs.pages.dev/) for more details.
194+
```
195+
holobridge/
196+
├── bin/holo.js # CLI tool
197+
├── plugins/ # Plugin directory
198+
├── src/
199+
│ ├── api/ # REST API routes & middleware
200+
│ ├── discord/ # Discord client & events
201+
│ ├── plugins/ # Plugin manager
202+
│ └── types/ # TypeScript types
203+
├── Dockerfile # Docker build
204+
└── docker-compose.yml # Docker Compose config
205+
```
206+
207+
## Resources
208+
209+
- [Use Cases](USE_CASES.md) - Creative ways to use HoloBridge
210+
- [Plugin Guide](plugins/README.md) - How to build plugins
211+
- [Documentation](https://holodocs.pages.dev/) - Full API docs
109212

110213
## License
111214

112215
MIT
216+

0 commit comments

Comments
 (0)