From 4770d9a65d2705b921f62eecfefb8d8672d6cdac Mon Sep 17 00:00:00 2001 From: Lucas Gabriel <90426410+lucmsilva651@users.noreply.github.com> Date: Sat, 1 Jun 2024 23:17:57 +0000 Subject: [PATCH] Tryng to implement blocklist --- src/commands/.start.js | 11 +++++++++++ src/commands/start.js | 28 ++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/commands/.start.js diff --git a/src/commands/.start.js b/src/commands/.start.js new file mode 100644 index 0000000..a3c6a98 --- /dev/null +++ b/src/commands/.start.js @@ -0,0 +1,11 @@ +module.exports = function(bot, msg) { + const chatId = msg.chat.id; + const userName = msg.from.first_name; + const userId = msg.from.id; + + const message = `Hello! I am Lynx!\nI was made with love by Lucas Gabriel (lucmsilva)!\n\nSee /help for the bot commands!` + + bot.sendMessage(chatId, message) + .catch(error => console.error('ERROR: Message cannot be sent:', error)); + console.log(`INFO: /start executed by ${userName}, ${userId}`) +} \ No newline at end of file diff --git a/src/commands/start.js b/src/commands/start.js index a3c6a98..eb3db59 100644 --- a/src/commands/start.js +++ b/src/commands/start.js @@ -1,11 +1,27 @@ +const fs = require('fs'); +const path = require('path'); + module.exports = function(bot, msg) { const chatId = msg.chat.id; - const userName = msg.from.first_name; - const userId = msg.from.id; + const userId = msg.from.id.toString(); + + const blocklistPath = path.join(__dirname, '../../blocklist.txt'); + let blocklist = []; + try { + blocklist = fs.readFileSync(blocklistPath, 'utf8').split('\n').map(id => id.trim()); + } catch (err) { + console.error(`Erro ao carregar a blocklist: ${err}`); + } + + if (blocklist.includes(userId)) { + bot.sendMessage(chatId, "You are blocked from use this bot.\nDon't even try using a alternative account, as you will be blocked too."); + return; + } + + const userName = msg.from.first_name; + const message = `Hello! I am Lynx!\nI was made with love by Lucas Gabriel (lucmsilva)!\n\nSee /help for the bot commands!`; - const message = `Hello! I am Lynx!\nI was made with love by Lucas Gabriel (lucmsilva)!\n\nSee /help for the bot commands!` - bot.sendMessage(chatId, message) .catch(error => console.error('ERROR: Message cannot be sent:', error)); - console.log(`INFO: /start executed by ${userName}, ${userId}`) -} \ No newline at end of file + console.log(`INFO: /start executed by ${userName}, ${userId}`); +}