-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
130 lines (105 loc) · 4.36 KB
/
index.js
File metadata and controls
130 lines (105 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const fs = require('fs');
const path = require('path');
const { Client, Collection, GatewayIntentBits, REST, Routes } = require('discord.js');
require('dotenv').config();
// Initialize the Discord client with required intents
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.commands = new Collection();
// Load and register commands from the commands folder
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}
// Register slash commands (Loader)
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
// Load settings from settings.json for antifeatures
const settingsFilePath = path.join(__dirname, 'settings.json');
function loadSettings() {
if (fs.existsSync(settingsFilePath)) {
return JSON.parse(fs.readFileSync(settingsFilePath, 'utf-8'));
} else {
return { antilink: false, antiinvite: false, antispam: false, antinuke: false };
}
}
function saveSettings(settings) {
fs.writeFileSync(settingsFilePath, JSON.stringify(settings, null, 2));
}
// Event: Ready
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
// Event: Interaction
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
// Anti-Link and Anti-Invite logic
client.on('messageCreate', async message => {
if (message.author.bot) return; // Ignore bot messages
const settings = loadSettings();
// Antilink: Delete messages containing links
if (settings.antilink && message.content.includes('http')) {
await message.delete();
message.channel.send(`${message.author}, links are not allowed.`);
}
// Antiinvite: Delete messages containing Discord invites
if (settings.antiinvite && message.content.includes('discord.gg')) {
await message.delete();
message.channel.send(`${message.author}, Discord invite links are not allowed.`);
}
// Antispam: Prevent spam (5 consecutive identical messages)
if (settings.antispam) {
if (!client.messageCache) client.messageCache = new Map();
const userMessages = client.messageCache.get(message.author.id) || [];
userMessages.push(message.content);
if (userMessages.length > 5) userMessages.shift(); // Keep only last 5 messages
client.messageCache.set(message.author.id, userMessages);
// Check if user is spamming the same message
const isSpamming = userMessages.every(msg => msg === userMessages[0]);
if (isSpamming) {
await message.delete();
message.channel.send(`${message.author}, please stop spamming.`);
}
}
});
// Anti-Nuke Protection: Monitor for mass role and channel deletions
client.on('roleDelete', async (role) => {
const settings = loadSettings();
if (settings.antinuke) {
console.log(`Role ${role.name} deleted, checking for mass deletions...`);
// Add logic to handle potential nuke actions, such as preventing further deletions or taking action
}
});
client.on('channelDelete', async (channel) => {
const settings = loadSettings();
if (settings.antinuke) {
console.log(`Channel ${channel.name} deleted, checking for mass deletions...`);
// Similar to roleDelete, logic to handle mass deletion detection
}
});
// Login to Discord
client.login(process.env.TOKEN);