2026-02-17 17:25:18 -05:00
|
|
|
import { Client, Events } from '@fluxerjs/core';
|
|
|
|
|
import { messageHelper } from "./helpers/messageHelper.js";
|
|
|
|
|
import {enums} from "./enums.js";
|
|
|
|
|
import {commands} from "./commands.js";
|
|
|
|
|
import {webhookHelper} from "./helpers/webhookHelper.js";
|
|
|
|
|
import * as env from 'dotenv';
|
2026-02-16 11:07:43 -05:00
|
|
|
|
|
|
|
|
env.config();
|
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 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 14:30:12 -05:00
|
|
|
// If message doesn't start with the bot prefix, it could still be a message with a proxy tag. If it's not, return.
|
2026-02-14 11:37:04 -05:00
|
|
|
if (!content.startsWith(messageHelper.prefix)) {
|
2026-02-19 00:52:06 -05:00
|
|
|
await webhookHelper.sendMessageAsMember(client, message, content).catch((e) => {
|
2026-02-14 21:10:20 -05:00
|
|
|
throw e
|
|
|
|
|
});
|
2026-02-14 11:46:35 -05:00
|
|
|
return;
|
2026-02-14 11:37:04 -05:00
|
|
|
}
|
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)
|
2026-02-19 21:41:59 -05:00
|
|
|
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 21:10:20 -05:00
|
|
|
await command.execute(message, client, args).catch(e => {
|
|
|
|
|
throw e
|
|
|
|
|
});
|
2026-02-13 18:20:29 -05:00
|
|
|
}
|
2026-02-19 19:31:18 -05:00
|
|
|
else {
|
2026-02-19 19:32:37 -05:00
|
|
|
await message.reply(enums.err.COMMAND_NOT_RECOGNIZED);
|
2026-02-19 19:31:18 -05:00
|
|
|
}
|
2026-02-13 18:20:29 -05:00
|
|
|
}
|
2026-02-14 10:07:27 -05:00
|
|
|
catch(error) {
|
2026-02-16 11:07:43 -05:00
|
|
|
console.error(error);
|
2026-02-19 19:13:54 -05:00
|
|
|
// return await message.reply(error.message);
|
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}`);
|
2026-02-13 18:20:29 -05:00
|
|
|
});
|
|
|
|
|
|
2026-02-19 00:52:06 -05:00
|
|
|
let guildCount = 0;
|
|
|
|
|
client.on(Events.GuildCreate, () => {
|
|
|
|
|
guildCount++;
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function printGuilds() {
|
|
|
|
|
console.log(`Serving ${client.guilds.size} guild(s)`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const callback = Debounce(printGuilds, 2000);
|
|
|
|
|
|
|
|
|
|
function Debounce(func, delay) {
|
|
|
|
|
let timeout = null;
|
|
|
|
|
return function (...args) {
|
|
|
|
|
clearTimeout(timeout);
|
|
|
|
|
timeout = setTimeout(() => func(...args), delay);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 11:37:04 -05:00
|
|
|
try {
|
|
|
|
|
await client.login(token);
|
2026-02-15 01:14:21 -05:00
|
|
|
// await db.check_connection();
|
2026-02-14 11:37:04 -05:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Login failed:', err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|