-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
82 lines (73 loc) · 3.01 KB
/
app.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import bot from "./src/services/bot.js";
import { sleep, logger } from "./src/utils.js";
// Error global handler
process.on("unhandledRejection", (reason, promise) => {
logger.error("🛑 Unhandled Rejection at:", promise, "reason:", reason);
process.exit(1);
});
process.on("uncaughtException", (err) => {
logger.error("🛑 Uncaught Exception thrown", err);
process.exit(1);
});
// Signal handler
process.on("SIGINT", () => {
logger.info("✋ Gracefully shutting down bot...");
bot.stop("SIGINT");
process.exit(0);
});
/**
* Main function to start the bot
*/
const main = async () => {
// Start the bot
logger.info("🤖 Starting the bot...");
console.log(`############################################################`);
console.log(`# #`);
console.log(`# ███████╗ █████╗ ██████╗██╗ ██╗██╗ ██╗ #`);
console.log(`# ╚══███╔╝██╔══██╗██╔════╝██║ ██╔╝╚██╗ ██╔╝ #`);
console.log(`# ███╔╝ ███████║██║ █████╔╝ ╚████╔╝ #`);
console.log(`# ███╔╝ ██╔══██║██║ ██╔═██╗ ╚██╔╝ #`);
console.log(`# ███████╗██║ ██║╚██████╗██║ ██╗ ██║ #`);
console.log(`# ╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ #`);
console.log(`# #`);
console.log(`# Anonim Telegram Chatbot (https://t.me/zckyachmd) #`);
console.log(`# Version: 1.0.0 #`);
console.log(`# #`);
console.log(`############################################################`);
const maxRetries = 3;
for (let retryCount = 0; retryCount < maxRetries; retryCount++) {
try {
if (retryCount > 0) {
await sleep(15);
}
logger.info(
`🤖 Attempting to start bot (Attempt ${
retryCount + 1
} of ${maxRetries})...`
);
const botInfo = await bot.telegram.getMe();
if (botInfo && botInfo.username) {
logger.info(
`🚀 Bot started successfully! Username: @${botInfo.username}`
);
await bot.launch();
break;
} else {
throw new Error("Failed to start the bot or get bot info");
}
} catch (error) {
logger.error(
`❌ Error starting the bot (Attempt ${
retryCount + 1
} of ${maxRetries}):`,
error.message
);
}
if (retryCount === maxRetries - 1) {
logger.error("❌ Failed to start bot after maximum retries. Exiting...");
process.exit(1);
}
}
};
// Run the main function
main();