-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
56 lines (45 loc) · 1.45 KB
/
Copy pathserver.js
File metadata and controls
56 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const client = require("./index"); // Import bot instance
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors({ origin: "https://jadedsieger.github.io" }));
app.use(express.json());
// Start Bot
app.post('/bot/start', async (req, res) => {
if (client.isReady()) {
return res.json({ message: "Bot is already running!" });
}
try {
await client.login(process.env.token);
// Wait for the bot to fully start before sending response
client.once("ready", () => {
res.json({ message: "Bot started successfully!" });
});
} catch (error) {
console.error("Error starting bot:", error);
res.status(500).json({ message: "Error starting bot", error });
}
});
// Stop Bot
app.post('/bot/stop', async (req, res) => {
if (!client.isReady()) {
return res.json({ message: "Bot is not running!" });
}
await client.destroy();
res.json({ message: "Bot stopped successfully!" });
});
// Get Bot Status
app.get('/bot/status', (req, res) => {
console.log("isReady():", client.isReady());
res.json({ status: client.isReady() ? "Online" : "Offline" });
});
// Get Bot Name
app.get('/bot/name', (req, res) => {
res.json({ name: "Lieserl Einstein" });
});
// Start Express Server
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});