Implemented blocklist + some code changes

This commit is contained in:
Lucas Gabriel 2024-06-02 01:48:19 -03:00
parent 945182329e
commit 4b0e188467
No known key found for this signature in database
GPG key ID: D9B075FC6DC93985
13 changed files with 48 additions and 12 deletions

28
src/blocklist.js Normal file
View file

@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');
const blocklistPath = path.join(__dirname, '../blocklist.txt');
let blocklist = [];
const readBlocklist = () => {
try {
const data = fs.readFileSync(blocklistPath, 'utf8');
blocklist = data.split('\n').map(id => id.trim()).filter(id => id !== '');
} catch (error) {
if (error.code === 'ENOENT') {
console.log('WARN: Blocklist file not found. Creating a new one.');
fs.writeFileSync(blocklistPath, ''); // Create an empty blocklist file
} else {
console.error('WARN: Error reading blocklist:', error);
}
}
};
const isBlocked = (userId) => {
return blocklist.includes(String(userId));
};
readBlocklist();
module.exports = { isBlocked };