Spaces:
Runtime error
Runtime error
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
require('dotenv').config();
|
| 2 |
+
const { Client, GatewayIntentBits, Partials, Collection, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, SelectMenuBuilder, 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');
|
| 7 |
+
|
| 8 |
+
// Apply network fixes early
|
| 9 |
+
networkFix.applyAdvancedFixes();
|
| 10 |
+
|
| 11 |
+
const client = new Client({
|
| 12 |
+
intents: [
|
| 13 |
+
GatewayIntentBits.Guilds,
|
| 14 |
+
GatewayIntentBits.GuildMessages,
|
| 15 |
+
GatewayIntentBits.MessageContent,
|
| 16 |
+
GatewayIntentBits.GuildMessageReactions,
|
| 17 |
+
GatewayIntentBits.GuildMembers
|
| 18 |
+
],
|
| 19 |
+
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
client.commands = new Collection();
|
| 23 |
+
|
| 24 |
+
// --- 1. CONFIG ---
|
| 25 |
+
const TOKEN = process.env.BOT_TOKEN || process.env.TOKEN;
|
| 26 |
+
const PREFIX = "!";
|
| 27 |
+
|
| 28 |
+
// --- 2. COMMAND REGISTRATION (Minimal set for porting) ---
|
| 29 |
+
client.once('ready', async () => {
|
| 30 |
+
console.log(`[*] Logged in as ${client.user.tag}`);
|
| 31 |
+
console.log(`[*] Servers: ${client.guilds.cache.size}`);
|
| 32 |
+
|
| 33 |
+
// Sync Slash Commands
|
| 34 |
+
const commandsData = [
|
| 35 |
+
{
|
| 36 |
+
name: 'ping',
|
| 37 |
+
description: 'Check bot latency'
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
name: 'friendly',
|
| 41 |
+
description: 'Start a friendly match poll',
|
| 42 |
+
options: [
|
| 43 |
+
{ name: 'needed', type: 4, description: 'Players needed (default 6)', required: false }
|
| 44 |
+
]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
name: 'lineup',
|
| 48 |
+
description: 'Show current lineup board'
|
| 49 |
+
}
|
| 50 |
+
];
|
| 51 |
+
|
| 52 |
+
try {
|
| 53 |
+
await client.application.commands.set(commandsData);
|
| 54 |
+
console.log('[*] Slash commands registered.');
|
| 55 |
+
} catch (e) {
|
| 56 |
+
console.error(`[*] Register Error: ${e}`);
|
| 57 |
+
}
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
// --- 3. EVENT HANDLERS ---
|
| 61 |
+
|
| 62 |
+
// Message Command Handler
|
| 63 |
+
client.on('messageCreate', async (message) => {
|
| 64 |
+
if (message.author.bot || !message.content.startsWith(PREFIX)) return;
|
| 65 |
+
|
| 66 |
+
const args = message.content.slice(PREFIX.length).trim().split(/ +/);
|
| 67 |
+
const commandName = args.shift().toLowerCase();
|
| 68 |
+
|
| 69 |
+
if (commandName === 'ping') {
|
| 70 |
+
const msg = await message.reply('Pinging...');
|
| 71 |
+
msg.edit(`Pong! Latency: ${msg.createdTimestamp - message.createdTimestamp}ms`);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if (commandName === 'lineup') {
|
| 75 |
+
// Implementation of lineup command
|
| 76 |
+
await message.reply({ content: "**Lineup System** (Porting in progress...)", ephemeral: true });
|
| 77 |
+
}
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
// Interaction Handler
|
| 81 |
+
client.on('interactionCreate', async (interaction) => {
|
| 82 |
+
if (interaction.isChatInputCommand()) {
|
| 83 |
+
if (interaction.commandName === 'ping') {
|
| 84 |
+
await interaction.reply(`Latency: ${client.ws.ping}ms`);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if (interaction.commandName === 'friendly') {
|
| 88 |
+
const needed = interaction.options.getInteger('needed') || 6;
|
| 89 |
+
const embed = UI.createEmbed(
|
| 90 |
+
`${UI.icons.match} Friendly Match Poll`,
|
| 91 |
+
`React with 🟩 to join!\nNeeded: **${needed}** players.`,
|
| 92 |
+
UI.colors.success
|
| 93 |
+
);
|
| 94 |
+
|
| 95 |
+
const msg = await interaction.reply({ embeds: [embed], fetchReply: true });
|
| 96 |
+
await msg.react('🟩');
|
| 97 |
+
|
| 98 |
+
// Store active poll
|
| 99 |
+
storage.data.active_polls[interaction.guildId] = msg.id;
|
| 100 |
+
storage.save('polls');
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
});
|
| 104 |
+
|
| 105 |
+
// Start the health server
|
| 106 |
+
server.startServer();
|
| 107 |
+
|
| 108 |
+
// Connection error handling
|
| 109 |
+
client.on('error', (e) => console.error(`[!] Discord Client Error: ${e}`));
|
| 110 |
+
|
| 111 |
+
client.login(TOKEN).catch(e => {
|
| 112 |
+
console.error(`[!] Login Failed: ${e}`);
|
| 113 |
+
process.exit(1);
|
| 114 |
+
});
|