Brozy123 commited on
Commit
2cd0b57
·
verified ·
1 Parent(s): 6476d1f

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +60 -2
index.js CHANGED
@@ -225,7 +225,9 @@ const commandsData = [
225
  { name: 'player1', type: 6, description: 'First player', required: true },
226
  { name: 'player2', type: 6, description: 'Second player', required: true }
227
  ]
228
- }
 
 
229
  ];
230
 
231
  client.once('ready', async () => {
@@ -453,6 +455,13 @@ client.on('messageCreate', async (message) => {
453
  return;
454
  }
455
 
 
 
 
 
 
 
 
456
  // Removed locks for better responsiveness as requested by user
457
  const userId = String(message.author?.id || 'unknown');
458
 
@@ -793,6 +802,26 @@ client.on('messageCreate', async (message) => {
793
  return;
794
  }
795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
796
  if (commandName === 'clear') {
797
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
798
  const amount = parseInt(args[0]);
@@ -1209,6 +1238,13 @@ client.on('interactionCreate', async (interaction) => {
1209
  }
1210
  }
1211
  if (interaction.isChatInputCommand()) {
 
 
 
 
 
 
 
1212
  try {
1213
  logTransaction(client, interaction.commandName, interaction.user, interaction.guild, interaction.member);
1214
 
@@ -1379,7 +1415,29 @@ client.on('interactionCreate', async (interaction) => {
1379
  if (interaction.commandName === 'friendlybotsettings') {
1380
  const roles = roleStorage.roles[interaction.guildId] || [];
1381
  const rInfo = roles.length > 0 ? roles.map(r => `<@&${r}>`).join(', ') : "Only administrator.";
1382
- await safeReply(interaction, { content: `🟢 **Online**\nWhitelist: ${rInfo}` });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1383
  }
1384
 
1385
  if (interaction.commandName === 'lineup') {
 
225
  { name: 'player1', type: 6, description: 'First player', required: true },
226
  { name: 'player2', type: 6, description: 'Second player', required: true }
227
  ]
228
+ },
229
+ { name: 'on', description: 'Turn the bot on' },
230
+ { name: 'off', description: 'Turn the bot off' }
231
  ];
232
 
233
  client.once('ready', async () => {
 
455
  return;
456
  }
457
 
458
+ const config = storage.data.config[message.guildId] || {};
459
+ const botEnabled = config.botEnabled !== false; // Default to true if not set
460
+
461
+ if (!botEnabled && commandName !== 'on') {
462
+ return message.reply("⚠️ The bot is currently **OFF**. Please use `/on` if you want to use the bot.");
463
+ }
464
+
465
  // Removed locks for better responsiveness as requested by user
466
  const userId = String(message.author?.id || 'unknown');
467
 
 
802
  return;
803
  }
804
 
805
+ if (commandName === 'on') {
806
+ if (!message.member.permissions.has('Administrator') && !roleStorage.isWhitelisted(message.guildId, message.member)) {
807
+ return sendNoPermission(message);
808
+ }
809
+ if (!storage.data.config[message.guildId]) storage.data.config[message.guildId] = {};
810
+ storage.data.config[message.guildId].botEnabled = true;
811
+ storage.save('config');
812
+ return message.reply("✅ The bot has been turned **ON**.");
813
+ }
814
+
815
+ if (commandName === 'off') {
816
+ if (!message.member.permissions.has('Administrator') && !roleStorage.isWhitelisted(message.guildId, message.member)) {
817
+ return sendNoPermission(message);
818
+ }
819
+ if (!storage.data.config[message.guildId]) storage.data.config[message.guildId] = {};
820
+ storage.data.config[message.guildId].botEnabled = false;
821
+ storage.save('config');
822
+ return message.reply("❌ The bot has been turned **OFF**. Use `/on` to re-enable it.");
823
+ }
824
+
825
  if (commandName === 'clear') {
826
  if (!roleStorage.isWhitelisted(message.guildId, message.member)) return sendNoPermission(message);
827
  const amount = parseInt(args[0]);
 
1238
  }
1239
  }
1240
  if (interaction.isChatInputCommand()) {
1241
+ const config = storage.data.config[interaction.guildId] || {};
1242
+ const botEnabled = config.botEnabled !== false;
1243
+
1244
+ if (!botEnabled && interaction.commandName !== 'on') {
1245
+ return safeReply(interaction, { content: "⚠️ The bot is currently **OFF**. Please use `/on` if you want to use the bot.", flags: [MessageFlags.Ephemeral] });
1246
+ }
1247
+
1248
  try {
1249
  logTransaction(client, interaction.commandName, interaction.user, interaction.guild, interaction.member);
1250
 
 
1415
  if (interaction.commandName === 'friendlybotsettings') {
1416
  const roles = roleStorage.roles[interaction.guildId] || [];
1417
  const rInfo = roles.length > 0 ? roles.map(r => `<@&${r}>`).join(', ') : "Only administrator.";
1418
+ const config = storage.data.config[interaction.guildId] || {};
1419
+ const status = config.botEnabled !== false ? "🟢 **Online**" : "🔴 **Offline**";
1420
+ await safeReply(interaction, { content: `${status}\nWhitelist: ${rInfo}` });
1421
+ }
1422
+
1423
+ if (interaction.commandName === 'on') {
1424
+ if (!interaction.member.permissions.has('Administrator') && !roleStorage.isWhitelisted(interaction.guildId, interaction.member)) {
1425
+ return sendNoPermission(interaction);
1426
+ }
1427
+ if (!storage.data.config[interaction.guildId]) storage.data.config[interaction.guildId] = {};
1428
+ storage.data.config[interaction.guildId].botEnabled = true;
1429
+ storage.save('config');
1430
+ await safeReply(interaction, "✅ The bot has been turned **ON**.");
1431
+ }
1432
+
1433
+ if (interaction.commandName === 'off') {
1434
+ if (!interaction.member.permissions.has('Administrator') && !roleStorage.isWhitelisted(interaction.guildId, interaction.member)) {
1435
+ return sendNoPermission(interaction);
1436
+ }
1437
+ if (!storage.data.config[interaction.guildId]) storage.data.config[interaction.guildId] = {};
1438
+ storage.data.config[interaction.guildId].botEnabled = false;
1439
+ storage.save('config');
1440
+ await safeReply(interaction, "❌ The bot has been turned **OFF**. Use `/on` to re-enable it.");
1441
  }
1442
 
1443
  if (interaction.commandName === 'lineup') {