mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
forgot to push it lmaoooooo is like 3 days
This commit is contained in:
1 parent
6341f4e68f
commit
47b1615cbc
9 files changed
+136
-67
No files matched your search
+11
-4
@@ -61,7 +61,7 @@ export class CommandRequirement {
|
||||
}
|
||||
setOwnerOnly(bool) { this.ownerOnly = bool; return this; }
|
||||
/**
|
||||
* @param {string} p Fluxer permission string (discord.js-style, e.g. "ManageChannels", "ManageGuild")
|
||||
* @param {string} p Fluxer permission string (ManageChannels", "ManageGuild")
|
||||
*/
|
||||
addPermission(p) { this.permissions.push(p); return this; }
|
||||
addPermissions(...p) { this.permissions.push(...p); return this; }
|
||||
@@ -70,7 +70,7 @@ export class CommandRequirement {
|
||||
}
|
||||
|
||||
export class Option {
|
||||
// Fluxer uses discord.js-like channel mentions: <#id> and user mentions <@id>
|
||||
// Fluxer uses channel mentions: <#id> and user mentions <@id>
|
||||
channelRegex = /^<#(?<id>\d+)>/;
|
||||
userRegex = /^<@!?(?<id>\d+)>/;
|
||||
idRegex = /^(?<id>\d+)/;
|
||||
@@ -602,7 +602,7 @@ export class CommandHandler extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks requirements using fluxerjs (discord.js-like) permission API.
|
||||
* Checks requirements using fluxerjs permission API.
|
||||
*/
|
||||
assertRequirements(cmd, msg) {
|
||||
const authorId = msg.message?.author?.id;
|
||||
@@ -625,7 +625,14 @@ export class CommandHandler extends EventEmitter {
|
||||
}
|
||||
} else {
|
||||
// not cached — fetch async and re-run
|
||||
guild.fetchMember(authorId).then(member => {
|
||||
// guild.fetchMember(id) is a Fluxer shorthand; guild.members.fetch(id) is the
|
||||
// standard compatible form. Try both so either API name works.
|
||||
const fetchPromise = typeof guild.fetchMember === "function"
|
||||
? guild.fetchMember(authorId)
|
||||
: typeof guild.members?.fetch === "function"
|
||||
? guild.members.fetch(authorId)
|
||||
: Promise.reject(new Error("No member fetch API available"));
|
||||
fetchPromise.then(member => {
|
||||
const missing = req.permissions.filter(p => !member.permissions.has(PermissionFlags[p] ?? p));
|
||||
if (missing.length > 0) {
|
||||
this.replyHandler(req.permissionError, msg);
|
||||
|
||||
+21
-10
@@ -2,11 +2,13 @@ import { Client, Events, EmbedBuilder } from "@fluxerjs/core";
|
||||
import { logger } from "./constants/Logger.mjs";
|
||||
import { Utils } from "./Utils.mjs";
|
||||
|
||||
/** Parse a color value from config — accepts hex string "0xe9196c" or number */
|
||||
/** Parse a color value from config — accepts hex string "0xe9196c", "#e9196c", or number */
|
||||
export function parseColor(value, fallback = 0xe9196c) {
|
||||
if (!value) return fallback;
|
||||
if (typeof value === "number") return value;
|
||||
const n = parseInt(value, 16);
|
||||
// Strip leading # ("#ff0000" → "ff0000") or 0x prefix ("0xe9196c" → "e9196c")
|
||||
const cleaned = String(value).replace(/^#/, "").replace(/^0x/i, "");
|
||||
const n = parseInt(cleaned, 16);
|
||||
return isNaN(n) ? fallback : n;
|
||||
}
|
||||
|
||||
@@ -74,9 +76,13 @@ export class MessageHandler {
|
||||
*/
|
||||
checkPermissions(permissions, channel) {
|
||||
if (!channel?.guild) return []; // DMs — no guild perms
|
||||
const me = channel.guild.members.me;
|
||||
if (!me) return []; // ← change: can't verify, assume OK instead of blocking
|
||||
const perms = channel.permissionsFor(me);
|
||||
// guild.members.me and channel.permissionsFor()
|
||||
// @fluxerjs/core may expose them or may not — guard with optional chaining so
|
||||
// a missing implementation fails open (assume OK) rather than throwing.
|
||||
const me = channel.guild.members?.me ?? null;
|
||||
if (!me) return []; // can't verify — assume OK
|
||||
const perms = channel.permissionsFor?.(me) ?? null;
|
||||
if (!perms) return []; // API unavailable — assume OK
|
||||
return permissions.filter(p => !perms.has(p));
|
||||
}
|
||||
|
||||
@@ -125,10 +131,10 @@ export class MessageHandler {
|
||||
* @returns {Message|null}
|
||||
*/
|
||||
get(id) {
|
||||
// fluxerjs messages are per-channel; search across cached channels
|
||||
// channel.messages is a MessageManager — @fluxerjs/core may not expose it.
|
||||
// Guard with optional chaining so the loop is a no-op if the property is absent.
|
||||
for (const channel of this.client.channels.cache.values()) {
|
||||
if (!channel.messages) continue;
|
||||
const msg = channel.messages.cache.get(id);
|
||||
const msg = channel.messages?.cache?.get?.(id) ?? null;
|
||||
if (msg) return new Message(msg, this);
|
||||
}
|
||||
return null;
|
||||
@@ -144,7 +150,12 @@ export class MessageHandler {
|
||||
const cached = this.get(id);
|
||||
if (cached) return cached;
|
||||
const channel = await this.client.channels.fetch(channelId);
|
||||
return new Message(await channel.messages.fetch(id), this);
|
||||
// channel.fetchMessage() is the @fluxerjs/core method.
|
||||
// Fall back to the channel.messages.fetch() if the former is absent.
|
||||
const raw = typeof channel.fetchMessage === "function"
|
||||
? await channel.fetchMessage(id)
|
||||
: await channel.messages?.fetch?.(id);
|
||||
return raw ? new Message(raw, this) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,7 +404,7 @@ export class MessageHandler {
|
||||
const { joinVoiceChannel } = await import("@fluxerjs/voice");
|
||||
const channel = await this.client.channels.fetch(channelId);
|
||||
if (!channel || !("guildId" in channel)) throw new Error("Cannot join a non-guild voice channel.");
|
||||
// @fluxerjs/voice API: joinVoiceChannel(client, channel) — NOT the old discord-voip object style
|
||||
// @fluxerjs/voice API: joinVoiceChannel(client, channel) — NOT the old object style
|
||||
return joinVoiceChannel(this.client, channel);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -99,13 +99,21 @@ export class MoonlinkManager extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send voice payload to Discord via Fluxer's WebSocket
|
||||
* Send voice payload to Fluxer's WebSocket
|
||||
* @param {string} guildId
|
||||
* @param {{ op: number, d: object }} payload
|
||||
* @private
|
||||
*/
|
||||
_sendPayload(guildId, payload) {
|
||||
try {
|
||||
// Prefer the public ws.send(shardId, payload) API — shards is a private field
|
||||
// in @fluxerjs/ws and accessing it directly risks breaking on internal refactors.
|
||||
if (typeof this._client?.ws?.send === "function") {
|
||||
this._client.ws.send(0, payload);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: access shard directly only if the public API is unavailable
|
||||
const shard = this._client?.ws?.shards?.get?.(0);
|
||||
if (!shard) {
|
||||
logger.warn("[MoonlinkManager] No WebSocket shard available");
|
||||
@@ -132,7 +140,6 @@ export class MoonlinkManager extends EventEmitter {
|
||||
_setupVoiceForwarding(client) {
|
||||
// @fluxerjs/core emits VoiceStateUpdate with a SINGLE argument:
|
||||
// (data: GatewayVoiceStateUpdateDispatchData) — raw gateway snake_case fields.
|
||||
// This is NOT discord.js style (oldState, newState).
|
||||
client.on(Events.VoiceStateUpdate, (data) => {
|
||||
try {
|
||||
// data is the raw GatewayVoiceStateUpdateDispatchData — always snake_case
|
||||
@@ -174,6 +181,10 @@ export class MoonlinkManager extends EventEmitter {
|
||||
// on gateway reconnects. Without this, each reconnect stacks another handler on the socket.
|
||||
const attachRawWs = () => {
|
||||
try {
|
||||
// NOTE: client.ws.shards is private in @fluxerjs/ws. There is no public API for
|
||||
// attaching a raw inbound message listener — ws.send() only covers outbound.
|
||||
// This access is intentional. If @fluxerjs/core exposes a public onRawMessage()
|
||||
// hook in a future release, replace shard0/wsObj extraction with that API.
|
||||
const shard0 = client.ws?.shards?.get?.(0);
|
||||
const wsObj = shard0?.ws ?? null;
|
||||
if (!wsObj) return;
|
||||
|
||||
+5
-1
@@ -137,8 +137,12 @@ export class RemoteSettingsManager extends EventEmitter {
|
||||
return this.remoteSave(server);
|
||||
}
|
||||
// Use mysql.escape() for every user-supplied value to prevent SQL injection.
|
||||
// Preserve native boolean/number types — mysql.escape(String(false)) stores "false"
|
||||
// (a truthy string) which breaks strict equality checks like songAnnouncements === false.
|
||||
const escapedPath = mysql.escape(`$.${key}`);
|
||||
const escapedVal = mysql.escape(String(val));
|
||||
const escapedVal = (typeof val === "boolean" || typeof val === "number")
|
||||
? mysql.escape(val)
|
||||
: mysql.escape(String(val));
|
||||
const escapedId = mysql.escape(server.id);
|
||||
const r = await this.query(`UPDATE settings SET data = JSON_SET(data, ${escapedPath}, ${escapedVal}) WHERE id=${escapedId}`);
|
||||
if (r.error) logger.error("[Settings] remoteUpdate error:", r.error);
|
||||
|
||||
Reference in new issue
Block a user