mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-04-28 17:15:57 +00:00
Added bam + some other code fixes
This commit is contained in:
parent
c419a4e653
commit
4b9ed6d2c0
@ -6,21 +6,21 @@ const blocklistPath = path.join(__dirname, '../blocklist.txt');
|
|||||||
let blocklist = [];
|
let blocklist = [];
|
||||||
|
|
||||||
const readBlocklist = () => {
|
const readBlocklist = () => {
|
||||||
try {
|
try {
|
||||||
const data = fs.readFileSync(blocklistPath, 'utf8');
|
const data = fs.readFileSync(blocklistPath, 'utf8');
|
||||||
blocklist = data.split('\n').map(id => id.trim()).filter(id => id !== '');
|
blocklist = data.split('\n').map(id => id.trim()).filter(id => id !== '');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'ENOENT') {
|
if (error.code === 'ENOENT') {
|
||||||
console.log('WARN: Blocklist file not found. Creating a new one.');
|
console.log('WARN: Blocklist file not found. Creating a new one.');
|
||||||
fs.writeFileSync(blocklistPath, '');
|
fs.writeFileSync(blocklistPath, '');
|
||||||
} else {
|
} else {
|
||||||
console.error('WARN: Error reading blocklist:', error);
|
console.error('WARN: Error reading blocklist:', error);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isBlocked = (userId) => {
|
const isBlocked = (userId) => {
|
||||||
return blocklist.includes(String(userId));
|
return blocklist.includes(String(userId));
|
||||||
};
|
};
|
||||||
|
|
||||||
readBlocklist();
|
readBlocklist();
|
||||||
|
8
src/commands/bam.js
Normal file
8
src/commands/bam.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module.exports = function(bot, msg) {
|
||||||
|
const chatId = msg.chat.id;
|
||||||
|
|
||||||
|
const message = `O usuario foi bamido com sucesso`;
|
||||||
|
|
||||||
|
bot.sendMessage(chatId, message, { parse_mode: 'Markdown' })
|
||||||
|
.catch(error => console.error('WARN: Message cannot be sent: ', error));
|
||||||
|
}
|
@ -5,37 +5,37 @@ const logFile = 'log.txt';
|
|||||||
const logStream = fs.createWriteStream(logFile, { flags: 'a' });
|
const logStream = fs.createWriteStream(logFile, { flags: 'a' });
|
||||||
|
|
||||||
const getFormattedDate = () => {
|
const getFormattedDate = () => {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
||||||
const day = ('0' + date.getDate()).slice(-2);
|
const day = ('0' + date.getDate()).slice(-2);
|
||||||
const hours = ('0' + date.getHours()).slice(-2);
|
const hours = ('0' + date.getHours()).slice(-2);
|
||||||
const minutes = ('0' + date.getMinutes()).slice(-2);
|
const minutes = ('0' + date.getMinutes()).slice(-2);
|
||||||
const seconds = ('0' + date.getSeconds()).slice(-2);
|
const seconds = ('0' + date.getSeconds()).slice(-2);
|
||||||
return `[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]`;
|
return `[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const logMessage = async (message) => {
|
const logMessage = async (message) => {
|
||||||
const timestamp = getFormattedDate();
|
const timestamp = getFormattedDate();
|
||||||
const formattedMessage = `${timestamp} ${util.format(message)}`;
|
const formattedMessage = `${timestamp} ${util.format(message)}`;
|
||||||
|
|
||||||
process.stdout.write(formattedMessage + '\n');
|
process.stdout.write(formattedMessage + '\n');
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logStream.write(formattedMessage + '\n', (err) => {
|
logStream.write(formattedMessage + '\n', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log = (message) => {
|
console.log = (message) => {
|
||||||
logMessage(message).catch(err => {
|
logMessage(message).catch(err => {
|
||||||
process.stderr.write(`WARN: Error writing to log: ${err}\n`);
|
process.stderr.write(`WARN: Error writing to log: ${err}\n`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = logMessage;
|
module.exports = logMessage;
|
||||||
|
@ -3,9 +3,8 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const token = process.env.TGBOT_TOKEN;
|
const token = process.env.TGBOT_TOKEN;
|
||||||
const bot = new TelegramBot(token, { polling: true });
|
const bot = new TelegramBot(token, { polling: true });
|
||||||
|
|
||||||
const logMessage = require('./logger');
|
|
||||||
const { isBlocked } = require('./blocklist');
|
const { isBlocked } = require('./blocklist');
|
||||||
|
require('./logger');
|
||||||
|
|
||||||
const commandsPath = path.join(__dirname, 'commands');
|
const commandsPath = path.join(__dirname, 'commands');
|
||||||
const commandHandlers = {};
|
const commandHandlers = {};
|
||||||
@ -30,7 +29,7 @@ bot.on('message', (msg) => {
|
|||||||
commandHandlers[messageText](bot, msg);
|
commandHandlers[messageText](bot, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`INFO: User ${userName}, ${userId} sended a message with the content:
|
console.log(`INFO: User ${userName}, ${userId} sended a command or message with the content:
|
||||||
• ${messageText}\n`)
|
• ${messageText}\n`)
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -38,5 +37,4 @@ bot.on('polling_error', (error) => {
|
|||||||
console.error('WARN: Polling error:', error);
|
console.error('WARN: Polling error:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
const date = new Date().toString();
|
|
||||||
console.log(`INFO: Lynx started\n`);
|
console.log(`INFO: Lynx started\n`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user