Add blacklisting
This commit is contained in:
parent
f15a527de1
commit
66c016bfa3
|
@ -4,3 +4,5 @@ cookies.txt
|
|||
config.json
|
||||
package-lock.json
|
||||
statuses.json
|
||||
*.webm
|
||||
blacklist.json
|
|
@ -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);
|
||||
}
|
||||
};
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"BOT_OWNER_ID": "ID"
|
||||
"prefix": "+",
|
||||
"token": "token",
|
||||
"cookie-file": "/home/user/dz-musicbot/cookies.txt"
|
||||
|
|
35
index.js
35
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);
|
Loading…
Reference in New Issue