mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
cleaning
This commit is contained in:
1 parent
963e63751c
commit
29c129971a
4 files changed
+205
-74
No files matched your search
@@ -18,13 +18,18 @@ function embed(desc) {
|
|||||||
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc).toJSON()] };
|
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc).toJSON()] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanId(value) {
|
||||||
|
return String(value ?? "").replace(/\D/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
export async function run(msg, data) {
|
export async function run(msg, data) {
|
||||||
const cid = data.get("channelId").value;
|
const cid = cleanId(data.get("channelId").value);
|
||||||
const targetChannel = this.client.channels.cache.get(cid);
|
const targetChannel = this.client.channels.cache.get(cid);
|
||||||
if (!targetChannel) return msg.replyEmbed(embed("❌ Channel not found."));
|
if (!targetChannel) return msg.replyEmbed(embed("❌ Channel not found."));
|
||||||
if (msg.message.guildId !== targetChannel.guildId)
|
if (cleanId(msg.message.guildId) !== cleanId(targetChannel.guildId))
|
||||||
return msg.replyEmbed(embed("❌ This command has to be run in the same server as the voice channel."));
|
return msg.replyEmbed(embed("❌ This command has to be run in the same server as the voice channel."));
|
||||||
const p = this.players.playerMap.get(cid);
|
const p = this.players.playerMap.get(cid)
|
||||||
|
?? [...this.players.playerMap.values()].find((player) => cleanId(player?._channelId) === cid);
|
||||||
if (!p) return msg.replyEmbed(embed("❌ Player not found."));
|
if (!p) return msg.replyEmbed(embed("❌ Player not found."));
|
||||||
if (!p.connection) return msg.replyEmbed(embed("❌ Player not initialized."));
|
if (!p.connection) return msg.replyEmbed(embed("❌ Player not initialized."));
|
||||||
await this.players.leave(msg, cid);
|
await this.players.leave(msg, cid);
|
||||||
|
|||||||
+29
-16
@@ -3,6 +3,20 @@ import { EmbedBuilder } from "@fluxerjs/core";
|
|||||||
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
||||||
import Player from "../src/Player.mjs";
|
import Player from "../src/Player.mjs";
|
||||||
|
|
||||||
|
function getGuildId(message) {
|
||||||
|
return message?.channel?.guildId
|
||||||
|
?? message?.channel?.guild?.id
|
||||||
|
?? message?.message?.guildId
|
||||||
|
?? message?.message?.guild?.id
|
||||||
|
?? message?.channel?.server_id
|
||||||
|
?? message?.channel?.serverId
|
||||||
|
?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanId(value) {
|
||||||
|
return String(value ?? "").replace(/\D/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
||||||
if (!this.client.channels.cache.has(cid)) {
|
if (!this.client.channels.cache.has(cid)) {
|
||||||
ecb();
|
ecb();
|
||||||
@@ -11,8 +25,11 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
|||||||
.toJSON();
|
.toJSON();
|
||||||
return message.replyEmbed({ embeds: [embed] });
|
return message.replyEmbed({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
if (this.players.playerMap.has(cid)) {
|
const cleanChannelId = cleanId(cid);
|
||||||
cb(this.players.playerMap.get(cid));
|
const existing = this.players.playerMap.get(cleanChannelId)
|
||||||
|
?? [...this.players.playerMap.values()].find((player) => cleanId(player?._channelId) === cleanChannelId);
|
||||||
|
if (existing) {
|
||||||
|
cb(existing);
|
||||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||||
.setDescription("Already joined <#" + cid + ">.")
|
.setDescription("Already joined <#" + cid + ">.")
|
||||||
.toJSON();
|
.toJSON();
|
||||||
@@ -41,11 +58,7 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
|||||||
p.on("autoleave", () => {
|
p.on("autoleave", () => {
|
||||||
const activeChannelId = String(p._channelId ?? cid).replace(/\D/g, "") || cid;
|
const activeChannelId = String(p._channelId ?? cid).replace(/\D/g, "") || cid;
|
||||||
const homeChannelId = String(p._home247Channel ?? activeChannelId).replace(/\D/g, "") || activeChannelId;
|
const homeChannelId = String(p._home247Channel ?? activeChannelId).replace(/\D/g, "") || activeChannelId;
|
||||||
const guildId = message.channel?.guildId
|
const guildId = getGuildId(message);
|
||||||
?? message.channel?.guild?.id
|
|
||||||
?? message.message?.guildId
|
|
||||||
?? message.channel?.server_id
|
|
||||||
?? message.channel?.serverId;
|
|
||||||
const is247 = (() => {
|
const is247 = (() => {
|
||||||
try {
|
try {
|
||||||
const raw = this.settingsMgr?.getServer?.(guildId)?.get?.("stay_247");
|
const raw = this.settingsMgr?.getServer?.(guildId)?.get?.("stay_247");
|
||||||
@@ -54,7 +67,7 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
|||||||
})();
|
})();
|
||||||
const prefix = (() => {
|
const prefix = (() => {
|
||||||
try {
|
try {
|
||||||
return this._commands?.getPrefix?.(message.channel?.guild?.id) ?? "%";
|
return this._commands?.getPrefix?.(guildId) ?? "%";
|
||||||
} catch (_) { return "%"; }
|
} catch (_) { return "%"; }
|
||||||
})();
|
})();
|
||||||
const desc = is247
|
const desc = is247
|
||||||
@@ -71,7 +84,7 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
p.on("message", m => {
|
p.on("message", m => {
|
||||||
const guildId = message.channel?.guild?.id ?? message.channel?.server_id ?? message.channel?.serverId;
|
const guildId = getGuildId(message);
|
||||||
const raw = this.settingsMgr?.getServer?.(guildId)?.get("songAnnouncements");
|
const raw = this.settingsMgr?.getServer?.(guildId)?.get("songAnnouncements");
|
||||||
const disabled = raw === false || raw === 0 ||
|
const disabled = raw === false || raw === 0 ||
|
||||||
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
||||||
@@ -80,17 +93,17 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
|||||||
message.channel.sendEmbed({ embeds: [embed] });
|
message.channel.sendEmbed({ embeds: [embed] });
|
||||||
});
|
});
|
||||||
|
|
||||||
this.players.playerMap.set(cid, p);
|
this.players.playerMap.set(cleanChannelId, p);
|
||||||
|
|
||||||
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription("⏳ Joining Channel...").toJSON();
|
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription("⏳ Joining Channel...").toJSON();
|
||||||
const statusMsg = await message.replyEmbed({ embeds: [joiningEmbed] });
|
const statusMsg = await message.replyEmbed({ embeds: [joiningEmbed] });
|
||||||
try {
|
try {
|
||||||
await p.join(cid);
|
await p.join(cleanChannelId);
|
||||||
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`✅ Successfully joined <#${cid}>`).toJSON();
|
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`✅ Successfully joined <#${cid}>`).toJSON();
|
||||||
await statusMsg.editEmbed({ embeds: [okEmbed] });
|
await statusMsg.editEmbed({ embeds: [okEmbed] });
|
||||||
cb(p);
|
cb(p);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.players.playerMap.delete(cid);
|
this.players.playerMap.delete(cleanChannelId);
|
||||||
p.destroy();
|
p.destroy();
|
||||||
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`❌ Failed to join: ${e.message}`).toJSON();
|
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`❌ Failed to join: ${e.message}`).toJSON();
|
||||||
await statusMsg.editEmbed({ embeds: [errEmbed] });
|
await statusMsg.editEmbed({ embeds: [errEmbed] });
|
||||||
@@ -125,7 +138,7 @@ export function run(message, data) {
|
|||||||
resolvedId = idMatch[1];
|
resolvedId = idMatch[1];
|
||||||
} else {
|
} else {
|
||||||
// Try to look up by name
|
// Try to look up by name
|
||||||
const serverId = message.channel?.server_id ?? message.channel?.serverId;
|
const guildId = cleanId(getGuildId(message));
|
||||||
const allChannels = [
|
const allChannels = [
|
||||||
...(this._commands?.client?.channels?.values?.() ??
|
...(this._commands?.client?.channels?.values?.() ??
|
||||||
this._commands?.client?.channels?.cache?.values?.() ??
|
this._commands?.client?.channels?.cache?.values?.() ??
|
||||||
@@ -133,9 +146,9 @@ export function run(message, data) {
|
|||||||
this.client?.channels?.cache?.values?.() ?? [])
|
this.client?.channels?.cache?.values?.() ?? [])
|
||||||
];
|
];
|
||||||
const match = allChannels.find(c => {
|
const match = allChannels.find(c => {
|
||||||
const cServerId = c.server_id ?? c.serverId ?? c.guildId;
|
const cServerId = cleanId(c.guildId ?? c.guild?.id ?? c.server_id ?? c.serverId);
|
||||||
const isVoice = c.channel_type === "VoiceChannel" || c.type === "VoiceChannel" || c.type === 2;
|
const isVoice = c.channel_type === "VoiceChannel" || c.type === "VoiceChannel" || c.type === 2;
|
||||||
return isVoice && cServerId === serverId &&
|
return isVoice && cServerId === guildId &&
|
||||||
(c.name?.toLowerCase() === rawArg.toLowerCase());
|
(c.name?.toLowerCase() === rawArg.toLowerCase());
|
||||||
});
|
});
|
||||||
if (match) resolvedId = match._id ?? match.id;
|
if (match) resolvedId = match._id ?? match.id;
|
||||||
@@ -155,7 +168,7 @@ export function run(message, data) {
|
|||||||
const cid = this.players.checkVoiceChannels(message);
|
const cid = this.players.checkVoiceChannels(message);
|
||||||
|
|
||||||
if (!cid) {
|
if (!cid) {
|
||||||
const prefix = this._commands?.getPrefix?.(message.channel?.guild?.id ?? message.channel?.server_id ?? message.channel?.serverId) ?? "%";
|
const prefix = this._commands?.getPrefix?.(getGuildId(message)) ?? "%";
|
||||||
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
const embed = new EmbedBuilder().setColor(getGlobalColor())
|
||||||
.setDescription(`❌ You're not in a voice channel. Please join one first, or specify a channel: \`${prefix}join <#channel>\``)
|
.setDescription(`❌ You're not in a voice channel. Please join one first, or specify a channel: \`${prefix}join <#channel>\``)
|
||||||
.toJSON();
|
.toJSON();
|
||||||
|
|||||||
@@ -56,7 +56,13 @@ function displayValue(key, value) {
|
|||||||
|
|
||||||
/** Resolve guild ID from a message context */
|
/** Resolve guild ID from a message context */
|
||||||
function getGuildId(message) {
|
function getGuildId(message) {
|
||||||
return message.message?.guild?.id ?? message.channel?.guild?.id ?? null;
|
return message.message?.guildId
|
||||||
|
?? message.message?.guild?.id
|
||||||
|
?? message.channel?.guildId
|
||||||
|
?? message.channel?.guild?.id
|
||||||
|
?? message.channel?.server_id
|
||||||
|
?? message.channel?.serverId
|
||||||
|
?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolve guild name from a message context */
|
/** Resolve guild name from a message context */
|
||||||
|
|||||||
+161
-54
@@ -12,6 +12,7 @@ import { SettingsManager } from "./Settings.mjs";
|
|||||||
import { Utils } from "./Utils.mjs";
|
import { Utils } from "./Utils.mjs";
|
||||||
import { logger } from "./constants/Logger.mjs";
|
import { logger } from "./constants/Logger.mjs";
|
||||||
import { EmbedBuilder } from "@fluxerjs/core";
|
import { EmbedBuilder } from "@fluxerjs/core";
|
||||||
|
import { getVoiceManager } from "@fluxerjs/voice";
|
||||||
import { getGlobalColor } from "./MessageHandler.mjs";
|
import { getGlobalColor } from "./MessageHandler.mjs";
|
||||||
|
|
||||||
/** Helper — build a plain embed payload from a description string */
|
/** Helper — build a plain embed payload from a description string */
|
||||||
@@ -19,6 +20,36 @@ function mkEmbed(desc) {
|
|||||||
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc).toJSON()] };
|
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc).toJSON()] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanId(value) {
|
||||||
|
return String(value ?? "").replace(/\D/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMessageGuildId(message) {
|
||||||
|
return message?.channel?.guildId ??
|
||||||
|
message?.channel?.guild?.id ??
|
||||||
|
message?.message?.guildId ??
|
||||||
|
message?.message?.guild?.id ??
|
||||||
|
message?.channel?.server_id ??
|
||||||
|
message?.channel?.serverId ??
|
||||||
|
message?.message?.server_id ??
|
||||||
|
message?.message?.serverId ??
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlayerGuildId(player, fallbackChannel = null) {
|
||||||
|
return cleanId(
|
||||||
|
player?._guildId ??
|
||||||
|
fallbackChannel?.guildId ??
|
||||||
|
fallbackChannel?.guild?.id ??
|
||||||
|
fallbackChannel?.server_id ??
|
||||||
|
fallbackChannel?.serverId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlayerChannelId(player, fallbackChannelId = null) {
|
||||||
|
return cleanId(player?._channelId ?? player?._home247Channel ?? fallbackChannelId);
|
||||||
|
}
|
||||||
|
|
||||||
export class PlayerManager {
|
export class PlayerManager {
|
||||||
/** @type {SettingsManager} */
|
/** @type {SettingsManager} */
|
||||||
settings;
|
settings;
|
||||||
@@ -61,30 +92,85 @@ export class PlayerManager {
|
|||||||
checkVoiceChannels(message) {
|
checkVoiceChannels(message) {
|
||||||
if (!message) return null;
|
if (!message) return null;
|
||||||
|
|
||||||
const userId = message.author?.id;
|
const userId = message.author?.id ?? message.message?.author?.id;
|
||||||
const serverId =
|
const guildId = getMessageGuildId(message);
|
||||||
message.channel?.server_id ??
|
|
||||||
message.channel?.serverId ??
|
|
||||||
message.channel?.guild?.id ??
|
|
||||||
message.channel?.guildId ??
|
|
||||||
message.message?.server_id ??
|
|
||||||
message.message?.serverId ??
|
|
||||||
message.message?.guildId;
|
|
||||||
|
|
||||||
if (!userId) return null;
|
if (!userId) return null;
|
||||||
|
if (!guildId) return null;
|
||||||
|
|
||||||
const cleanServer = serverId ? String(serverId).replace(/\D/g, "") : null;
|
const cleanGuild = cleanId(guildId);
|
||||||
|
const seedObserved = (channelId) => {
|
||||||
|
const cleanChannelId = cleanId(channelId);
|
||||||
|
if (!cleanChannelId) return null;
|
||||||
|
if (!this.observedVoiceUsers?.has(userId)) {
|
||||||
|
this.observedVoiceUsers?.set(userId, { channelId: cleanChannelId, guildId: cleanGuild });
|
||||||
|
}
|
||||||
|
return cleanId(this.observedVoiceUsers?.get(userId)?.channelId) || cleanChannelId;
|
||||||
|
};
|
||||||
|
|
||||||
// Fallback: find any existing player in this server
|
const observed = this.observedVoiceUsers?.get?.(userId);
|
||||||
if (cleanServer) {
|
if (cleanId(observed?.guildId) === cleanGuild) {
|
||||||
for (const [channelId] of this.playerMap) {
|
const observedChannelId = cleanId(observed?.channelId);
|
||||||
const channel = this.commands.client?.channels?.get(channelId) ??
|
if (observedChannelId) return observedChannelId;
|
||||||
this.commands.client?.channels?.cache?.get(channelId);
|
}
|
||||||
const chGuild = String(channel?.guildId ?? channel?.server_id ?? channel?.serverId ?? "").replace(/\D/g, "");
|
|
||||||
if (chGuild === cleanServer) {
|
try {
|
||||||
return channelId;
|
const vm = getVoiceManager(this.commands.client);
|
||||||
|
const voiceChannelId = vm?.getVoiceChannelId?.(guildId, userId);
|
||||||
|
const seeded = seedObserved(voiceChannelId);
|
||||||
|
if (seeded) return seeded;
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
const memberVoiceChannelId =
|
||||||
|
message?.member?.voice?.channelId ??
|
||||||
|
message?.message?.member?.voice?.channelId ??
|
||||||
|
null;
|
||||||
|
{
|
||||||
|
const seeded = seedObserved(memberVoiceChannelId);
|
||||||
|
if (seeded) return seeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const guild =
|
||||||
|
this.commands.client?.guilds?.cache?.get?.(guildId) ??
|
||||||
|
this.commands.client?.guilds?.cache?.get?.(cleanGuild);
|
||||||
|
const voiceStates = guild?.voice_states ?? guild?.voiceStates?.cache ?? guild?.voiceStates ?? null;
|
||||||
|
if (voiceStates) {
|
||||||
|
if (!Array.isArray(voiceStates) && typeof voiceStates === "object") {
|
||||||
|
const direct = voiceStates[userId];
|
||||||
|
const directChannelId =
|
||||||
|
typeof direct === "string"
|
||||||
|
? direct
|
||||||
|
: direct?.channelId ?? direct?.channel_id ?? null;
|
||||||
|
const seeded = seedObserved(directChannelId);
|
||||||
|
if (seeded) return seeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries = Array.isArray(voiceStates)
|
||||||
|
? voiceStates
|
||||||
|
: typeof voiceStates.values === "function"
|
||||||
|
? voiceStates.values()
|
||||||
|
: Object.values(voiceStates);
|
||||||
|
|
||||||
|
for (const state of entries) {
|
||||||
|
const stateUserId = state?.userId ?? state?.user_id ?? state?.id;
|
||||||
|
const stateGuildId = cleanId(state?.guildId ?? state?.guild_id ?? guildId);
|
||||||
|
if (stateUserId !== userId || stateGuildId !== cleanGuild) continue;
|
||||||
|
const seeded = seedObserved(state?.channelId ?? state?.channel_id);
|
||||||
|
if (seeded) return seeded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
const liveGuildPlayers = [...this.playerMap.entries()].filter(([channelId, player]) => {
|
||||||
|
const fallbackChannel =
|
||||||
|
this.commands.client?.channels?.get?.(channelId) ??
|
||||||
|
this.commands.client?.channels?.cache?.get?.(channelId) ??
|
||||||
|
null;
|
||||||
|
return getPlayerGuildId(player, fallbackChannel) === cleanGuild;
|
||||||
|
});
|
||||||
|
if (liveGuildPlayers.length === 1) {
|
||||||
|
return getPlayerChannelId(liveGuildPlayers[0][1], liveGuildPlayers[0][0]) || cleanId(liveGuildPlayers[0][0]);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -102,24 +188,16 @@ export class PlayerManager {
|
|||||||
* @returns {Promise<Player|null>}
|
* @returns {Promise<Player|null>}
|
||||||
*/
|
*/
|
||||||
async getPlayer(message, promptJoin = true, verifyUser = true, shouldJoin = false) {
|
async getPlayer(message, promptJoin = true, verifyUser = true, shouldJoin = false) {
|
||||||
const serverId =
|
const guildId = getMessageGuildId(message);
|
||||||
message.channel?.server_id ??
|
const cleanGuildId = cleanId(guildId);
|
||||||
message.channel?.serverId ??
|
|
||||||
message.channel?.guild?.id ??
|
|
||||||
message.channel?.guildId ??
|
|
||||||
message.message?.server_id ??
|
|
||||||
message.message?.serverId ??
|
|
||||||
message.message?.guildId;
|
|
||||||
|
|
||||||
const cleanServerId = serverId ? String(serverId).replace(/\D/g, "") : null;
|
|
||||||
|
|
||||||
const userChannelId = this.checkVoiceChannels(message);
|
const userChannelId = this.checkVoiceChannels(message);
|
||||||
const cleanUserChannelId = userChannelId ? String(userChannelId).replace(/\D/g, "") : null;
|
const cleanUserChannelId = cleanId(userChannelId);
|
||||||
|
|
||||||
if (cleanUserChannelId) {
|
if (cleanUserChannelId) {
|
||||||
const player = this.playerMap.get(cleanUserChannelId)
|
const player = this.playerMap.get(cleanUserChannelId)
|
||||||
?? [...this.playerMap.values()].find(p =>
|
?? [...this.playerMap.values()].find(p =>
|
||||||
String(p?._channelId ?? "").replace(/\D/g, "") === cleanUserChannelId
|
getPlayerChannelId(p) === cleanUserChannelId
|
||||||
);
|
);
|
||||||
if (player) {
|
if (player) {
|
||||||
player.textChannel = message.channel;
|
player.textChannel = message.channel;
|
||||||
@@ -127,10 +205,9 @@ export class PlayerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverPlayers = cleanServerId
|
const serverPlayers = cleanGuildId
|
||||||
? [...this.playerMap.entries()].filter(([, player]) => {
|
? [...this.playerMap.entries()].filter(([, player]) => {
|
||||||
const playerGuildId = String(player?._guildId ?? "").replace(/\D/g, "");
|
return getPlayerGuildId(player) === cleanGuildId;
|
||||||
return playerGuildId === cleanServerId;
|
|
||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
@@ -166,7 +243,7 @@ export class PlayerManager {
|
|||||||
|
|
||||||
const prefix = (() => {
|
const prefix = (() => {
|
||||||
try {
|
try {
|
||||||
return this.settings.getServer(serverId)?.get("prefix") ?? "%";
|
return this.settings.getServer(guildId)?.get("prefix") ?? "%";
|
||||||
} catch (_) { return "%"; }
|
} catch (_) { return "%"; }
|
||||||
})();
|
})();
|
||||||
message.replyEmbed(mkEmbed(`⚠️ I'm already playing in ${channelList}. Join that channel or use \`${prefix}play\` to start music in your channel.`));
|
message.replyEmbed(mkEmbed(`⚠️ I'm already playing in ${channelList}. Join that channel or use \`${prefix}play\` to start music in your channel.`));
|
||||||
@@ -206,13 +283,15 @@ export class PlayerManager {
|
|||||||
return new Promise(resolve => this.initPlayer(msg, autoDetected, (p) => resolve(p)));
|
return new Promise(resolve => this.initPlayer(msg, autoDetected, (p) => resolve(p)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverId = msg.channel?.server_id ?? msg.channel?.serverId;
|
const guildId = getMessageGuildId(msg);
|
||||||
const allChannels = serverId
|
const cleanGuildId = cleanId(guildId);
|
||||||
|
const allChannels = cleanGuildId
|
||||||
? [...(this.commands.client?.channels?.values?.() ??
|
? [...(this.commands.client?.channels?.values?.() ??
|
||||||
this.commands.client?.channels?.cache?.values?.() ?? [])]
|
this.commands.client?.channels?.cache?.values?.() ?? [])]
|
||||||
.filter(c => {
|
.filter(c => {
|
||||||
const cServerId = c.server_id ?? c.serverId;
|
const channelGuildId = cleanId(c.guildId ?? c.guild?.id ?? c.server_id ?? c.serverId);
|
||||||
return cServerId === serverId && c.channel_type === "VoiceChannel";
|
const isVoice = c.channel_type === "VoiceChannel" || c.type === "VoiceChannel" || c.type === 2;
|
||||||
|
return channelGuildId === cleanGuildId && isVoice;
|
||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
@@ -342,8 +421,10 @@ export class PlayerManager {
|
|||||||
return message.replyEmbed(mkEmbed("❌ Please join a **voice channel** first before using this command!"));
|
return message.replyEmbed(mkEmbed("❌ Please join a **voice channel** first before using this command!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.playerMap.has(cid)) {
|
const cleanChannelId = cleanId(cid);
|
||||||
const existing = this.playerMap.get(cid);
|
const existing = this.playerMap.get(cleanChannelId)
|
||||||
|
?? [...this.playerMap.values()].find((entry) => getPlayerChannelId(entry) === cleanChannelId);
|
||||||
|
if (existing) {
|
||||||
existing.textChannel = message.channel;
|
existing.textChannel = message.channel;
|
||||||
cb(existing);
|
cb(existing);
|
||||||
return message.replyEmbed(mkEmbed(`Already joined <#${cid}>.`));
|
return message.replyEmbed(mkEmbed(`Already joined <#${cid}>.`));
|
||||||
@@ -362,19 +443,19 @@ export class PlayerManager {
|
|||||||
player.textChannel = message.channel;
|
player.textChannel = message.channel;
|
||||||
|
|
||||||
player.on("autoleave", () => {
|
player.on("autoleave", () => {
|
||||||
const activeChannelId = String(player._channelId ?? cid).replace(/\D/g, "") || cid;
|
const activeChannelId = getPlayerChannelId(player, cleanChannelId) || cleanChannelId;
|
||||||
const homeChannelId = String(player._home247Channel ?? activeChannelId).replace(/\D/g, "") || activeChannelId;
|
const homeChannelId = cleanId(player._home247Channel) || activeChannelId;
|
||||||
const ch = player.textChannel;
|
const ch = player.textChannel;
|
||||||
const serverId = ch?.server_id ?? ch?.serverId ?? ch?.guild?.id;
|
const guildId = cleanId(player._guildId ?? ch?.guildId ?? ch?.guild?.id ?? getMessageGuildId({ channel: ch }));
|
||||||
const is247 = (() => {
|
const is247 = (() => {
|
||||||
try {
|
try {
|
||||||
const raw = this.settings.getServer(serverId)?.get("stay_247");
|
const raw = this.settings.getServer(guildId)?.get("stay_247");
|
||||||
return raw && raw !== "none";
|
return raw && raw !== "none";
|
||||||
} catch (_) { return false; }
|
} catch (_) { return false; }
|
||||||
})();
|
})();
|
||||||
const prefix = (() => {
|
const prefix = (() => {
|
||||||
try {
|
try {
|
||||||
return this.settings.getServer(serverId)?.get("prefix") ?? "%";
|
return this.settings.getServer(guildId)?.get("prefix") ?? "%";
|
||||||
} catch (_) { return "%"; }
|
} catch (_) { return "%"; }
|
||||||
})();
|
})();
|
||||||
const desc = is247
|
const desc = is247
|
||||||
@@ -382,7 +463,7 @@ export class PlayerManager {
|
|||||||
: `Left channel <#${activeChannelId}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
|
: `Left channel <#${activeChannelId}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
|
||||||
ch?.sendEmbed(mkEmbed(desc));
|
ch?.sendEmbed(mkEmbed(desc));
|
||||||
this.playerMap.delete(activeChannelId);
|
this.playerMap.delete(activeChannelId);
|
||||||
if (activeChannelId !== cid) this.playerMap.delete(cid);
|
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
|
||||||
if (homeChannelId !== activeChannelId) this.playerMap.delete(homeChannelId);
|
if (homeChannelId !== activeChannelId) this.playerMap.delete(homeChannelId);
|
||||||
player.destroy();
|
player.destroy();
|
||||||
});
|
});
|
||||||
@@ -391,15 +472,15 @@ export class PlayerManager {
|
|||||||
|
|
||||||
player.on("message", (m) => {
|
player.on("message", (m) => {
|
||||||
const ch = player.textChannel;
|
const ch = player.textChannel;
|
||||||
const serverId = ch?.server_id ?? ch?.serverId ?? ch?.guild?.id;
|
const guildId = cleanId(player._guildId ?? ch?.guildId ?? ch?.guild?.id ?? getMessageGuildId({ channel: ch }));
|
||||||
const raw = this.settings.getServer(serverId)?.get("songAnnouncements");
|
const raw = this.settings.getServer(guildId)?.get("songAnnouncements");
|
||||||
const disabled = raw === false || raw === 0 ||
|
const disabled = raw === false || raw === 0 ||
|
||||||
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
ch?.sendEmbed(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m));
|
ch?.sendEmbed(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.playerMap.set(cid, player);
|
this.playerMap.set(cleanChannelId, player);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const statusMsg = await message.replyEmbed(mkEmbed("⏳ Joining Channel..."));
|
const statusMsg = await message.replyEmbed(mkEmbed("⏳ Joining Channel..."));
|
||||||
@@ -407,9 +488,9 @@ export class PlayerManager {
|
|||||||
await player.join(cid);
|
await player.join(cid);
|
||||||
await statusMsg.editEmbed(mkEmbed(`✅ Successfully joined <#${cid}>`));
|
await statusMsg.editEmbed(mkEmbed(`✅ Successfully joined <#${cid}>`));
|
||||||
|
|
||||||
const serverId = message.channel?.server_id ?? message.channel?.serverId;
|
const guildId = cleanId(channel.guildId ?? getMessageGuildId(message));
|
||||||
if (serverId) {
|
if (guildId) {
|
||||||
const savedVol = this.settings.getServer(serverId)?.get("volume");
|
const savedVol = this.settings.getServer(guildId)?.get("volume");
|
||||||
if (savedVol !== undefined && savedVol !== null) {
|
if (savedVol !== undefined && savedVol !== null) {
|
||||||
const vol = Number(savedVol);
|
const vol = Number(savedVol);
|
||||||
if (!isNaN(vol)) player.setVolume(vol / 100);
|
if (!isNaN(vol)) player.setVolume(vol / 100);
|
||||||
@@ -419,9 +500,35 @@ export class PlayerManager {
|
|||||||
cb(player);
|
cb(player);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await statusMsg.editEmbed(mkEmbed(`❌ Failed to join: ${err.message}`)).catch(() => {});
|
await statusMsg.editEmbed(mkEmbed(`❌ Failed to join: ${err.message}`)).catch(() => {});
|
||||||
this.playerMap.delete(cid);
|
this.playerMap.delete(cleanChannelId);
|
||||||
player.destroy();
|
player.destroy();
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
async leave(msg, cid) {
|
||||||
|
if (!cid) {
|
||||||
|
const guildId = getMessageGuildId(msg);
|
||||||
|
if (guildId) {
|
||||||
|
const matchedEntry = [...this.playerMap.entries()].find(([, player]) =>
|
||||||
|
getPlayerGuildId(player) === cleanId(guildId)
|
||||||
|
);
|
||||||
|
cid = getPlayerChannelId(matchedEntry?.[1], matchedEntry?.[0]) || matchedEntry?.[0] || null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cleanChannelId = cleanId(cid);
|
||||||
|
const player = cleanChannelId
|
||||||
|
? this.playerMap.get(cleanChannelId) ??
|
||||||
|
[...this.playerMap.values()].find((entry) => getPlayerChannelId(entry) === cleanChannelId)
|
||||||
|
: null;
|
||||||
|
if (!player) return msg.replyEmbed(mkEmbed("I'm not in a voice channel."));
|
||||||
|
|
||||||
|
const activeChannelId = getPlayerChannelId(player, cleanChannelId) || cleanChannelId;
|
||||||
|
this.playerMap.delete(activeChannelId);
|
||||||
|
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
|
||||||
|
await msg.replyEmbed(mkEmbed("✅ Successfully Left"));
|
||||||
|
await player.leave();
|
||||||
|
player.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user