mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
no comment still working on it
This commit is contained in:
1 parent
cea0014e18
commit
e11fca151c
87 files changed
+5710
-10182
No files matched your search
+44
-46
@@ -1,13 +1,14 @@
|
||||
/**
|
||||
* @file leave.mjs — Leave the current voice channel and stop playback
|
||||
* @module commands.leave
|
||||
* @module commands/leave
|
||||
* @description Make the bot leave a voice channel, with 24/7 cleanup and player destruction.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { logger } from "../src/constants/Logger.mjs";
|
||||
import { getGlobalColor, cleanId } from "../src/MessageHandler.mjs";
|
||||
import { get247ChannelMode } from "../src/constants/Helpers247.mjs";
|
||||
|
||||
/** @type {CommandBuilder} @description Command definition for the leave/stop command. */
|
||||
export const command = new CommandBuilder()
|
||||
.setName("leave")
|
||||
.setDescription("Make the bot leave a voice channel", "commands.leave")
|
||||
@@ -20,6 +21,13 @@ export const command = new CommandBuilder()
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Resolve the guild ID from a player, its map key, or the channel object.
|
||||
* @param {Player} player - The player instance.
|
||||
* @param {string} mapKey - The key under which the player is stored in playerMap.
|
||||
* @param {import('@fluxerjs/core').Client} client - The Discord/Fluxer client.
|
||||
* @returns {string} Cleaned guild ID, or empty string if unresolvable.
|
||||
*/
|
||||
function resolvePlayerGuildId(player, mapKey, client) {
|
||||
const direct = cleanId(player?._guildId);
|
||||
if (direct) return direct;
|
||||
@@ -30,9 +38,11 @@ function resolvePlayerGuildId(player, mapKey, client) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the leave command.
|
||||
* @param {import("../src/MessageHandler.mjs").Message} msg - The incoming message
|
||||
* @param {Map<string, {value: *}>} data - Slash-command options map
|
||||
* Run handler for the leave/stop command.
|
||||
* Finds the target player, removes 24/7 if enabled, destroys the player,
|
||||
* and sends a confirmation message.
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @param {object} data - Parsed command data containing option values.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(msg, data) {
|
||||
@@ -67,7 +77,7 @@ export async function run(msg, data) {
|
||||
}
|
||||
const channelList = guildPlayers.map(([mapKey, p]) => {
|
||||
const id = cleanId(p._channelId ?? mapKey);
|
||||
return id ? `<#${id}>` : "`unknown`";
|
||||
return id ? `<#${id}>` : "\`unknown\`";
|
||||
});
|
||||
return msg.reply(
|
||||
this.t(msg, "responses.leave.specifyChannel", {
|
||||
@@ -89,7 +99,7 @@ export async function run(msg, data) {
|
||||
}
|
||||
const channelList = guildPlayers.map(([mapKey, p]) => {
|
||||
const id = cleanId(p._channelId ?? mapKey);
|
||||
return id ? `<#${id}>` : "`unknown`";
|
||||
return id ? `<#${id}>` : "\`unknown\`";
|
||||
});
|
||||
return msg.reply(
|
||||
this.t(msg, "responses.leave.noPlayerInChannel", {
|
||||
@@ -104,6 +114,8 @@ export async function run(msg, data) {
|
||||
const activeChannelId = cleanId(player._channelId) || targetChannelId;
|
||||
const homeChannelId = cleanId(player._home247Channel) || activeChannelId;
|
||||
|
||||
// If this channel has 24/7 enabled, remove it from the saved list first.
|
||||
// This prevents the disconnect handler from scheduling an auto-rejoin loop.
|
||||
const set = this.getSettings(msg);
|
||||
const raw = set?.get("stay_247");
|
||||
const ch247 = (!raw || raw === "none")
|
||||
@@ -112,44 +124,30 @@ export async function run(msg, data) {
|
||||
? new Set(raw.map(id => cleanId(id)).filter(Boolean))
|
||||
: new Set([cleanId(raw)]);
|
||||
|
||||
const is247 = ch247.has(activeChannelId) || ch247.has(homeChannelId);
|
||||
const was247 = ch247.has(activeChannelId) || ch247.has(homeChannelId);
|
||||
|
||||
if (is247) {
|
||||
const matchChannel = ch247.has(homeChannelId) ? homeChannelId
|
||||
: ch247.has(activeChannelId) ? activeChannelId
|
||||
: null;
|
||||
const mode = matchChannel ? get247ChannelMode(set, matchChannel) : "off";
|
||||
const prefix = this.handler.getPrefix(msg.message?.guildId ?? msg.channel?.guild?.id);
|
||||
|
||||
this.markIntentionalLeave(activeChannelId);
|
||||
this.players.playerMap.delete(activeChannelId);
|
||||
this.players._unindexPlayer(player._guildId, activeChannelId);
|
||||
if (activeChannelId !== targetChannelId) this.players.playerMap.delete(targetChannelId);
|
||||
if (homeChannelId !== activeChannelId) this.players.playerMap.delete(homeChannelId);
|
||||
|
||||
const pendingScrobble = this.players._pendingScrobbleTimers?.get(activeChannelId);
|
||||
if (pendingScrobble) {
|
||||
clearTimeout(pendingScrobble.timer);
|
||||
this.players._pendingScrobbleTimers.delete(activeChannelId);
|
||||
}
|
||||
|
||||
await player.leave().catch(() => {});
|
||||
player.destroy();
|
||||
|
||||
if (mode === "auto") {
|
||||
msg.reply(this.t(msg, "responses.leave.leftRejoin247", { channel: targetChannelId, prefix }));
|
||||
const rejoinDelay = this.config?.timers?.leave247RejoinDelay ?? 5000;
|
||||
setTimeout(() => {
|
||||
if (this._spawnPlayer) {
|
||||
this._spawnPlayer(guildId, homeChannelId).catch(e =>
|
||||
logger.warn("[leave] 247 rejoin failed for", homeChannelId, e.message)
|
||||
);
|
||||
}
|
||||
}, rejoinDelay);
|
||||
} else {
|
||||
msg.reply(this.t(msg, "responses.leave.left247On", { prefix }));
|
||||
}
|
||||
} else {
|
||||
await this.leaveChannel(activeChannelId, guildId, msg);
|
||||
if (was247) {
|
||||
const target = ch247.has(activeChannelId) ? activeChannelId : homeChannelId;
|
||||
ch247.delete(target);
|
||||
set.set("stay_247", ch247.size > 0 ? [...ch247] : "none");
|
||||
}
|
||||
|
||||
// Mark as intentional leave so the disconnect handler doesn't also try to rejoin
|
||||
this.markIntentionalLeave(activeChannelId);
|
||||
this.players.playerMap.delete(activeChannelId);
|
||||
this.players._unindexPlayer(player._guildId, activeChannelId);
|
||||
if (activeChannelId !== targetChannelId) this.players.playerMap.delete(targetChannelId);
|
||||
if (homeChannelId !== activeChannelId) this.players.playerMap.delete(homeChannelId);
|
||||
|
||||
const pendingScrobble = this.players._pendingScrobbleTimers?.get(activeChannelId);
|
||||
if (pendingScrobble) {
|
||||
clearTimeout(pendingScrobble.timer);
|
||||
this.players._pendingScrobbleTimers.delete(activeChannelId);
|
||||
}
|
||||
|
||||
await player.leave().catch(() => {});
|
||||
player.destroy();
|
||||
|
||||
const label247 = was247 ? " 24/7 disabled." : "";
|
||||
msg.reply(this.t(msg, "responses.leave.left") + label247);
|
||||
}
|
||||
Reference in new issue
Block a user