mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
test
This commit is contained in:
commit
a467611e37
5 files changed
+23
-90
No files matched your search
@@ -70,10 +70,7 @@ export class CommandHandler extends EventEmitter {
|
||||
this.helpHandler = new HelpHandler(this);
|
||||
this.helpCommand = "help";
|
||||
this.replyHandler = (message, msg) => {
|
||||
const guildId = msg?.channel?.guildId ?? msg?.channel?.channel?.guildId ?? msg?.guildId ?? msg?.message?.guildId ?? null;
|
||||
Promise.resolve(msg.reply(this.format(message, guildId))).catch(err => {
|
||||
logger.warn("[CommandHandler] Failed to reply:", err?.message);
|
||||
});
|
||||
msg.reply(this.format(message, msg.channel.channel.guildId));
|
||||
};
|
||||
this.messages.onMessage(this.messageHandler.bind(this));
|
||||
}
|
||||
@@ -272,10 +269,7 @@ export class CommandHandler extends EventEmitter {
|
||||
if (cmd.requirements.length > 0 && !external) {
|
||||
if (!this.assertRequirements(cmd, msg)) return;
|
||||
}
|
||||
if (previous === false) {
|
||||
const prevGuildId = msg.channel?.guildId ?? msg.channel?.channel?.guildId ?? msg.message?.guildId ?? null;
|
||||
previous = this.format("$prefix" + cmd.name, prevGuildId);
|
||||
}
|
||||
if (previous === false) previous = this.format("$prefix" + cmd.name, msg.channel?.channel?.guildId);
|
||||
if (!external) this.emit("command", { command: cmd, message: msg });
|
||||
|
||||
if (cmd.subcommands.length !== 0) {
|
||||
|
||||
@@ -44,31 +44,23 @@ export class CommandLoader {
|
||||
this.commands.on("run", (data) => {
|
||||
if (!this.runnables.has(data.command.uid)) return;
|
||||
const runFc = this.runnables.get(data.command.uid);
|
||||
const isPermError = (err) => {
|
||||
return err?.code === "MISSING_PERMISSIONS" ||
|
||||
err?.code === "COMMUNICATION_DISABLED" ||
|
||||
err?.statusCode === 403;
|
||||
};
|
||||
const sendErrorReply = (id) => {
|
||||
Promise.resolve(data.message.reply("An error occurred. Error id: `#" + id + "`"))
|
||||
.catch(err => logger.warn("[CommandHandler] Failed to send error-reply; error id #" + id + ":", err?.message));
|
||||
};
|
||||
const handleCmdError = (e) => {
|
||||
if (isPermError(e)) {
|
||||
logger.warn(`[CommandHandler] Missing permissions in channel ${data.message?.channelId ?? data.message?.channel?.id}: ${e.code ?? e.message}`);
|
||||
return;
|
||||
}
|
||||
const id = Utils.uid();
|
||||
logger.error("Error running command; error id #" + id, e);
|
||||
sendErrorReply(id);
|
||||
};
|
||||
try {
|
||||
const result = runFc.call(this.context, data.message, data);
|
||||
if (result && typeof result.catch === "function") {
|
||||
result.catch(handleCmdError);
|
||||
result.catch(e => {
|
||||
const id = Utils.uid();
|
||||
logger.error("Error running command; error id #" + id, e);
|
||||
sendErrorReply(id);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
handleCmdError(e);
|
||||
const id = Utils.uid();
|
||||
logger.error("Error running command; error id #" + id, e);
|
||||
sendErrorReply(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+3
-3
@@ -233,10 +233,10 @@ class Remix {
|
||||
),
|
||||
false,
|
||||
{
|
||||
icon_url: (msg.channel?.channel?.guild?.icon || msg.server?.icon)
|
||||
? `https://cdn.fluxer.app/icons/${msg.channel?.channel?.guild?.id ?? msg.server?.id}/${msg.channel?.channel?.guild?.icon ?? msg.server?.icon}.webp`
|
||||
icon_url: msg.channel.channel.guild?.icon
|
||||
? `https://cdn.fluxer.app/icons/${msg.channel.channel.guild.id}/${msg.channel.channel.guild.icon}.webp`
|
||||
: null,
|
||||
title: msg.channel?.channel?.guild?.name ?? msg.server?.name ?? null,
|
||||
title: msg.channel.channel.guild?.name ?? null,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
@@ -557,7 +557,7 @@ const PlayerLifecycleMixin = {
|
||||
});
|
||||
});
|
||||
|
||||
const statusMsg = await message.reply(this._t(message, "responses.join.joining")).catch(() => null);
|
||||
const statusMsg = await message.reply(this._t(message, "responses.join.joining"));
|
||||
try {
|
||||
await player.join(cid);
|
||||
|
||||
@@ -565,7 +565,7 @@ const PlayerLifecycleMixin = {
|
||||
this._indexPlayer(channel.guildId ?? getMessageGuildId(message), cleanChannelId);
|
||||
this._pendingJoins.delete(cleanChannelId);
|
||||
|
||||
await statusMsg?.edit?.(this._t(message, "responses.join.joined", { channel: cid })).catch(() => {});
|
||||
await statusMsg.edit(this._t(message, "responses.join.joined", { channel: cid }));
|
||||
|
||||
const guildId = cleanId(channel.guildId ?? getMessageGuildId(message));
|
||||
this._restorePlayerVolume(player, guildId);
|
||||
@@ -584,7 +584,7 @@ const PlayerLifecycleMixin = {
|
||||
|
||||
this.playerMap.set(cleanChannelId, player);
|
||||
this._indexPlayer(channel.guildId ?? getMessageGuildId(message), cleanChannelId);
|
||||
await statusMsg?.edit?.(this._t(message, "responses.join.joined", { channel: cid })).catch(() => {});
|
||||
await statusMsg.edit(this._t(message, "responses.join.joined", { channel: cid }));
|
||||
|
||||
const retryGuildId = cleanId(channel.guildId ?? getMessageGuildId(message));
|
||||
this._restorePlayerVolume(player, retryGuildId);
|
||||
@@ -602,7 +602,7 @@ const PlayerLifecycleMixin = {
|
||||
} else {
|
||||
errorMsg = this._t(message, "responses.join.joinFailed", { error: err.message });
|
||||
}
|
||||
await statusMsg?.edit?.(errorMsg).catch(() => {});
|
||||
await statusMsg.edit(errorMsg).catch(() => {});
|
||||
this.playerMap.delete(cleanChannelId);
|
||||
this._unindexPlayer(channel.guildId ?? getMessageGuildId(message), cleanChannelId);
|
||||
player.destroy();
|
||||
|
||||
@@ -395,15 +395,7 @@ export class MessageHandler {
|
||||
} else {
|
||||
opts = { ...message };
|
||||
}
|
||||
try {
|
||||
return new Message(await replyingTo.reply(opts, { ping: false }), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot reply in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return new Message(await replyingTo.reply(opts, { ping: false }), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,15 +409,7 @@ export class MessageHandler {
|
||||
if (!(await this.assertPermissions(["SendMessages", "EmbedLinks"], replyingTo))) return null;
|
||||
|
||||
if (typeof message === "object" && Array.isArray(message.embeds)) {
|
||||
try {
|
||||
return new Message(await replyingTo.reply(message, { ping: false }), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return new Message(await replyingTo.reply(message, { ping: false }), this);
|
||||
}
|
||||
|
||||
options = {
|
||||
@@ -439,15 +423,7 @@ export class MessageHandler {
|
||||
const { embedText, ...rest } = message;
|
||||
payload = { ...payload, ...rest };
|
||||
}
|
||||
try {
|
||||
return new Message(await replyingTo.reply(payload, { ping: false }), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot replyEmbed in channel ${replyingTo.channelId ?? replyingTo.channel?.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return new Message(await replyingTo.reply(payload, { ping: false }), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,15 +443,7 @@ export class MessageHandler {
|
||||
} else {
|
||||
opts = message;
|
||||
}
|
||||
try {
|
||||
return new Message(await channel.send(opts), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot sendMessage in channel ${channel.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return new Message(await channel.send(opts), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -490,15 +458,7 @@ export class MessageHandler {
|
||||
return this.sendMessage(channel, typeof content === "string" ? content : content?.embedText ?? "");
|
||||
}
|
||||
if (typeof content === "object" && Array.isArray(content.embeds)) {
|
||||
try {
|
||||
return new Message(await channel.send(content), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot sendEmbed in channel ${channel.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return new Message(await channel.send(content), this);
|
||||
}
|
||||
const text = (typeof content === "object") ? content.embedText : content;
|
||||
const payload = this.#createEmbed(text, embedOptions);
|
||||
@@ -506,15 +466,7 @@ export class MessageHandler {
|
||||
const { embedText, ...rest } = content;
|
||||
Object.assign(payload, rest);
|
||||
}
|
||||
try {
|
||||
return new Message(await channel.send(payload), this);
|
||||
} catch (err) {
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] Cannot sendEmbed in channel ${channel.id}: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
return new Message(await channel.send(payload), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -551,11 +503,6 @@ export class MessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (err.code === "MISSING_PERMISSIONS" || err.code === "COMMUNICATION_DISABLED" || err.statusCode === 403) {
|
||||
logger.warn(`[MessageHandler] editEmbed: missing permissions or communication disabled: ${err.code ?? err.message}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (RETRYABLE.has(err.statusCode) && attempt < MAX_ATTEMPTS) {
|
||||
logger.warn(`[MessageHandler] editEmbed: ${err.statusCode} on attempt ${attempt}/${MAX_ATTEMPTS}, retrying in ${RETRY_DELAY_MS}ms…`);
|
||||
await new Promise(r => setTimeout(r, RETRY_DELAY_MS));
|
||||
|
||||
Reference in new issue
Block a user