mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49:57 +00:00
bot.js optimizations
This commit is contained in:
parent
66dff8ceb3
commit
1c21387b02
19
bot.js
19
bot.js
@ -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}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user