|
1 | 1 | const { SlashCommandBuilder, EmbedBuilder } = require("discord.js"); |
2 | | -const Database = require("../../../utils/database"); |
| 2 | +const Database = require("../../utils/database"); |
3 | 3 |
|
4 | 4 | module.exports = { |
5 | | - data: new SlashCommandBuilder() |
6 | | - .setName("antiraid") |
7 | | - .setDescription("🛡️ Simple anti-raid protection") |
8 | | - .addSubcommand((subcommand) => |
9 | | - subcommand |
10 | | - .setName("enable") |
11 | | - .setDescription("Enable anti-raid protection") |
12 | | - ) |
13 | | - .addSubcommand((subcommand) => |
14 | | - subcommand |
15 | | - .setName("disable") |
16 | | - .setDescription("Disable anti-raid protection") |
17 | | - ) |
18 | | - .addSubcommand((subcommand) => |
19 | | - subcommand |
20 | | - .setName("status") |
21 | | - .setDescription("Check anti-raid status") |
22 | | - ), |
| 5 | + data: new SlashCommandBuilder() |
| 6 | + .setName("antiraid") |
| 7 | + .setDescription("🛡️ Simple anti-raid protection") |
| 8 | + .addSubcommand((subcommand) => |
| 9 | + subcommand |
| 10 | + .setName("enable") |
| 11 | + .setDescription("Enable anti-raid protection"), |
| 12 | + ) |
| 13 | + .addSubcommand((subcommand) => |
| 14 | + subcommand |
| 15 | + .setName("disable") |
| 16 | + .setDescription("Disable anti-raid protection"), |
| 17 | + ) |
| 18 | + .addSubcommand((subcommand) => |
| 19 | + subcommand.setName("status").setDescription("Check anti-raid status"), |
| 20 | + ), |
23 | 21 |
|
24 | | - async execute(interaction) { |
25 | | - if (!interaction.member.permissions.has("Administrator")) { |
26 | | - return interaction.reply({ |
27 | | - embeds: [ |
28 | | - new EmbedBuilder() |
29 | | - .setColor("#ff0000") |
30 | | - .setTitle("❌ No Permission") |
31 | | - .setDescription("You need Administrator permissions to use this command.") |
32 | | - ], |
33 | | - flags: 64 |
34 | | - }); |
35 | | - } |
| 22 | + async execute(interaction) { |
| 23 | + if (!interaction.member.permissions.has("Administrator")) { |
| 24 | + return interaction.reply({ |
| 25 | + embeds: [ |
| 26 | + new EmbedBuilder() |
| 27 | + .setColor("#ff0000") |
| 28 | + .setTitle("❌ No Permission") |
| 29 | + .setDescription( |
| 30 | + "You need Administrator permissions to use this command.", |
| 31 | + ), |
| 32 | + ], |
| 33 | + flags: 64, |
| 34 | + }); |
| 35 | + } |
36 | 36 |
|
37 | | - const subcommand = interaction.options.getSubcommand(); |
| 37 | + const subcommand = interaction.options.getSubcommand(); |
38 | 38 |
|
39 | | - try { |
40 | | - const db = Database; // Use the exported instance |
41 | | -await db.ensureConnection(); // Ensure connection is established |
42 | | - |
43 | | - switch (subcommand) { |
44 | | - case "enable": |
45 | | - await handleEnable(interaction, db); |
46 | | - break; |
47 | | - case "disable": |
48 | | - await handleDisable(interaction, db); |
49 | | - break; |
50 | | - case "status": |
51 | | - await handleStatus(interaction, db); |
52 | | - break; |
53 | | - } |
54 | | - } catch (error) { |
55 | | - console.error("Anti-raid command error:", error); |
56 | | - |
57 | | - await interaction.reply({ |
58 | | - embeds: [ |
59 | | - new EmbedBuilder() |
60 | | - .setColor("#ff0000") |
61 | | - .setTitle("❌ Error") |
62 | | - .setDescription("An error occurred while processing anti-raid command.") |
63 | | - ], |
64 | | - flags: 64 |
65 | | - }); |
66 | | - } |
67 | | - }, |
| 39 | + try { |
| 40 | + const db = await Database.getInstance(); |
| 41 | + await db.ensureConnection(); |
| 42 | + |
| 43 | + switch (subcommand) { |
| 44 | + case "enable": |
| 45 | + await handleEnable(interaction, db); |
| 46 | + break; |
| 47 | + case "disable": |
| 48 | + await handleDisable(interaction, db); |
| 49 | + break; |
| 50 | + case "status": |
| 51 | + await handleStatus(interaction, db); |
| 52 | + break; |
| 53 | + } |
| 54 | + } catch (error) { |
| 55 | + console.error("Anti-raid command error:", error); |
| 56 | + |
| 57 | + await interaction.reply({ |
| 58 | + embeds: [ |
| 59 | + new EmbedBuilder() |
| 60 | + .setColor("#ff0000") |
| 61 | + .setTitle("❌ Error") |
| 62 | + .setDescription( |
| 63 | + "An error occurred while processing anti-raid command.", |
| 64 | + ), |
| 65 | + ], |
| 66 | + flags: 64, |
| 67 | + }); |
| 68 | + } |
| 69 | + }, |
68 | 70 | }; |
69 | 71 |
|
70 | 72 | async function handleEnable(interaction, db) { |
71 | | - try { |
72 | | - await db.GuildConfig.findOneAndUpdate( |
73 | | - { guildId: interaction.guild.id }, |
74 | | - { |
75 | | - $set: { |
76 | | - antiRaidEnabled: true, |
77 | | - antiRaidThreshold: 5, |
78 | | - antiRaidTimeWindow: 10000 // 10 seconds |
79 | | - } |
80 | | - }, |
81 | | - { upsert: true, new: true } |
82 | | - ); |
| 73 | + try { |
| 74 | + await db.GuildConfig.findOneAndUpdate( |
| 75 | + { guildId: interaction.guild.id }, |
| 76 | + { |
| 77 | + $set: { |
| 78 | + antiRaidEnabled: true, |
| 79 | + antiRaidThreshold: 5, |
| 80 | + antiRaidTimeWindow: 10000, // 10 seconds |
| 81 | + }, |
| 82 | + }, |
| 83 | + { upsert: true, new: true }, |
| 84 | + ); |
83 | 85 |
|
84 | | - await interaction.reply({ |
85 | | - embeds: [ |
86 | | - new EmbedBuilder() |
87 | | - .setColor("#00ff00") |
88 | | - .setTitle("✅ Anti-Raid Enabled") |
89 | | - .setDescription("Anti-raid protection has been enabled with default settings.") |
90 | | - .addFields( |
91 | | - { name: "Threshold", value: "5 joins", inline: true }, |
92 | | - { name: "Time Window", value: "10 seconds", inline: true } |
93 | | - ) |
94 | | - ] |
95 | | - }); |
96 | | - } catch (error) { |
97 | | - console.error("Error enabling anti-raid:", error); |
98 | | - throw error; |
99 | | - } |
| 86 | + await interaction.reply({ |
| 87 | + embeds: [ |
| 88 | + new EmbedBuilder() |
| 89 | + .setColor("#00ff00") |
| 90 | + .setTitle("✅ Anti-Raid Enabled") |
| 91 | + .setDescription( |
| 92 | + "Anti-raid protection has been enabled with default settings.", |
| 93 | + ) |
| 94 | + .addFields( |
| 95 | + { name: "Threshold", value: "5 joins", inline: true }, |
| 96 | + { name: "Time Window", value: "10 seconds", inline: true }, |
| 97 | + ), |
| 98 | + ], |
| 99 | + }); |
| 100 | + } catch (error) { |
| 101 | + console.error("Error enabling anti-raid:", error); |
| 102 | + throw error; |
| 103 | + } |
100 | 104 | } |
101 | 105 |
|
102 | 106 | async function handleDisable(interaction, db) { |
103 | | - try { |
104 | | - await db.GuildConfig.findOneAndUpdate( |
105 | | - { guildId: interaction.guild.id }, |
106 | | - { $set: { antiRaidEnabled: false } }, |
107 | | - { upsert: true, new: true } |
108 | | - ); |
| 107 | + try { |
| 108 | + await db.GuildConfig.findOneAndUpdate( |
| 109 | + { guildId: interaction.guild.id }, |
| 110 | + { $set: { antiRaidEnabled: false } }, |
| 111 | + { upsert: true, new: true }, |
| 112 | + ); |
109 | 113 |
|
110 | | - await interaction.reply({ |
111 | | - embeds: [ |
112 | | - new EmbedBuilder() |
113 | | - .setColor("#ff0000") |
114 | | - .setTitle("❌ Anti-Raid Disabled") |
115 | | - .setDescription("Anti-raid protection has been disabled.") |
116 | | - ] |
117 | | - }); |
118 | | - } catch (error) { |
119 | | - console.error("Error disabling anti-raid:", error); |
120 | | - throw error; |
121 | | - } |
| 114 | + await interaction.reply({ |
| 115 | + embeds: [ |
| 116 | + new EmbedBuilder() |
| 117 | + .setColor("#ff0000") |
| 118 | + .setTitle("❌ Anti-Raid Disabled") |
| 119 | + .setDescription("Anti-raid protection has been disabled."), |
| 120 | + ], |
| 121 | + }); |
| 122 | + } catch (error) { |
| 123 | + console.error("Error disabling anti-raid:", error); |
| 124 | + throw error; |
| 125 | + } |
122 | 126 | } |
123 | 127 |
|
124 | 128 | async function handleStatus(interaction, db) { |
125 | | - try { |
126 | | - const config = await db.GuildConfig.findOne({ guildId: interaction.guild.id }); |
127 | | - |
128 | | - const isEnabled = config?.antiRaidEnabled || false; |
129 | | - const threshold = config?.antiRaidThreshold || 5; |
130 | | - const timeWindow = config?.antiRaidTimeWindow || 10000; |
| 129 | + try { |
| 130 | + const config = await db.GuildConfig.findOne({ |
| 131 | + guildId: interaction.guild.id, |
| 132 | + }); |
| 133 | + |
| 134 | + const isEnabled = config?.antiRaidEnabled || false; |
| 135 | + const threshold = config?.antiRaidThreshold || 5; |
| 136 | + const timeWindow = config?.antiRaidTimeWindow || 10000; |
131 | 137 |
|
132 | | - await interaction.reply({ |
133 | | - embeds: [ |
134 | | - new EmbedBuilder() |
135 | | - .setColor(isEnabled ? "#00ff00" : "#ff0000") |
136 | | - .setTitle("🛡️ Anti-Raid Status") |
137 | | - .addFields( |
138 | | - { name: "Status", value: isEnabled ? "✅ Enabled" : "❌ Disabled", inline: true }, |
139 | | - { name: "Threshold", value: `${threshold} joins`, inline: true }, |
140 | | - { name: "Time Window", value: `${timeWindow / 1000} seconds`, inline: true } |
141 | | - ) |
142 | | - ] |
143 | | - }); |
144 | | - } catch (error) { |
145 | | - console.error("Error checking anti-raid status:", error); |
146 | | - throw error; |
147 | | - } |
| 138 | + await interaction.reply({ |
| 139 | + embeds: [ |
| 140 | + new EmbedBuilder() |
| 141 | + .setColor(isEnabled ? "#00ff00" : "#ff0000") |
| 142 | + .setTitle("🛡️ Anti-Raid Status") |
| 143 | + .addFields( |
| 144 | + { |
| 145 | + name: "Status", |
| 146 | + value: isEnabled ? "✅ Enabled" : "❌ Disabled", |
| 147 | + inline: true, |
| 148 | + }, |
| 149 | + { name: "Threshold", value: `${threshold} joins`, inline: true }, |
| 150 | + { |
| 151 | + name: "Time Window", |
| 152 | + value: `${timeWindow / 1000} seconds`, |
| 153 | + inline: true, |
| 154 | + }, |
| 155 | + ), |
| 156 | + ], |
| 157 | + }); |
| 158 | + } catch (error) { |
| 159 | + console.error("Error checking anti-raid status:", error); |
| 160 | + throw error; |
| 161 | + } |
148 | 162 | } |
0 commit comments