discord js (#1)

* clear out fluxer.net

* basic discord.js bot with ping, and echo

* added creation of webhook

* simplifying webhook logic

* sending messages as webhook

* deleting orignal message

* adding sequelize file

* commented out pgadmin part while it's not working

* adding member sort of working

* changing names of values

* updating names of values and adding new method in memberHelper

* renamed messagehelper function

* deleted proxyhelper

* passed only channel id into webhook helper methods

* added new functions and got update working

* changed message match to better reducer

* adjusted webhook helper to use actual data

* refactored bot.js and removed unused methods
This commit is contained in:
pieartsy
2026-02-13 18:20:29 -05:00
committed by GitHub
parent 3bac14f15e
commit fbee6d71f0
15 changed files with 431 additions and 642 deletions

66
bot.js Normal file
View File

@@ -0,0 +1,66 @@
import { Client, GatewayDispatchEvents } from "@discordjs/core";
import { REST } from "@discordjs/rest";
import { WebSocketManager } from "@discordjs/ws";
import { db } from './sequelize.js';
import { webhookHelper } from "./helpers/webhookHelper.js";
import { messageHelper } from "./helpers/messageHelper.js";
import { memberHelper } from "./helpers/memberHelper.js";
const token = process.env.FLUXER_BOT_TOKEN;
if (!token) {
console.error("Missing FLUXER_BOT_TOKEN environment variable.");
process.exit(1);
}
const rest = new REST({
api: "https://api.fluxer.app",
version: "1",
}).setToken(token);
const gateway = new WebSocketManager({
token,
intents: 0, // Fluxer has no intents yet
rest,
version: "1",
});
export const client = new Client({ rest, gateway });
let plural_flux_name = "";
let plural_flux_discriminator = "";
client.on(GatewayDispatchEvents.MessageCreate, async ({ api, data }) => {
if (data.webhook_id) {
return;
}
else if (data.author.username === plural_flux_name && data.author.discriminator === plural_flux_discriminator) {
return;
}
else if (!data.content.startsWith(messageHelper.prefix)) {
const proxyMatch = await messageHelper.parse_proxy_tags(data.author.id, data.content);
if (!proxyMatch.proxy) {
return;
}
const member = await memberHelper.get_member_by_proxy(data.author.id, proxyMatch.proxy);
await webhookHelper.replace_message(api, data, proxyMatch.message, member);
}
else {
const command_name = data.content.slice(messageHelper.prefix.length).split(" ")[0];
const args = messageHelper.parse_command_args(data.content, command_name);
if (command_name === "member" || command_name === "m") {
const reply = await memberHelper.parse_member_command(data.author.id, args);
await api.channels.createMessage(data.channel_id, {content: reply});
}
}
});
client.on(GatewayDispatchEvents.Ready, async ({data}) => {
console.log(`Logged in as ${data.user.username}#${data.user.discriminator}`);
plural_flux_name = data.user.username;
plural_flux_discriminator = data.user.discriminator;
await db.check_connection();
});
gateway.connect();