mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
- Move voice state population outside settings conditional in GuildCreate (now runs on every gateway resume, not just new guild joins) - Make checkVoiceChannels() async with Fluxer API fallback (fetches member voice state directly when cache is empty after reboot) - Fix PlayerManager client reference passing - Update all callers to properly await checkVoiceChannels() - Fix leave command to work without requiring user in voice channel Fixes issue where bot couldn't detect users already in voice channels immediately after a reboot due to empty voice state cache.
80 lines
3.2 KiB
JavaScript
80 lines
3.2 KiB
JavaScript
import { CommandBuilder } from "../src/CommandHandler.mjs";
|
|
import { Utils } from "../src/Utils.mjs";
|
|
import { EmbedBuilder } from "@fluxerjs/core";
|
|
import { getGlobalColor } from "../src/MessageHandler.mjs";
|
|
|
|
export const command = new CommandBuilder()
|
|
.setName("stats")
|
|
.setDescription("Display stats about the bot like the uptime.", "commands.stats")
|
|
.addAliases("info")
|
|
.setCategory("util");
|
|
|
|
// ── User count ────────────────────────────────────────────────────────────────
|
|
|
|
async function fetchUserCount(client) {
|
|
try {
|
|
let total = 0;
|
|
for (const guild of client.guilds.cache.values()) {
|
|
total += guild.memberCount ?? guild.member_count ?? 0;
|
|
}
|
|
return total;
|
|
} catch { return 0; }
|
|
}
|
|
|
|
// ── Embed builder ─────────────────────────────────────────────────────────────
|
|
|
|
function buildEmbed({ guildCount, userCount, playerCount, ping, uptime, comHash, comLink, reason, footer, loading }) {
|
|
const num = (v) => Number(v).toLocaleString();
|
|
const ld = (v) => loading ? "..." : v;
|
|
|
|
const description = [
|
|
`📂 **Servers** — \`${num(guildCount)}\``,
|
|
`👥 **Users** — \`${ld(num(userCount))}\``,
|
|
`🎧 **Players** — \`${num(playerCount)}\``,
|
|
`🏓 **Ping** — \`${ld(`${ping}ms`)}\``,
|
|
`⏱️ **Uptime** — \`${uptime}\``,
|
|
`🔧 **Build** — [\`${comHash}\`](${comLink})`,
|
|
reason ? `🪛 **Last restart** — \`${reason}\`` : null,
|
|
``,
|
|
`☕ [Support us on Ko-fi](https://ko-fi.com/remixbot)`,
|
|
`💬 [Community](https://fluxer.gg/Remix)`,
|
|
].filter(l => l !== null).join("\n");
|
|
|
|
const builder = new EmbedBuilder()
|
|
.setColor(getGlobalColor())
|
|
.setAuthor({ name: "Remix Music Bot" })
|
|
.setDescription(description)
|
|
.setFooter({ text: footer || "Remix Music Bot" });
|
|
// setTimestamp() is not verified on @fluxerjs/core's EmbedBuilder — call it only
|
|
// if the method exists so the command doesn't throw when building the embed.
|
|
if (typeof builder.setTimestamp === "function") builder.setTimestamp();
|
|
return builder.toJSON();
|
|
}
|
|
|
|
// ── Runner ────────────────────────────────────────────────────────────────────
|
|
|
|
export async function run(message) {
|
|
const shared = {
|
|
guildCount: this.client.guilds.cache.size,
|
|
playerCount: this.players.playerMap.size,
|
|
uptime: Utils.prettifyMS(Math.round(process.uptime()) * 1000),
|
|
comHash: this.comHash,
|
|
comLink: this.comLink,
|
|
reason: this.config.restart ?? null,
|
|
footer: this.config.customStatsFooter || null,
|
|
};
|
|
|
|
const start = Date.now();
|
|
|
|
const msg = await message.replyEmbed({
|
|
embeds: [buildEmbed({ ...shared, userCount: 0, ping: 0, loading: true })]
|
|
});
|
|
|
|
const ping = Date.now() - start;
|
|
const users = await fetchUserCount(this.client);
|
|
|
|
await msg.editEmbed({
|
|
embeds: [buildEmbed({ ...shared, userCount: users, ping, loading: false })]
|
|
}).catch(() => {});
|
|
}
|