bot.js optimizations

This commit is contained in:
Lucas Gabriel 2024-09-10 17:56:33 -03:00
parent 66dff8ceb3
commit 1c21387b02
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985

19
bot.js
View File

@ -8,32 +8,23 @@ const bot = new Telegraf(Config.botToken);
const MAX_RETRIES = 5; const MAX_RETRIES = 5;
let restartCount = 0; let restartCount = 0;
const loadCommands = () => { const loadCommands = () => {
const commandsPath = path.join(__dirname, 'commands'); const commandsPath = path.join(__dirname, 'commands');
try { try {
fs.readdirSync(commandsPath).forEach((file) => { const files = fs.readdirSync(commandsPath);
files.forEach((file) => {
try { try {
const command = require(path.join(commandsPath, file)); const command = require(path.join(commandsPath, file));
if (typeof command === 'function') { if (typeof command === 'function') {
command(bot, isOnSpamWatch); command(bot, isOnSpamWatch);
} }
} catch (fileError) { } catch (error) {
console.error(`Failed to load command file ${file}: ${fileError.message}`); console.error(`Failed to load command file ${file}: ${error.message}`);
} }
}); });
} catch (dirError) {
console.error(`Failed to read commands directory: ${dirError.message}`);
}
};
const sendMessage = async (ctx, text, options = {}) => {
try {
await ctx.reply(text, options);
} catch (error) { } catch (error) {
console.error('Error sending message:', error.message); console.error(`Failed to read commands directory: ${error.message}`);
} }
}; };