test: some cool stuff from shadowsss

This commit is contained in:
NoLogicAlan committed 2026-04-16 16:06:24 +03:00
1 parent 47b1615cbc
commit 910a244120
2 files changed
+62 -12

No files matched your search

+53 -7
View File
@@ -56,8 +56,8 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
} catch (_) { return "%"; }
})();
const desc = is247
? `Left channel <#${cid}> because of inactivity.`
: `Left channel <#${cid}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
? `Left channel <#${cid}> because of inactivity.`
: `Left channel <#${cid}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription(desc)
.toJSON();
@@ -98,16 +98,62 @@ export const command = new CommandBuilder()
.setName("join")
.setDescription("Make the bot join your voice channel, or specify one.", "commands.join")
.setId("join")
.setCategory("music");
.setCategory("music")
.addTextOption(option =>
option.setName("channel")
.setDescription("A voice channel mention, ID, or name to join. Defaults to your current channel.")
.setRequired(false)
);
export function run(message) {
// @fluxerjs/core Message has no .member property — voice channel detection
// is handled entirely by checkVoiceChannels() via the VoiceManager state map.
export function run(message, data) {
// Check if a channel argument was provided (mention like <#123456>, bare ID, or name)
const rawArg = data?.get?.("channel")?.value?.trim?.() ?? null;
if (rawArg) {
// Parse channel mention <#ID>, bare numeric ID, or channel name
const mentionMatch = rawArg.match(/^<#(\d+)>$/);
const idMatch = rawArg.match(/^(\d{15,})$/);
let resolvedId = null;
if (mentionMatch) {
resolvedId = mentionMatch[1];
} else if (idMatch) {
resolvedId = idMatch[1];
} else {
// Try to look up by name
const serverId = message.channel?.server_id ?? message.channel?.serverId;
const allChannels = [
...(this._commands?.client?.channels?.values?.() ??
this._commands?.client?.channels?.cache?.values?.() ??
this.client?.channels?.values?.() ??
this.client?.channels?.cache?.values?.() ?? [])
];
const match = allChannels.find(c => {
const cServerId = c.server_id ?? c.serverId ?? c.guildId;
const isVoice = c.channel_type === "VoiceChannel" || c.type === "VoiceChannel" || c.type === 2;
return isVoice && cServerId === serverId &&
(c.name?.toLowerCase() === rawArg.toLowerCase());
});
if (match) resolvedId = match._id ?? match.id;
}
if (!resolvedId) {
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("❌ Couldn't find that voice channel. Try using a mention like `<#channelid>` or the exact channel name.")
.toJSON();
return message.replyEmbed({ embeds: [embed] });
}
return this.players.initPlayer(message, resolvedId);
}
// No argument — auto-detect the user's current voice channel
const cid = this.players.checkVoiceChannels(message);
if (!cid) {
const prefix = this._commands?.getPrefix?.(message.channel?.guild?.id ?? message.channel?.server_id ?? message.channel?.serverId) ?? "%";
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("❌ You're not in a voice channel. Please join one first.")
.setDescription(`❌ You're not in a voice channel. Please join one first, or specify a channel: \`${prefix}join <#channel>\``)
.toJSON();
return message.replyEmbed({ embeds: [embed] });
}
+9 -5
View File
@@ -138,6 +138,10 @@ export class PlayerManager {
}
if (!userChannelId) {
if (shouldJoin) {
// Auto-detect failed — fall back to interactive channel selection prompt
return this.promptVC(message);
}
message.replyEmbed(mkEmbed("⚠️ Please join a voice channel first."));
return null;
}
@@ -163,7 +167,7 @@ export class PlayerManager {
async promptVC(msg) {
const autoDetected = this.checkVoiceChannels(msg);
if (autoDetected) {
return new Promise(resolve => this.initPlayer(msg, autoDetected, () => resolve(autoDetected)));
return new Promise(resolve => this.initPlayer(msg, autoDetected, (p) => resolve(p)));
}
const serverId = msg.channel?.server_id ?? msg.channel?.serverId;
@@ -215,7 +219,7 @@ export class PlayerManager {
clearTimeout(timeout);
cleanup();
const cid = channel._id ?? channel.id;
this.initPlayer(msg, cid, () => resolve(cid));
this.initPlayer(msg, cid, (p) => resolve(p));
},
msg.author
);
@@ -237,7 +241,7 @@ export class PlayerManager {
const channel = this.commands.formatInput("voiceChannel", m.content, m);
clearTimeout(timeout);
cleanup();
this.initPlayer(m, channel, () => resolve(channel));
this.initPlayer(m, channel, (p) => resolve(p));
}, msg.author);
});
}
@@ -335,8 +339,8 @@ export class PlayerManager {
} catch (_) { return "%"; }
})();
const desc = is247
? `Left channel <#${cid}> because of inactivity.`
: `Left channel <#${cid}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
? `Left channel <#${cid}> because of inactivity.`
: `Left channel <#${cid}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
ch?.sendEmbed(mkEmbed(desc));
this.playerMap.delete(cid);
player.destroy();