diff --git a/.gitignore b/.gitignore index 922de0a..3847f25 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ node_modules/ cookies.txt config.json package-lock.json -statuses.json \ No newline at end of file +statuses.json +*.webm +blacklist.json \ No newline at end of file diff --git a/commands/blacklist.js b/commands/blacklist.js new file mode 100644 index 0000000..8c5cd0e --- /dev/null +++ b/commands/blacklist.js @@ -0,0 +1,38 @@ +const fs = require('fs'); +const path = require('path'); + +const { BOT_OWNER_ID } = require('../config.json'); + +module.exports = { + name: 'blacklist', + description: 'Blacklist or unblacklist a user from using the bot', + async execute(message, args) { + if (message.author.id !== BOT_OWNER_ID) { + return message.reply("You don't have permission to use this command."); + } + + const mentionedUser = message.mentions.users.first(); + if (!mentionedUser) { + return message.reply("Please mention a user to blacklist/unblacklist."); + } + + const blacklistPath = path.join(__dirname, '../blacklist.json'); + const blacklistData = JSON.parse(fs.readFileSync(blacklistPath, 'utf8')); + + const isBlacklisted = blacklistData.blacklisted.includes(mentionedUser.id); + + if (isBlacklisted) { + blacklistData.blacklisted = blacklistData.blacklisted.filter(id => id !== mentionedUser.id); + fs.writeFileSync(blacklistPath, JSON.stringify(blacklistData, null, 2)); + message.reply(`${mentionedUser.tag} has been unblacklisted.`); + } else { + blacklistData.blacklisted.push(mentionedUser.id); + fs.writeFileSync(blacklistPath, JSON.stringify(blacklistData, null, 2)); + message.reply(`${mentionedUser.tag} has been blacklisted.`); + } + + const updatedBlacklist = blacklistData.blacklisted; + const index = require('../index.js'); + index.updateBlacklist(updatedBlacklist); + } +}; \ No newline at end of file diff --git a/config.json.example b/config.json.example index 52f453c..46da31d 100644 --- a/config.json.example +++ b/config.json.example @@ -1,4 +1,5 @@ { + "BOT_OWNER_ID": "ID" "prefix": "+", "token": "token", "cookie-file": "/home/user/dz-musicbot/cookies.txt" diff --git a/index.js b/index.js index acb5fa1..0aaa304 100644 --- a/index.js +++ b/index.js @@ -16,19 +16,7 @@ fs.readdir(tmpDir, (err, files) => { if (err) throw err; for (const file of files) { - if (file.endsWith('.mp3')) { - fs.unlink(path.join(tmpDir, file), err => { - if (err) throw err; - }); - } - } -}); - -fs.readdir(tmpDir, (err, files) => { - if (err) throw err; - - for (const file of files) { - if (file.endsWith('.part')) { + if (file.endsWith('.mp3') || file.endsWith('.part')) { fs.unlink(path.join(tmpDir, file), err => { if (err) throw err; }); @@ -42,6 +30,16 @@ for (const file of commandFiles) { client.commands.set(command.name, command); } +const blacklistPath = path.join(__dirname, 'blacklist.json'); + +if (!fs.existsSync(blacklistPath)) { + console.log('blacklist.json not found, creating one...'); + fs.writeFileSync(blacklistPath, JSON.stringify({ blacklisted: [] }, null, 2)); +} + +let blacklistData = JSON.parse(fs.readFileSync(blacklistPath, 'utf8')); +let blacklist = blacklistData.blacklisted; + client.once('ready', () => { console.log(`Logged in as ${client.user.tag}!`); client.user.setStatus('idle'); @@ -61,6 +59,10 @@ client.once('ready', () => { client.on('messageCreate', async message => { if (!message.content.startsWith(prefix) || message.author.bot) return; + if (blacklist.includes(message.author.id)) { + return message.reply("You are blacklisted from using this bot."); + } + const args = message.content.slice(prefix.length).trim().split(/ +/); const commandName = args.shift().toLowerCase(); @@ -77,4 +79,11 @@ client.on('messageCreate', async message => { } }); +function updateBlacklist(newBlacklist) { + blacklist = newBlacklist; + console.log("Blacklist updated:", blacklist); +} + +module.exports = { updateBlacklist }; + client.login(token); \ No newline at end of file