Skip to content

Commit f7121a6

Browse files
authored
Merge pull request #9 from johnnyFR26/discord
[add: ping route to keep alive]
2 parents 340f177 + cfafd18 commit f7121a6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/bot.ts

+9
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ client.once('ready', () => {
1212

1313
client.login(process.env.DISCORD_TOKEN)
1414

15+
client.on("disconnect", () => {
16+
console.warn("⚠️ Bot desconectado! Tentando reconectar...");
17+
});
18+
19+
client.on("reconnecting", () => {
20+
console.log("🔄 Reconectando ao Discord...");
21+
});
22+
23+
1524
export { client }

routes/bot.routes.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { FastifyInstance } from "fastify";
22
import { handleGitHubWebhook } from "../controllers/discord.controller";
3+
import { client } from "../lib/bot";
34

45
export default async function BotRoutes(server: FastifyInstance) {
56
server.post('/webhook', handleGitHubWebhook)
7+
server.get("/ping", async (request, reply) => {
8+
if (!client.isReady()) {
9+
return reply.status(500).send({ error: "Bot não está pronto!" });
10+
}
11+
return reply.send({ status: "Bot online!", uptime: process.uptime() });
12+
});
613

714
}

0 commit comments

Comments
 (0)