discord-bots-manager 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +150 -0
- package/dist/BotProcess.d.ts +26 -0
- package/dist/BotProcess.d.ts.map +1 -0
- package/dist/BotProcess.js +140 -0
- package/dist/BotProcess.js.map +1 -0
- package/dist/Manager.d.ts +21 -0
- package/dist/Manager.d.ts.map +1 -0
- package/dist/Manager.js +82 -0
- package/dist/Manager.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 discord-bot-manager
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# discord-bot-manager
|
|
2
|
+
|
|
3
|
+
Spawn, monitor, and manage multiple Discord bot processes from a single Node.js process.
|
|
4
|
+
|
|
5
|
+
Each bot runs in its own isolated child process (`child_process.fork`), so a crash in one bot never affects the others. The manager handles auto-restarts, IPC communication, and graceful shutdown.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Multi-process isolation** — each bot is a separate OS process
|
|
10
|
+
- **Auto-restart** — configurable delay and max retry count
|
|
11
|
+
- **IPC** — send messages between the manager and any bot process
|
|
12
|
+
- **Lifecycle events** — `start`, `ready`, `crash`, `restart`, `stop`, `error`
|
|
13
|
+
- **Graceful shutdown** — sends `shutdown` message, then SIGKILL after 5s timeout
|
|
14
|
+
- **Status reporting** — query PID, status, uptime, and restart count per bot
|
|
15
|
+
- **TypeScript** — full type declarations included
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install discord-bot-manager
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
> **Peer dependency:** requires `discord.js@^14`
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### Manager (index.js)
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { Manager } from 'discord-bot-manager'
|
|
31
|
+
|
|
32
|
+
const manager = new Manager({
|
|
33
|
+
bots: [
|
|
34
|
+
{
|
|
35
|
+
name: 'mod-bot',
|
|
36
|
+
token: process.env.MOD_BOT_TOKEN!,
|
|
37
|
+
script: './bot.js',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'music-bot',
|
|
41
|
+
token: process.env.MUSIC_BOT_TOKEN!,
|
|
42
|
+
script: './bot.js',
|
|
43
|
+
restartDelay: 5000,
|
|
44
|
+
maxRestarts: 3,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
manager.on('bot:ready', (name) => console.log(`${name} is online`))
|
|
50
|
+
manager.on('bot:crash', ({ name, code }) =>
|
|
51
|
+
console.error(`${name} crashed (exit ${code})`))
|
|
52
|
+
|
|
53
|
+
manager.startAll()
|
|
54
|
+
|
|
55
|
+
process.on('SIGINT', () => {
|
|
56
|
+
manager.stopAll()
|
|
57
|
+
process.exit(0)
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Bot worker (bot.js)
|
|
62
|
+
|
|
63
|
+
This is the script the manager forks. It receives `BOT_NAME`, `BOT_TOKEN`, and `BOT_INTENTS` via environment variables.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { Client, GatewayIntentBits } from 'discord.js'
|
|
67
|
+
import type { IPCMessage } from 'discord-bot-manager'
|
|
68
|
+
|
|
69
|
+
const client = new Client({
|
|
70
|
+
intents: Number(process.env.BOT_INTENTS) || GatewayIntentBits.Guilds,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
client.once('ready', () => {
|
|
74
|
+
// Notify the manager that the bot is online
|
|
75
|
+
process.send?.({ type: 'ready', from: 'worker', botName: process.env.BOT_NAME, timestamp: Date.now() })
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
// Listen for messages from the manager
|
|
79
|
+
process.on('message', (msg: IPCMessage) => {
|
|
80
|
+
if (msg.type === 'shutdown') {
|
|
81
|
+
client.destroy()
|
|
82
|
+
process.exit(0)
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
client.login(process.env.BOT_TOKEN)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## API
|
|
90
|
+
|
|
91
|
+
### `Manager`
|
|
92
|
+
|
|
93
|
+
| Method | Description |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `startAll()` | Start all registered bots |
|
|
96
|
+
| `start(name)` | Start a specific bot |
|
|
97
|
+
| `stopAll()` | Stop all bots gracefully |
|
|
98
|
+
| `stop(name)` | Stop a specific bot |
|
|
99
|
+
| `restartAll()` | Restart all bots |
|
|
100
|
+
| `restart(name)` | Restart a specific bot |
|
|
101
|
+
| `addBot(config)` | Register a new bot at runtime |
|
|
102
|
+
| `removeBot(name)` | Stop and remove a bot |
|
|
103
|
+
| `sendTo(name, type, payload?)` | Send IPC message to a specific bot |
|
|
104
|
+
| `broadcast(type, payload?)` | Send IPC message to all bots |
|
|
105
|
+
| `status()` | Get status array for all bots |
|
|
106
|
+
| `statusOf(name)` | Get status of one bot |
|
|
107
|
+
|
|
108
|
+
### Events
|
|
109
|
+
|
|
110
|
+
| Event | Payload |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `bot:start` | `string` (name) |
|
|
113
|
+
| `bot:ready` | `string` (name) |
|
|
114
|
+
| `bot:crash` | `{ name, code, signal }` |
|
|
115
|
+
| `bot:restart` | `string` (name) |
|
|
116
|
+
| `bot:stop` | `string` (name) |
|
|
117
|
+
| `bot:error` | `{ name, error }` |
|
|
118
|
+
| `bot:message` | `(msg: IPCMessage, name: string)` |
|
|
119
|
+
|
|
120
|
+
### `BotConfig`
|
|
121
|
+
|
|
122
|
+
| Field | Type | Default | Description |
|
|
123
|
+
|---|---|---|---|
|
|
124
|
+
| `name` | `string` | — | Unique identifier for the bot |
|
|
125
|
+
| `token` | `string` | — | Discord bot token (injected as `BOT_TOKEN` env) |
|
|
126
|
+
| `script` | `string` | — | Path to the worker script |
|
|
127
|
+
| `intents` | `number` | `0` | Discord.js intents bitfield |
|
|
128
|
+
| `env` | `Record<string, string>` | `{}` | Extra env variables |
|
|
129
|
+
| `restartDelay` | `number` | `2000` | Delay before restart (ms) |
|
|
130
|
+
| `maxRestarts` | `number` | `Infinity` | Max auto-restart attempts |
|
|
131
|
+
|
|
132
|
+
## Examples
|
|
133
|
+
|
|
134
|
+
Clone the repo and run:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npm install
|
|
138
|
+
npm run build
|
|
139
|
+
node examples/manager.js
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
See the [examples](./examples) directory for a complete manager + worker setup.
|
|
143
|
+
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ChildProcess } from 'child_process';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { BotConfig, BotStatus, IPCMessage } from './types';
|
|
4
|
+
export declare class BotProcess extends EventEmitter {
|
|
5
|
+
config: BotConfig;
|
|
6
|
+
process: ChildProcess | null;
|
|
7
|
+
restarts: number;
|
|
8
|
+
lastRestart: number | null;
|
|
9
|
+
startTime: number | null;
|
|
10
|
+
private manualStop;
|
|
11
|
+
private restartTimer;
|
|
12
|
+
constructor(config: BotConfig);
|
|
13
|
+
get pid(): number | null;
|
|
14
|
+
get status(): BotStatus['status'];
|
|
15
|
+
get uptime(): number | null;
|
|
16
|
+
toStatus(): BotStatus;
|
|
17
|
+
start(): void;
|
|
18
|
+
stop(): void;
|
|
19
|
+
restart(): void;
|
|
20
|
+
send(msg: Omit<IPCMessage, 'from'> & {
|
|
21
|
+
from?: 'manager' | 'worker';
|
|
22
|
+
}): boolean;
|
|
23
|
+
private scheduleRestart;
|
|
24
|
+
private clearRestartTimer;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=BotProcess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BotProcess.d.ts","sourceRoot":"","sources":["../src/BotProcess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAQ,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE1D,qBAAa,UAAW,SAAQ,YAAY;IACnC,MAAM,EAAE,SAAS,CAAA;IACjB,OAAO,EAAE,YAAY,GAAG,IAAI,CAAO;IACnC,QAAQ,SAAI;IACZ,WAAW,EAAE,MAAM,GAAG,IAAI,CAAO;IACjC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAO;IACtC,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,YAAY,CAA6C;gBAErD,MAAM,EAAE,SAAS;IAK7B,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,CAEvB;IAED,IAAI,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,CAOhC;IAED,IAAI,MAAM,IAAI,MAAM,GAAG,IAAI,CAI1B;IAED,QAAQ,IAAI,SAAS;IAWrB,KAAK,IAAI,IAAI;IA2Cb,IAAI,IAAI,IAAI;IAYZ,OAAO,IAAI,IAAI;IAef,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;KAAE,GAAG,OAAO;IAK9E,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,iBAAiB;CAM1B"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotProcess = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
class BotProcess extends events_1.EventEmitter {
|
|
7
|
+
config;
|
|
8
|
+
process = null;
|
|
9
|
+
restarts = 0;
|
|
10
|
+
lastRestart = null;
|
|
11
|
+
startTime = null;
|
|
12
|
+
manualStop = false;
|
|
13
|
+
restartTimer = null;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
super();
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
get pid() {
|
|
19
|
+
return this.process?.pid ?? null;
|
|
20
|
+
}
|
|
21
|
+
get status() {
|
|
22
|
+
if (this.process === null)
|
|
23
|
+
return 'stopped';
|
|
24
|
+
if (this.process.killed)
|
|
25
|
+
return 'stopped';
|
|
26
|
+
if (this.process.exitCode !== null && !this.manualStop)
|
|
27
|
+
return 'crashed';
|
|
28
|
+
if (this.process.exitCode !== null)
|
|
29
|
+
return 'stopped';
|
|
30
|
+
if (this.startTime === null)
|
|
31
|
+
return 'starting';
|
|
32
|
+
return 'running';
|
|
33
|
+
}
|
|
34
|
+
get uptime() {
|
|
35
|
+
if (this.startTime === null)
|
|
36
|
+
return null;
|
|
37
|
+
if (this.process === null || this.process.killed)
|
|
38
|
+
return (Date.now() - this.startTime);
|
|
39
|
+
return Date.now() - this.startTime;
|
|
40
|
+
}
|
|
41
|
+
toStatus() {
|
|
42
|
+
return {
|
|
43
|
+
name: this.config.name,
|
|
44
|
+
pid: this.pid,
|
|
45
|
+
status: this.status,
|
|
46
|
+
uptime: this.uptime,
|
|
47
|
+
restarts: this.restarts,
|
|
48
|
+
lastRestart: this.lastRestart
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
start() {
|
|
52
|
+
this.manualStop = false;
|
|
53
|
+
this.startTime = Date.now();
|
|
54
|
+
this.lastRestart = Date.now();
|
|
55
|
+
const env = {
|
|
56
|
+
...process.env,
|
|
57
|
+
...this.config.env,
|
|
58
|
+
BOT_NAME: this.config.name,
|
|
59
|
+
BOT_TOKEN: this.config.token,
|
|
60
|
+
BOT_INTENTS: String(this.config.intents ?? 0)
|
|
61
|
+
};
|
|
62
|
+
this.process = (0, child_process_1.fork)(this.config.script, [], {
|
|
63
|
+
env: env,
|
|
64
|
+
stdio: ['pipe', 'pipe', 'pipe', 'ipc']
|
|
65
|
+
});
|
|
66
|
+
this.process.on('message', (msg) => {
|
|
67
|
+
if (msg.type === 'ready') {
|
|
68
|
+
this.emit('ready', this.config.name);
|
|
69
|
+
}
|
|
70
|
+
this.emit('message', msg, this.config.name);
|
|
71
|
+
});
|
|
72
|
+
this.process.on('exit', (code, signal) => {
|
|
73
|
+
const crashed = !this.manualStop;
|
|
74
|
+
this.emit('exit', { name: this.config.name, code, signal, crashed });
|
|
75
|
+
if (crashed) {
|
|
76
|
+
this.emit('crash', { name: this.config.name, code, signal });
|
|
77
|
+
this.scheduleRestart();
|
|
78
|
+
}
|
|
79
|
+
this.process = null;
|
|
80
|
+
this.startTime = null;
|
|
81
|
+
});
|
|
82
|
+
this.process.on('error', (err) => {
|
|
83
|
+
this.emit('error', { name: this.config.name, error: err.message });
|
|
84
|
+
});
|
|
85
|
+
this.emit('start', this.config.name);
|
|
86
|
+
}
|
|
87
|
+
stop() {
|
|
88
|
+
this.manualStop = true;
|
|
89
|
+
this.clearRestartTimer();
|
|
90
|
+
if (!this.process)
|
|
91
|
+
return;
|
|
92
|
+
this.send({ type: 'shutdown', from: 'manager', botName: this.config.name, timestamp: Date.now() });
|
|
93
|
+
const killTimeout = setTimeout(() => {
|
|
94
|
+
this.process?.kill('SIGKILL');
|
|
95
|
+
}, 5000);
|
|
96
|
+
this.process.once('exit', () => clearTimeout(killTimeout));
|
|
97
|
+
this.process?.disconnect();
|
|
98
|
+
}
|
|
99
|
+
restart() {
|
|
100
|
+
this.manualStop = true;
|
|
101
|
+
this.clearRestartTimer();
|
|
102
|
+
if (this.process) {
|
|
103
|
+
this.process.once('exit', () => {
|
|
104
|
+
this.manualStop = false;
|
|
105
|
+
this.start();
|
|
106
|
+
});
|
|
107
|
+
this.stop();
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.manualStop = false;
|
|
111
|
+
this.start();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
send(msg) {
|
|
115
|
+
if (!this.process || !this.process.connected)
|
|
116
|
+
return false;
|
|
117
|
+
return this.process.send({ ...msg, from: 'manager' });
|
|
118
|
+
}
|
|
119
|
+
scheduleRestart() {
|
|
120
|
+
const delay = this.config.restartDelay ?? 2000;
|
|
121
|
+
const max = this.config.maxRestarts ?? Infinity;
|
|
122
|
+
if (this.restarts >= max) {
|
|
123
|
+
this.emit('error', { name: this.config.name, error: `Max restarts (${max}) reached` });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.restarts++;
|
|
127
|
+
this.restartTimer = setTimeout(() => {
|
|
128
|
+
this.emit('restart', this.config.name);
|
|
129
|
+
this.start();
|
|
130
|
+
}, delay);
|
|
131
|
+
}
|
|
132
|
+
clearRestartTimer() {
|
|
133
|
+
if (this.restartTimer) {
|
|
134
|
+
clearTimeout(this.restartTimer);
|
|
135
|
+
this.restartTimer = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.BotProcess = BotProcess;
|
|
140
|
+
//# sourceMappingURL=BotProcess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BotProcess.js","sourceRoot":"","sources":["../src/BotProcess.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAClD,mCAAqC;AAGrC,MAAa,UAAW,SAAQ,qBAAY;IACnC,MAAM,CAAW;IACjB,OAAO,GAAwB,IAAI,CAAA;IACnC,QAAQ,GAAG,CAAC,CAAA;IACZ,WAAW,GAAkB,IAAI,CAAA;IACjC,SAAS,GAAkB,IAAI,CAAA;IAC9B,UAAU,GAAG,KAAK,CAAA;IAClB,YAAY,GAAyC,IAAI,CAAA;IAEjE,YAAY,MAAiB;QAC3B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAA;IAClC,CAAC;IAED,IAAI,MAAM;QACR,IAAI,IAAI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QACd,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAC/B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;QAC1B,CAAC;IACH,CAAC;CACF;AA3ID,gCA2IC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { BotConfig, BotStatus, ManagerOptions } from './types';
|
|
3
|
+
import { BotProcess } from './BotProcess';
|
|
4
|
+
export declare class Manager extends EventEmitter {
|
|
5
|
+
bots: Map<string, BotProcess>;
|
|
6
|
+
private maxConcurrentRestarts;
|
|
7
|
+
constructor(options: ManagerOptions);
|
|
8
|
+
addBot(config: BotConfig): BotProcess;
|
|
9
|
+
removeBot(name: string): boolean;
|
|
10
|
+
startAll(): void;
|
|
11
|
+
start(name: string): void;
|
|
12
|
+
stopAll(): void;
|
|
13
|
+
stop(name: string): void;
|
|
14
|
+
restartAll(): void;
|
|
15
|
+
restart(name: string): void;
|
|
16
|
+
sendTo(name: string, type: string, payload?: unknown): boolean;
|
|
17
|
+
broadcast(type: string, payload?: unknown): void;
|
|
18
|
+
status(): BotStatus[];
|
|
19
|
+
statusOf(name: string): BotStatus | null;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=Manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../src/Manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,qBAAa,OAAQ,SAAQ,YAAY;IAChC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAY;IAChD,OAAO,CAAC,qBAAqB,CAAQ;gBAEzB,OAAO,EAAE,cAAc;IAQnC,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU;IAkBrC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAQhC,QAAQ,IAAI,IAAI;IAMhB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIzB,OAAO,IAAI,IAAI;IAMf,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxB,UAAU,IAAI,IAAI;IAMlB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI3B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO;IAM9D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI;IAMhD,MAAM,IAAI,SAAS,EAAE;IAIrB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAGzC"}
|
package/dist/Manager.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Manager = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const BotProcess_1 = require("./BotProcess");
|
|
6
|
+
class Manager extends events_1.EventEmitter {
|
|
7
|
+
bots = new Map();
|
|
8
|
+
maxConcurrentRestarts;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super();
|
|
11
|
+
this.maxConcurrentRestarts = options.maxConcurrentRestarts ?? 3;
|
|
12
|
+
for (const botCfg of options.bots) {
|
|
13
|
+
this.addBot(botCfg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
addBot(config) {
|
|
17
|
+
if (this.bots.has(config.name)) {
|
|
18
|
+
throw new Error(`Bot "${config.name}" already registered`);
|
|
19
|
+
}
|
|
20
|
+
const bp = new BotProcess_1.BotProcess(config);
|
|
21
|
+
this.bots.set(config.name, bp);
|
|
22
|
+
bp.on('start', (name) => this.emit('bot:start', name));
|
|
23
|
+
bp.on('stop', (name) => this.emit('bot:stop', name));
|
|
24
|
+
bp.on('crash', (data) => this.emit('bot:crash', data));
|
|
25
|
+
bp.on('restart', (name) => this.emit('bot:restart', name));
|
|
26
|
+
bp.on('ready', (name) => this.emit('bot:ready', name));
|
|
27
|
+
bp.on('error', (data) => this.emit('bot:error', data));
|
|
28
|
+
bp.on('message', (msg, name) => this.emit('bot:message', msg, name));
|
|
29
|
+
return bp;
|
|
30
|
+
}
|
|
31
|
+
removeBot(name) {
|
|
32
|
+
const bp = this.bots.get(name);
|
|
33
|
+
if (!bp)
|
|
34
|
+
return false;
|
|
35
|
+
bp.stop();
|
|
36
|
+
bp.removeAllListeners();
|
|
37
|
+
return this.bots.delete(name);
|
|
38
|
+
}
|
|
39
|
+
startAll() {
|
|
40
|
+
for (const bp of this.bots.values()) {
|
|
41
|
+
bp.start();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
start(name) {
|
|
45
|
+
this.bots.get(name)?.start();
|
|
46
|
+
}
|
|
47
|
+
stopAll() {
|
|
48
|
+
for (const bp of this.bots.values()) {
|
|
49
|
+
bp.stop();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
stop(name) {
|
|
53
|
+
this.bots.get(name)?.stop();
|
|
54
|
+
}
|
|
55
|
+
restartAll() {
|
|
56
|
+
for (const bp of this.bots.values()) {
|
|
57
|
+
bp.restart();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
restart(name) {
|
|
61
|
+
this.bots.get(name)?.restart();
|
|
62
|
+
}
|
|
63
|
+
sendTo(name, type, payload) {
|
|
64
|
+
const bp = this.bots.get(name);
|
|
65
|
+
if (!bp)
|
|
66
|
+
return false;
|
|
67
|
+
return bp.send({ type, payload, from: 'manager', botName: name, timestamp: Date.now() });
|
|
68
|
+
}
|
|
69
|
+
broadcast(type, payload) {
|
|
70
|
+
for (const [name, bp] of this.bots) {
|
|
71
|
+
bp.send({ type, payload, from: 'manager', botName: name, timestamp: Date.now() });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
status() {
|
|
75
|
+
return Array.from(this.bots.values()).map(b => b.toStatus());
|
|
76
|
+
}
|
|
77
|
+
statusOf(name) {
|
|
78
|
+
return this.bots.get(name)?.toStatus() ?? null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Manager = Manager;
|
|
82
|
+
//# sourceMappingURL=Manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Manager.js","sourceRoot":"","sources":["../src/Manager.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC,6CAAyC;AAEzC,MAAa,OAAQ,SAAQ,qBAAY;IAChC,IAAI,GAA4B,IAAI,GAAG,EAAE,CAAA;IACxC,qBAAqB,CAAQ;IAErC,YAAY,OAAuB;QACjC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,IAAI,CAAC,CAAA;QAC/D,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,MAAiB;QACtB,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,QAAQ,MAAM,CAAC,IAAI,sBAAsB,CAAC,CAAA;QAC5D,CAAC;QACD,MAAM,EAAE,GAAG,IAAI,uBAAU,CAAC,MAAM,CAAC,CAAA;QACjC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAE9B,EAAE,CA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AM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACnC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QACnF,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC9D,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAA;IAChD,CAAC;CACF;AAvFD,0BAuFC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotProcess = exports.Manager = void 0;
|
|
4
|
+
var Manager_1 = require("./Manager");
|
|
5
|
+
Object.defineProperty(exports, "Manager", { enumerable: true, get: function () { return Manager_1.Manager; } });
|
|
6
|
+
var BotProcess_1 = require("./BotProcess");
|
|
7
|
+
Object.defineProperty(exports, "BotProcess", { enumerable: true, get: function () { return BotProcess_1.BotProcess; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,2CAAyC;AAAhC,wGAAA,UAAU,OAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface BotConfig {
|
|
2
|
+
name: string;
|
|
3
|
+
token: string;
|
|
4
|
+
intents?: number;
|
|
5
|
+
script: string;
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
restartDelay?: number;
|
|
8
|
+
maxRestarts?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface BotStatus {
|
|
11
|
+
name: string;
|
|
12
|
+
pid: number | null;
|
|
13
|
+
status: 'starting' | 'running' | 'stopped' | 'crashed';
|
|
14
|
+
uptime: number | null;
|
|
15
|
+
restarts: number;
|
|
16
|
+
lastRestart: number | null;
|
|
17
|
+
}
|
|
18
|
+
export interface ManagerOptions {
|
|
19
|
+
bots: BotConfig[];
|
|
20
|
+
maxConcurrentRestarts?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface IPCMessage {
|
|
23
|
+
type: string;
|
|
24
|
+
payload?: unknown;
|
|
25
|
+
from: 'manager' | 'worker';
|
|
26
|
+
botName: string;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
}
|
|
29
|
+
export type BotEvent = 'start' | 'stop' | 'crash' | 'restart' | 'ready' | 'error' | 'message';
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IACtD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,EAAE,CAAA;IACjB,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "discord-bots-manager",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Spawn and manage multiple Discord bot processes from a single manager using child_process.fork()",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"clean": "rm -rf dist",
|
|
10
|
+
"prepublishOnly": "npm run build",
|
|
11
|
+
"example": "npm run build && node examples/manager.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"discord",
|
|
15
|
+
"bot",
|
|
16
|
+
"manager",
|
|
17
|
+
"process-manager",
|
|
18
|
+
"discord.js",
|
|
19
|
+
"cluster",
|
|
20
|
+
"shard",
|
|
21
|
+
"sharding",
|
|
22
|
+
"multiprocess",
|
|
23
|
+
"child-process",
|
|
24
|
+
"fork",
|
|
25
|
+
"process-management",
|
|
26
|
+
"bot-manager",
|
|
27
|
+
"nodejs",
|
|
28
|
+
"typescript",
|
|
29
|
+
"discord-bot"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/freepinkg/discord-bot-manager.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/freepinkg/discord-bot-manager/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/freepinkg/discord-bot-manager",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"typescript": "^5.4.0",
|
|
48
|
+
"@types/node": "^20.0.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"discord.js": "^14.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|