Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
require('dotenv').config();
|
| 2 |
const { Client, GatewayIntentBits, Partials, Collection, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, UserSelectMenuBuilder, ComponentType } = require('discord.js');
|
| 3 |
const storage = require('./storage');
|
|
|
|
| 4 |
const networkFix = require('./network_fix');
|
| 5 |
const server = require('./server');
|
| 6 |
const { UI } = require('./NewBotStyle');
|
|
@@ -130,7 +131,7 @@ client.on('messageCreate', async (message) => {
|
|
| 130 |
}
|
| 131 |
|
| 132 |
if (commandName === 'friendly') {
|
| 133 |
-
if (!
|
| 134 |
const needed = parseInt(args[0]) || 7;
|
| 135 |
const content = `⭐▬▬▬▬▬ **FRIENDLY** ▬▬▬▬▬⭐\n🤝 Session\n🟩 I'm In\n🟥 Busy\n⭐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬⭐\n🗳️ Needed: ${needed}\n@everyone`;
|
| 136 |
const msg = await message.channel.send({ content, allowedMentions: { parse: ['everyone'] } });
|
|
@@ -141,7 +142,7 @@ client.on('messageCreate', async (message) => {
|
|
| 141 |
}
|
| 142 |
|
| 143 |
if (commandName === 'lineup') {
|
| 144 |
-
if (!
|
| 145 |
guildLineups.set(message.guildId, new Map());
|
| 146 |
await message.channel.send(createLineupView(message.guildId));
|
| 147 |
}
|
|
@@ -158,18 +159,13 @@ client.on('messageCreate', async (message) => {
|
|
| 158 |
}
|
| 159 |
|
| 160 |
if (commandName === 'friendlybotsettings') {
|
| 161 |
-
const roles =
|
| 162 |
const rInfo = roles.length > 0 ? roles.map(r => `<@&${r}>`).join(', ') : "Only administrator.";
|
| 163 |
await message.reply(`🟢 **Online**\nWhitelist: ${rInfo}`);
|
| 164 |
}
|
| 165 |
|
| 166 |
-
if (commandName === 'record') {
|
| 167 |
-
const r = storage.getRecord(message.guildId);
|
| 168 |
-
await message.reply({ embeds: [UI.createEmbed("📊 Server Match Record", `✅ Wins: \`${r.wins}\`\n🟥 Losses: \`${r.losses}\`\n🤝 Draws: \`${r.draws}\``)] });
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
if (commandName === 'win' || commandName === 'loss' || commandName === 'draw') {
|
| 172 |
-
if (!
|
| 173 |
const type = commandName;
|
| 174 |
const res = args[0] || "?-?";
|
| 175 |
const scorers = args.slice(1).join(" ");
|
|
@@ -185,7 +181,7 @@ client.on('messageCreate', async (message) => {
|
|
| 185 |
}
|
| 186 |
|
| 187 |
if (commandName === 'leaguematch') {
|
| 188 |
-
if (!
|
| 189 |
const home = args[0] || "Home";
|
| 190 |
const away = args[1] || "Away";
|
| 191 |
const link = args.find(a => a.includes('http')) || "TBA";
|
|
@@ -204,7 +200,7 @@ client.on('messageCreate', async (message) => {
|
|
| 204 |
}
|
| 205 |
|
| 206 |
if (commandName === 'clear') {
|
| 207 |
-
if (!
|
| 208 |
const amount = parseInt(args[0]);
|
| 209 |
if (amount) {
|
| 210 |
await message.channel.bulkDelete(amount, true);
|
|
@@ -214,13 +210,13 @@ client.on('messageCreate', async (message) => {
|
|
| 214 |
}
|
| 215 |
|
| 216 |
if (commandName === 'lock') {
|
| 217 |
-
if (!
|
| 218 |
await message.channel.permissionOverwrites.edit(message.guild.roles.everyone, { SendMessages: false });
|
| 219 |
await message.reply("🔒 Channel Locked.");
|
| 220 |
}
|
| 221 |
|
| 222 |
if (commandName === 'unlock') {
|
| 223 |
-
if (!
|
| 224 |
await message.channel.permissionOverwrites.edit(message.guild.roles.everyone, { SendMessages: true });
|
| 225 |
await message.reply("🔓 Channel Unlocked.");
|
| 226 |
}
|
|
@@ -260,7 +256,7 @@ client.on('messageCreate', async (message) => {
|
|
| 260 |
}
|
| 261 |
|
| 262 |
if (commandName === 'sendlink') {
|
| 263 |
-
if (!
|
| 264 |
await message.channel.send(`Link : ${args[0] || 'None'}`);
|
| 265 |
}
|
| 266 |
|
|
@@ -333,15 +329,13 @@ client.on('messageCreate', async (message) => {
|
|
| 333 |
if (!role) return message.reply("❌ Please mention a role! (e.g. `!addrole @Staff`)");
|
| 334 |
|
| 335 |
const gid = message.guildId;
|
| 336 |
-
if (!storage.data.roles[gid]) storage.data.roles[gid] = [];
|
| 337 |
|
| 338 |
if (commandName === 'addrole') {
|
| 339 |
-
|
| 340 |
} else {
|
| 341 |
-
|
| 342 |
}
|
| 343 |
|
| 344 |
-
storage.save('roles');
|
| 345 |
await message.reply(`✅ Updated whitelist for ${role.name}`);
|
| 346 |
}
|
| 347 |
|
|
@@ -351,7 +345,7 @@ client.on('messageCreate', async (message) => {
|
|
| 351 |
}
|
| 352 |
|
| 353 |
if (commandName === 'lineupimage') {
|
| 354 |
-
if (!
|
| 355 |
const waitMsg = await message.reply('⏳ **Generating lineup image...**');
|
| 356 |
try {
|
| 357 |
const lineup = getGuildLineup(message.guildId);
|
|
@@ -372,7 +366,7 @@ client.on('messageCreate', async (message) => {
|
|
| 372 |
}
|
| 373 |
|
| 374 |
if (commandName === 'managerlineup') {
|
| 375 |
-
if (!
|
| 376 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 377 |
const row = new ActionRowBuilder().addComponents(
|
| 378 |
new StringSelectMenuBuilder()
|
|
@@ -392,7 +386,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 392 |
}
|
| 393 |
|
| 394 |
if (interaction.commandName === 'friendly') {
|
| 395 |
-
if (!
|
| 396 |
const needed = interaction.options.getInteger('needed') || 7;
|
| 397 |
const content = `⭐▬▬▬▬▬ **FRIENDLY** ▬▬▬▬▬⭐\n🤝 Session\n🟩 I'm In\n🟥 Busy\n⭐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬⭐\n🗳️ Needed: ${needed}\n@everyone`;
|
| 398 |
const msg = await interaction.reply({ content, fetchReply: true, allowedMentions: { parse: ['everyone'] } });
|
|
@@ -403,7 +397,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 403 |
}
|
| 404 |
|
| 405 |
if (interaction.commandName === 'leaguematch') {
|
| 406 |
-
if (!
|
| 407 |
const home = interaction.options.getString('home');
|
| 408 |
const away = interaction.options.getString('away');
|
| 409 |
const link = interaction.options.getString('link');
|
|
@@ -431,7 +425,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 431 |
}
|
| 432 |
|
| 433 |
if (interaction.commandName === 'win' || interaction.commandName === 'loss' || interaction.commandName === 'draw') {
|
| 434 |
-
if (!
|
| 435 |
|
| 436 |
const type = interaction.commandName;
|
| 437 |
const res = interaction.options.getString('result');
|
|
@@ -489,32 +483,32 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 489 |
}
|
| 490 |
|
| 491 |
if (interaction.commandName === 'friendlybotsettings') {
|
| 492 |
-
const roles =
|
| 493 |
const rInfo = roles.length > 0 ? roles.map(r => `<@&${r}>`).join(', ') : "Only administrator.";
|
| 494 |
await interaction.reply(`🟢 **Online**\nWhitelist: ${rInfo}`);
|
| 495 |
}
|
| 496 |
|
| 497 |
if (interaction.commandName === 'lineup') {
|
| 498 |
-
if (!
|
| 499 |
guildLineups.set(interaction.guildId, new Map());
|
| 500 |
await interaction.reply(createLineupView(interaction.guildId));
|
| 501 |
}
|
| 502 |
|
| 503 |
if (interaction.commandName === 'clear') {
|
| 504 |
-
if (!
|
| 505 |
const amount = interaction.options.getInteger('amount');
|
| 506 |
await interaction.channel.bulkDelete(amount, true);
|
| 507 |
await interaction.reply({ content: `✅ Cleared ${amount} messages.`, ephemeral: true });
|
| 508 |
}
|
| 509 |
|
| 510 |
if (interaction.commandName === 'lock') {
|
| 511 |
-
if (!
|
| 512 |
await interaction.channel.permissionOverwrites.edit(interaction.guild.roles.everyone, { SendMessages: false });
|
| 513 |
await interaction.reply("🔒 Channel Locked.");
|
| 514 |
}
|
| 515 |
|
| 516 |
if (interaction.commandName === 'unlock') {
|
| 517 |
-
if (!
|
| 518 |
await interaction.channel.permissionOverwrites.edit(interaction.guild.roles.everyone, { SendMessages: true });
|
| 519 |
await interaction.reply("🔓 Channel Unlocked.");
|
| 520 |
}
|
|
@@ -535,7 +529,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 535 |
}
|
| 536 |
|
| 537 |
if (interaction.commandName === 'sendlink') {
|
| 538 |
-
if (!
|
| 539 |
const link = interaction.options.getString('link');
|
| 540 |
await interaction.reply(`Link : ${link}`);
|
| 541 |
}
|
|
@@ -554,20 +548,18 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 554 |
if (!role) return interaction.reply({ content: "❌ Please select a role!", ephemeral: true });
|
| 555 |
|
| 556 |
const gid = interaction.guildId;
|
| 557 |
-
if (!storage.data.roles[gid]) storage.data.roles[gid] = [];
|
| 558 |
|
| 559 |
if (interaction.commandName === 'addrole') {
|
| 560 |
-
|
| 561 |
} else {
|
| 562 |
-
|
| 563 |
}
|
| 564 |
|
| 565 |
-
storage.save('roles');
|
| 566 |
await interaction.reply(`✅ Updated whitelist for <@&${role.id}>`);
|
| 567 |
}
|
| 568 |
|
| 569 |
if (interaction.commandName === 'managerlineup') {
|
| 570 |
-
if (!
|
| 571 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 572 |
const row = new ActionRowBuilder().addComponents(
|
| 573 |
new StringSelectMenuBuilder()
|
|
@@ -579,7 +571,7 @@ client.on('interactionCreate', async (interaction) => {
|
|
| 579 |
}
|
| 580 |
|
| 581 |
if (interaction.commandName === 'lineupimage') {
|
| 582 |
-
if (!
|
| 583 |
await interaction.deferReply();
|
| 584 |
try {
|
| 585 |
const lineup = getGuildLineup(interaction.guildId);
|
|
|
|
| 1 |
require('dotenv').config();
|
| 2 |
const { Client, GatewayIntentBits, Partials, Collection, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, UserSelectMenuBuilder, ComponentType } = require('discord.js');
|
| 3 |
const storage = require('./storage');
|
| 4 |
+
const roleStorage = require('./roleStorage');
|
| 5 |
const networkFix = require('./network_fix');
|
| 6 |
const server = require('./server');
|
| 7 |
const { UI } = require('./NewBotStyle');
|
|
|
|
| 131 |
}
|
| 132 |
|
| 133 |
if (commandName === 'friendly') {
|
| 134 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 135 |
const needed = parseInt(args[0]) || 7;
|
| 136 |
const content = `⭐▬▬▬▬▬ **FRIENDLY** ▬▬▬▬▬⭐\n🤝 Session\n🟩 I'm In\n🟥 Busy\n⭐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬⭐\n🗳️ Needed: ${needed}\n@everyone`;
|
| 137 |
const msg = await message.channel.send({ content, allowedMentions: { parse: ['everyone'] } });
|
|
|
|
| 142 |
}
|
| 143 |
|
| 144 |
if (commandName === 'lineup') {
|
| 145 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 146 |
guildLineups.set(message.guildId, new Map());
|
| 147 |
await message.channel.send(createLineupView(message.guildId));
|
| 148 |
}
|
|
|
|
| 159 |
}
|
| 160 |
|
| 161 |
if (commandName === 'friendlybotsettings') {
|
| 162 |
+
const roles = roleStorage.roles[message.guildId] || [];
|
| 163 |
const rInfo = roles.length > 0 ? roles.map(r => `<@&${r}>`).join(', ') : "Only administrator.";
|
| 164 |
await message.reply(`🟢 **Online**\nWhitelist: ${rInfo}`);
|
| 165 |
}
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
if (commandName === 'win' || commandName === 'loss' || commandName === 'draw') {
|
| 168 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 169 |
const type = commandName;
|
| 170 |
const res = args[0] || "?-?";
|
| 171 |
const scorers = args.slice(1).join(" ");
|
|
|
|
| 181 |
}
|
| 182 |
|
| 183 |
if (commandName === 'leaguematch') {
|
| 184 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 185 |
const home = args[0] || "Home";
|
| 186 |
const away = args[1] || "Away";
|
| 187 |
const link = args.find(a => a.includes('http')) || "TBA";
|
|
|
|
| 200 |
}
|
| 201 |
|
| 202 |
if (commandName === 'clear') {
|
| 203 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 204 |
const amount = parseInt(args[0]);
|
| 205 |
if (amount) {
|
| 206 |
await message.channel.bulkDelete(amount, true);
|
|
|
|
| 210 |
}
|
| 211 |
|
| 212 |
if (commandName === 'lock') {
|
| 213 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 214 |
await message.channel.permissionOverwrites.edit(message.guild.roles.everyone, { SendMessages: false });
|
| 215 |
await message.reply("🔒 Channel Locked.");
|
| 216 |
}
|
| 217 |
|
| 218 |
if (commandName === 'unlock') {
|
| 219 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 220 |
await message.channel.permissionOverwrites.edit(message.guild.roles.everyone, { SendMessages: true });
|
| 221 |
await message.reply("🔓 Channel Unlocked.");
|
| 222 |
}
|
|
|
|
| 256 |
}
|
| 257 |
|
| 258 |
if (commandName === 'sendlink') {
|
| 259 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 260 |
await message.channel.send(`Link : ${args[0] || 'None'}`);
|
| 261 |
}
|
| 262 |
|
|
|
|
| 329 |
if (!role) return message.reply("❌ Please mention a role! (e.g. `!addrole @Staff`)");
|
| 330 |
|
| 331 |
const gid = message.guildId;
|
|
|
|
| 332 |
|
| 333 |
if (commandName === 'addrole') {
|
| 334 |
+
roleStorage.addRole(gid, role.id);
|
| 335 |
} else {
|
| 336 |
+
roleStorage.removeRole(gid, role.id);
|
| 337 |
}
|
| 338 |
|
|
|
|
| 339 |
await message.reply(`✅ Updated whitelist for ${role.name}`);
|
| 340 |
}
|
| 341 |
|
|
|
|
| 345 |
}
|
| 346 |
|
| 347 |
if (commandName === 'lineupimage') {
|
| 348 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 349 |
const waitMsg = await message.reply('⏳ **Generating lineup image...**');
|
| 350 |
try {
|
| 351 |
const lineup = getGuildLineup(message.guildId);
|
|
|
|
| 366 |
}
|
| 367 |
|
| 368 |
if (commandName === 'managerlineup') {
|
| 369 |
+
if (!roleStorage.isWhitelisted(message.guildId, message.member)) return message.reply("❌ No Permission");
|
| 370 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 371 |
const row = new ActionRowBuilder().addComponents(
|
| 372 |
new StringSelectMenuBuilder()
|
|
|
|
| 386 |
}
|
| 387 |
|
| 388 |
if (interaction.commandName === 'friendly') {
|
| 389 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 390 |
const needed = interaction.options.getInteger('needed') || 7;
|
| 391 |
const content = `⭐▬▬▬▬▬ **FRIENDLY** ▬▬▬▬▬⭐\n🤝 Session\n🟩 I'm In\n🟥 Busy\n⭐▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬⭐\n🗳️ Needed: ${needed}\n@everyone`;
|
| 392 |
const msg = await interaction.reply({ content, fetchReply: true, allowedMentions: { parse: ['everyone'] } });
|
|
|
|
| 397 |
}
|
| 398 |
|
| 399 |
if (interaction.commandName === 'leaguematch') {
|
| 400 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 401 |
const home = interaction.options.getString('home');
|
| 402 |
const away = interaction.options.getString('away');
|
| 403 |
const link = interaction.options.getString('link');
|
|
|
|
| 425 |
}
|
| 426 |
|
| 427 |
if (interaction.commandName === 'win' || interaction.commandName === 'loss' || interaction.commandName === 'draw') {
|
| 428 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 429 |
|
| 430 |
const type = interaction.commandName;
|
| 431 |
const res = interaction.options.getString('result');
|
|
|
|
| 483 |
}
|
| 484 |
|
| 485 |
if (interaction.commandName === 'friendlybotsettings') {
|
| 486 |
+
const roles = roleStorage.roles[interaction.guildId] || [];
|
| 487 |
const rInfo = roles.length > 0 ? roles.map(r => `<@&${r}>`).join(', ') : "Only administrator.";
|
| 488 |
await interaction.reply(`🟢 **Online**\nWhitelist: ${rInfo}`);
|
| 489 |
}
|
| 490 |
|
| 491 |
if (interaction.commandName === 'lineup') {
|
| 492 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 493 |
guildLineups.set(interaction.guildId, new Map());
|
| 494 |
await interaction.reply(createLineupView(interaction.guildId));
|
| 495 |
}
|
| 496 |
|
| 497 |
if (interaction.commandName === 'clear') {
|
| 498 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 499 |
const amount = interaction.options.getInteger('amount');
|
| 500 |
await interaction.channel.bulkDelete(amount, true);
|
| 501 |
await interaction.reply({ content: `✅ Cleared ${amount} messages.`, ephemeral: true });
|
| 502 |
}
|
| 503 |
|
| 504 |
if (interaction.commandName === 'lock') {
|
| 505 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 506 |
await interaction.channel.permissionOverwrites.edit(interaction.guild.roles.everyone, { SendMessages: false });
|
| 507 |
await interaction.reply("🔒 Channel Locked.");
|
| 508 |
}
|
| 509 |
|
| 510 |
if (interaction.commandName === 'unlock') {
|
| 511 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 512 |
await interaction.channel.permissionOverwrites.edit(interaction.guild.roles.everyone, { SendMessages: true });
|
| 513 |
await interaction.reply("🔓 Channel Unlocked.");
|
| 514 |
}
|
|
|
|
| 529 |
}
|
| 530 |
|
| 531 |
if (interaction.commandName === 'sendlink') {
|
| 532 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 533 |
const link = interaction.options.getString('link');
|
| 534 |
await interaction.reply(`Link : ${link}`);
|
| 535 |
}
|
|
|
|
| 548 |
if (!role) return interaction.reply({ content: "❌ Please select a role!", ephemeral: true });
|
| 549 |
|
| 550 |
const gid = interaction.guildId;
|
|
|
|
| 551 |
|
| 552 |
if (interaction.commandName === 'addrole') {
|
| 553 |
+
roleStorage.addRole(gid, role.id);
|
| 554 |
} else {
|
| 555 |
+
roleStorage.removeRole(gid, role.id);
|
| 556 |
}
|
| 557 |
|
|
|
|
| 558 |
await interaction.reply(`✅ Updated whitelist for <@&${role.id}>`);
|
| 559 |
}
|
| 560 |
|
| 561 |
if (interaction.commandName === 'managerlineup') {
|
| 562 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 563 |
const formOptions = Object.keys(FORMATIONS).slice(0, 25).map(k => ({ label: k, value: k }));
|
| 564 |
const row = new ActionRowBuilder().addComponents(
|
| 565 |
new StringSelectMenuBuilder()
|
|
|
|
| 571 |
}
|
| 572 |
|
| 573 |
if (interaction.commandName === 'lineupimage') {
|
| 574 |
+
if (!roleStorage.isWhitelisted(interaction.guildId, interaction.member)) return interaction.reply({ content: "❌ No Permission", ephemeral: true });
|
| 575 |
await interaction.deferReply();
|
| 576 |
try {
|
| 577 |
const lineup = getGuildLineup(interaction.guildId);
|