Spaces:
Runtime error
Runtime error
itszubariel commited on
Commit ·
6f5f964
1
Parent(s): cdcbf0a
add per-user bot limit
Browse files- src/server.ts +2 -0
src/server.ts
CHANGED
|
@@ -50,6 +50,8 @@ app.use(auth);
|
|
| 50 |
app.post('/run', (req: Request<{}, any, RunRequestBody>, res: Response) => {
|
| 51 |
const { botId, discordId, envFile, zbrJson, commands, dbBase64 } = req.body;
|
| 52 |
const key = `${discordId}-${botId}`;
|
|
|
|
|
|
|
| 53 |
if (processes.has(key)) return res.status(400).send('Bot already running');
|
| 54 |
const tempDir = `/tmp/zbr-${discordId}-${botId}`;
|
| 55 |
fs.mkdirSync(tempDir, { recursive: true });
|
|
|
|
| 50 |
app.post('/run', (req: Request<{}, any, RunRequestBody>, res: Response) => {
|
| 51 |
const { botId, discordId, envFile, zbrJson, commands, dbBase64 } = req.body;
|
| 52 |
const key = `${discordId}-${botId}`;
|
| 53 |
+
const userHasRunningBot = Array.from(processes.keys()).some(k => k.startsWith(`${discordId}-`));
|
| 54 |
+
if (userHasRunningBot) return res.status(400).send('You already have a bot running. Stop it before starting another.');
|
| 55 |
if (processes.has(key)) return res.status(400).send('Bot already running');
|
| 56 |
const tempDir = `/tmp/zbr-${discordId}-${botId}`;
|
| 57 |
fs.mkdirSync(tempDir, { recursive: true });
|