rollback yes

This commit is contained in:
NoLogicAlan committed 2026-04-17 00:01:52 +03:00
1 parent 73c290e59c
commit f402237ad3
9 files changed
+506 -189

No files matched your search

+107 -9
View File
@@ -1,23 +1,116 @@
import { CommandBuilder } from "../src/CommandHandler.mjs";
import { EmbedBuilder } from "@fluxerjs/core";
import { getGlobalColor } from "../src/MessageHandler.mjs";
import Player from "../src/Player.mjs";
export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
if (!this.client.channels.cache.has(cid)) {
ecb();
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("Couldn't find the channel `" + cid + "`\nUse the help command to learn more about this. (`%help join`)")
.toJSON();
return message.replyEmbed({ embeds: [embed] });
}
if (this.players.playerMap.has(cid)) {
cb(this.players.playerMap.get(cid));
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("Already joined <#" + cid + ">.")
.toJSON();
return message.replyEmbed({ embeds: [embed] });
}
// Guard: moonlink must be ready before we can play anything
if (!this.moonlink) {
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("⚠️ Audio node is still connecting — please try again in a few seconds.")
.toJSON();
ecb();
return message.replyEmbed({ embeds: [embed] });
}
const p = new Player(this.config.token, {
client: this.client,
config: this.config,
nodelink: this.config.nodelink,
moonlink: this.moonlink ?? null,
messageChannel: message.channel,
settingsMgr: this.settingsMgr ?? this.settings ?? null,
observedVoiceUsers: this.observedVoiceUsers ?? null,
});
p.on("autoleave", () => {
const guildId = message.channel?.guildId
?? message.channel?.guild?.id
?? message.message?.guildId
?? message.channel?.server_id
?? message.channel?.serverId;
const is247 = (() => {
try {
const raw = this.settingsMgr?.getServer?.(guildId)?.get?.("stay_247");
return raw && raw !== "none";
} catch (_) { return false; }
})();
const prefix = (() => {
try {
return this._commands?.getPrefix?.(message.channel?.guild?.id) ?? "%";
} 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\``;
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription(desc)
.toJSON();
message.channel.sendEmbed({ embeds: [embed] });
this.players.playerMap.delete(cid);
p.destroy();
});
p.on("message", m => {
const guildId = message.channel?.guild?.id ?? message.channel?.server_id ?? message.channel?.serverId;
const raw = this.settingsMgr?.getServer?.(guildId)?.get("songAnnouncements");
const disabled = raw === false || raw === 0 ||
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
if (disabled) return;
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(m).toJSON();
message.channel.sendEmbed({ embeds: [embed] });
});
this.players.playerMap.set(cid, p);
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription("⏳ Joining Channel...").toJSON();
const statusMsg = await message.replyEmbed({ embeds: [joiningEmbed] });
try {
await p.join(cid);
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`✅ Successfully joined <#${cid}>`).toJSON();
await statusMsg.editEmbed({ embeds: [okEmbed] });
cb(p);
} catch (e) {
this.players.playerMap.delete(cid);
p.destroy();
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(`❌ Failed to join: ${e.message}`).toJSON();
await statusMsg.editEmbed({ embeds: [errEmbed] });
ecb(e);
}
}
export const command = new CommandBuilder()
.setName("join")
.setDescription("Make the bot join your voice channel, or specify one.")
.setDescription("Make the bot join your voice channel, or specify one.", "commands.join")
.setId("join")
.setCategory("music")
.addTextOption(option =>
option.setName("channel")
.setDescription("A voice channel mention, ID, or name to join.")
.setDescription("A voice channel mention, ID, or name to join. Defaults to your current channel.")
.setRequired(false)
);
export async function run(message, data) {
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, or name
// Parse channel mention <#ID>, bare numeric ID, or channel name
const mentionMatch = rawArg.match(/^<#(\d+)>$/);
const idMatch = rawArg.match(/^(\d{15,})$/);
let resolvedId = null;
@@ -27,7 +120,7 @@ export async function run(message, data) {
} else if (idMatch) {
resolvedId = idMatch[1];
} else {
// Lookup by name
// Try to look up by name
const serverId = message.channel?.server_id ?? message.channel?.serverId;
const allChannels = [
...(this._commands?.client?.channels?.values?.() ??
@@ -46,7 +139,7 @@ export async function run(message, data) {
if (!resolvedId) {
const embed = new EmbedBuilder().setColor(getGlobalColor())
.setDescription("❌ Couldn't find that voice channel.")
.setDescription("❌ Couldn't find that voice channel. Try using a mention like `<#channelid>` or the exact channel name.")
.toJSON();
return message.replyEmbed({ embeds: [embed] });
}
@@ -54,8 +147,8 @@ export async function run(message, data) {
return this.players.initPlayer(message, resolvedId);
}
// No argument — auto-detect (CRITICAL: must await here)
const cid = await this.players.checkVoiceChannels(message);
// 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) ?? "%";
@@ -66,4 +159,9 @@ export async function run(message, data) {
}
this.players.initPlayer(message, cid);
}
}
export const exportDef = {
name: "joinChannel",
object: joinChannel
};
+17 -26
View File
@@ -16,35 +16,26 @@ function embed(desc) {
export async function run(msg) {
const guildId = msg.channel?.guild?.id ?? msg.message?.guildId;
// Get all players in this guild
const guildPlayers = [...this.players.playerMap.entries()]
.filter(([chId, p]) => p._guildId === guildId);
const userChannelId = this.players.checkVoiceChannels(msg);
if (!userChannelId) return msg.replyEmbed(embed("⚠️ Please join a voice channel first."));
if (guildPlayers.length === 0) {
return msg.replyEmbed(embed("❌ I'm not in a voice channel in this server."));
const cid = String(userChannelId).replace(/\D/g, "");
if (!this.players.playerMap.has(cid)) {
const guildChannels = [...this.players.playerMap.entries()]
.filter(([chId, p]) => p._guildId === guildId)
.map(([chId]) => `<#${chId}>`);
if (guildChannels.length === 0) return msg.replyEmbed(embed("I'm not in a voice channel."));
if (guildChannels.length === 1) return msg.replyEmbed(embed(`⚠️ Please join ${guildChannels[0]} to use this command.`));
return msg.replyEmbed(embed(
`⚠️ I'm playing in multiple channels! Please join one of them:\n` +
guildChannels.map(c => `• ${c}`).join("\n")
));
}
let cid;
// Try to find the channel the user is in (optional, for convenience)
const userChannelId = await this.players.checkVoiceChannels(msg);
if (userChannelId && guildPlayers.some(([chId]) => chId === userChannelId)) {
// User is in a channel where the bot is playing - use that one
cid = userChannelId;
} else if (guildPlayers.length === 1) {
// Only one player in guild - use that one
cid = guildPlayers[0][0];
} else {
// Multiple channels - use the first one found
// Or you could implement a selection menu here
cid = guildPlayers[0][0];
}
cid = String(cid).replace(/\D/g, "");
const player = this.players.playerMap.get(cid);
if (!player?.connection) return msg.replyEmbed(embed("❌ Player not initialized."));
if (!player?.connection) return msg.replyEmbed(embed("Player not initialized."));
const set = this.getSettings(msg);
const raw = set?.get("stay_247");
@@ -77,4 +68,4 @@ export async function run(msg) {
} else {
await this.leaveChannel(cid, guildId, msg);
}
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ export const command = new CommandBuilder()
.setCategory("music");
export async function run(message) {
const p = await this.getPlayer(message, false, false, false);
const p = await this.getPlayer(message, false, true, false);
if (!p) return;
const res = p.resume();
const embed = new EmbedBuilder()
+1 -1
View File
@@ -8,7 +8,7 @@ export const command = new CommandBuilder()
.setCategory("music");
export async function run(message) {
const p = await this.getPlayer(message, false, false, false);
const p = await this.getPlayer(message, false, true, false);
if (!p) return;
const res = p.shuffle();
const embed = new EmbedBuilder()
+4
View File
@@ -12,6 +12,10 @@ export const command = new CommandBuilder()
// ── User count ────────────────────────────────────────────────────────────────
async function fetchUserCount(client) {
// client.rest is a concept and is not available on @fluxerjs/core.
// Use guild.memberCount (a cached integer Fluxer exposes on every Guild object)
// instead of paginating the REST members endpoint.
// Falls back to 0 per guild if the property is absent so the stat still renders.
try {
let total = 0;
for (const guild of client.guilds.cache.values()) {