2026-02-14 11:37:04 -05:00
|
|
|
import { Client, Events, GatewayOpcodes } from '@fluxerjs/core';
|
2026-02-13 18:20:29 -05:00
|
|
|
import { messageHelper } from "./helpers/messageHelper.js";
|
2026-02-13 22:19:06 -05:00
|
|
|
import {enums} from "./enums.js";
|
2026-02-14 11:37:04 -05:00
|
|
|
import {commands} from "./commands.js";
|
2026-02-13 18:20:29 -05:00
|
|
|
|
|
|
|
|
const token = process.env.FLUXER_BOT_TOKEN;
|
|
|
|
|
|
|
|
|
|
if (!token) {
|
|
|
|
|
console.error("Missing FLUXER_BOT_TOKEN environment variable.");
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
const BOT_STATUS = process.env.FLUXER_BOT_STATUS ?? 'online';
|
|
|
|
|
const client = new Client({ intents: 0 });
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
client.on(Events.MessageCreate, async (message) => {
|
|
|
|
|
try {
|
|
|
|
|
// Ignore bots and messages without content
|
|
|
|
|
if (message.author.bot || !message.content) return;
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
// Parse command and arguments
|
|
|
|
|
const content = message.content.trim();
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
// If message doesn't start with the bot prefix, it could still be a message with a proxy tag
|
|
|
|
|
if (!content.startsWith(messageHelper.prefix)) {
|
|
|
|
|
// wait until webhooks exist lol
|
|
|
|
|
//const successful = await webhookHelper.sendMessageAsMember(message, content);
|
|
|
|
|
// if (!successful) return;
|
|
|
|
|
}
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
const commandName = content.slice(messageHelper.prefix.length).split(" ")[0];
|
|
|
|
|
// If there's no command name (ie just the prefix)
|
|
|
|
|
if (!commandName) return await message.reply(enums.help.SHORT_DESC_PLURALFLUX);
|
2026-02-14 10:07:27 -05:00
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
const args = messageHelper.parseCommandArgs(content, commandName);
|
|
|
|
|
|
|
|
|
|
const command = commands.get(commandName);
|
2026-02-14 11:44:36 -05:00
|
|
|
if (command) {
|
2026-02-14 11:37:04 -05:00
|
|
|
try {
|
|
|
|
|
await command.execute(message, client, args);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(`Error executing ${commandName}:`, err);
|
|
|
|
|
await message.reply('An error occurred while running that command.').catch(() => {
|
|
|
|
|
});
|
2026-02-14 10:07:27 -05:00
|
|
|
}
|
2026-02-13 18:20:29 -05:00
|
|
|
}
|
2026-02-14 11:37:04 -05:00
|
|
|
|
2026-02-13 18:20:29 -05:00
|
|
|
}
|
2026-02-14 10:07:27 -05:00
|
|
|
catch(error) {
|
2026-02-14 11:37:04 -05:00
|
|
|
return await message.reply(error);
|
2026-02-13 18:20:29 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
client.on(Events.Ready, () => {
|
|
|
|
|
console.log(`Logged in as ${client.user?.username}`);
|
|
|
|
|
console.log(`Serving ${client.guilds.size} guild(s)`);
|
|
|
|
|
const status = ['online', 'idle', 'dnd', 'invisible'].includes(BOT_STATUS) ? BOT_STATUS : 'online';
|
|
|
|
|
client.sendToGateway(0, {
|
|
|
|
|
op: GatewayOpcodes.PresenceUpdate,
|
|
|
|
|
d: { status },
|
|
|
|
|
});
|
2026-02-13 18:20:29 -05:00
|
|
|
});
|
|
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
try {
|
|
|
|
|
await client.login(token);
|
|
|
|
|
console.log('Gateway connected');
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Login failed:', err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|