mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
feat: add %wrapped global and %top global cross-server statistics
This commit is contained in:
1 parent
22f48cfaab
commit
04ce02f672
11 files changed
+305
-41
No files matched your search
+38
-14
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @module commands/top
|
||||
* @description Display the most played tracks and top artists for the server.
|
||||
* @description Display the most played tracks and top artists for the server or global network.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/commands/index.mjs";
|
||||
@@ -18,7 +18,7 @@ export const command = new CommandBuilder()
|
||||
.addTextOption((o) =>
|
||||
o
|
||||
.setName("timeframe")
|
||||
.setDescription("Filter timeframe: week, month, or all.", "options.top.timeframe")
|
||||
.setDescription("Filter timeframe: week, month, all, or global.", "options.top.timeframe")
|
||||
.setRequired(false)
|
||||
);
|
||||
|
||||
@@ -32,27 +32,51 @@ export async function run(message, data) {
|
||||
const guildId = cleanId(message.message?.guildId ?? message.channel?.guildId);
|
||||
const prefix = this.handler.getPrefix(guildId) || "%";
|
||||
|
||||
const rawArg = (data?.get?.("timeframe")?.value ?? "").trim().toLowerCase();
|
||||
const rawArg = (
|
||||
data?.get?.("timeframe")?.value ??
|
||||
(message.message?.content || message.content || "").split(/\s+/)[1] ??
|
||||
""
|
||||
).trim().toLowerCase();
|
||||
|
||||
const isGlobal = rawArg === "global" || rawArg === "network";
|
||||
let timeframe = "month";
|
||||
if (rawArg === "week" || rawArg === "w" || rawArg === "7d") {
|
||||
if (isGlobal) {
|
||||
timeframe = "global";
|
||||
} else if (rawArg === "week" || rawArg === "w" || rawArg === "7d") {
|
||||
timeframe = "week";
|
||||
} else if (rawArg === "all" || rawArg === "alltime" || rawArg === "total") {
|
||||
timeframe = "all";
|
||||
}
|
||||
|
||||
const { tracks, topArtist } = GuildStats.getTopTracks(guildId, timeframe, 10);
|
||||
const { tracks, topArtist } = isGlobal
|
||||
? GuildStats.getGlobalTopTracks(10)
|
||||
: GuildStats.getTopTracks(guildId, timeframe, 10);
|
||||
|
||||
const timeframeLabel = timeframe === "week"
|
||||
? this.t(message, "responses.top.timeframeWeek")
|
||||
: (timeframe === "all" ? this.t(message, "responses.top.timeframeAll") : this.t(message, "responses.top.timeframeMonth"));
|
||||
const authorName = isGlobal
|
||||
? `🌐 ${this.t(message, "responses.top.globalAuthor")}`
|
||||
: `🏆 ${this.t(message, "responses.top.topAuthor")}`;
|
||||
|
||||
const timeframeLabel = isGlobal
|
||||
? "Global"
|
||||
: (timeframe === "week"
|
||||
? this.t(message, "responses.top.timeframeWeek")
|
||||
: (timeframe === "all" ? this.t(message, "responses.top.timeframeAll") : this.t(message, "responses.top.timeframeMonth")));
|
||||
|
||||
const titleName = isGlobal
|
||||
? this.t(message, "responses.top.globalTitle")
|
||||
: this.t(message, "responses.top.topTitle", { timeframe: timeframeLabel });
|
||||
|
||||
const footerText = isGlobal
|
||||
? this.t(message, "responses.top.globalFooter", { prefix })
|
||||
: this.t(message, "responses.top.topFooter", { prefix });
|
||||
|
||||
if (!tracks || tracks.length === 0) {
|
||||
const emptyEmbed = new EmbedBuilder()
|
||||
.setColor(getGlobalColor())
|
||||
.setAuthor({ name: `🏆 ${this.t(message, "responses.top.topAuthor")}` })
|
||||
.setTitle(this.t(message, "responses.top.topTitle", { timeframe: timeframeLabel }))
|
||||
.setAuthor({ name: authorName })
|
||||
.setTitle(titleName)
|
||||
.setDescription(this.t(message, "responses.top.noData", { prefix }))
|
||||
.setFooter({ text: this.t(message, "responses.top.topFooter", { prefix }) });
|
||||
.setFooter({ text: footerText });
|
||||
return message.reply({ embeds: [emptyEmbed] });
|
||||
}
|
||||
|
||||
@@ -73,10 +97,10 @@ export async function run(message, data) {
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(getGlobalColor())
|
||||
.setAuthor({ name: `🏆 ${this.t(message, "responses.top.topAuthor")}` })
|
||||
.setTitle(this.t(message, "responses.top.topTitle", { timeframe: timeframeLabel }))
|
||||
.setAuthor({ name: authorName })
|
||||
.setTitle(titleName)
|
||||
.setDescription(desc)
|
||||
.setFooter({ text: this.t(message, "responses.top.topFooter", { prefix }) });
|
||||
.setFooter({ text: footerText });
|
||||
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
+80
-3
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @module commands/wrapped
|
||||
* @description Generate community music recap and statistics for the server.
|
||||
* @description Generate community music recap and statistics for the server or global network.
|
||||
*/
|
||||
|
||||
import { CommandBuilder } from "../src/commands/index.mjs";
|
||||
@@ -14,17 +14,94 @@ export const command = new CommandBuilder()
|
||||
.setName("wrapped")
|
||||
.setDescription("Generate a community music recap and listening statistics.", "commands.wrapped")
|
||||
.addAliases("recap", "summary")
|
||||
.setCategory("music");
|
||||
.setCategory("music")
|
||||
.addTextOption((o) =>
|
||||
o
|
||||
.setName("scope")
|
||||
.setDescription("Recap scope: server or global.", "options.wrapped.scope")
|
||||
.setRequired(false)
|
||||
);
|
||||
|
||||
/**
|
||||
* Run handler for the wrapped command.
|
||||
* @param {object} message
|
||||
* @param {object} [data]
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function run(message) {
|
||||
export async function run(message, data) {
|
||||
const guildId = cleanId(message.message?.guildId ?? message.channel?.guildId);
|
||||
const prefix = this.handler.getPrefix(guildId) || "%";
|
||||
|
||||
const rawArg = (
|
||||
data?.get?.("scope")?.value ??
|
||||
(message.message?.content || message.content || "").split(/\s+/)[1] ??
|
||||
""
|
||||
).trim().toLowerCase();
|
||||
|
||||
const isGlobal = rawArg === "global" || rawArg === "all" || rawArg === "network";
|
||||
|
||||
if (isGlobal) {
|
||||
const serverCount = this.client?.guilds?.size ?? 1300;
|
||||
const stats = GuildStats.getGlobalWrapped(serverCount);
|
||||
|
||||
if (!stats) {
|
||||
const emptyEmbed = new EmbedBuilder()
|
||||
.setColor(getGlobalColor())
|
||||
.setAuthor({ name: `🌐 ${this.t(message, "responses.wrapped.globalAuthor")}` })
|
||||
.setTitle(this.t(message, "responses.wrapped.globalTitle"))
|
||||
.setDescription(this.t(message, "responses.top.noData", { prefix }))
|
||||
.setFooter({ text: this.t(message, "responses.wrapped.globalFooter", { prefix }) });
|
||||
return message.reply({ embeds: [emptyEmbed] });
|
||||
}
|
||||
|
||||
const playsLabel = this.t(message, "responses.top.plays");
|
||||
const medals = ["🥇", "🥈", "🥉", "4️⃣", "5️⃣"];
|
||||
|
||||
let topSongsText = "";
|
||||
if (stats.topTracks && stats.topTracks.length > 0) {
|
||||
topSongsText = stats.topTracks
|
||||
.map((t, i) => `${medals[i] || "•"} **${Utils.truncate(t.title, 35)}** — *${Utils.truncate(t.artist, 25)}* (\`${t.count} ${playsLabel}\`)`)
|
||||
.join("\n");
|
||||
} else {
|
||||
topSongsText = "_No track history recorded yet._";
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(getGlobalColor())
|
||||
.setAuthor({ name: `🌐 ${this.t(message, "responses.wrapped.globalAuthor")}` })
|
||||
.setTitle(this.t(message, "responses.wrapped.globalTitle"))
|
||||
.addFields(
|
||||
{
|
||||
name: `⏱️ ${this.t(message, "responses.wrapped.totalStreamed")}`,
|
||||
value: `**${stats.totalHours}** hours`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `🎵 ${this.t(message, "responses.wrapped.tracksQueued")}`,
|
||||
value: `**${stats.totalTracks.toLocaleString()}** tracks`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `⏰ ${this.t(message, "responses.wrapped.peakHour")}`,
|
||||
value: `**${stats.peakHour}**`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `🌍 ${this.t(message, "responses.wrapped.activeServers")}`,
|
||||
value: `**${stats.totalGuilds.toLocaleString()}** servers`,
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: `🏆 ${this.t(message, "responses.wrapped.topSongs")}`,
|
||||
value: topSongsText,
|
||||
inline: false,
|
||||
}
|
||||
)
|
||||
.setFooter({ text: this.t(message, "responses.wrapped.globalFooter", { prefix }) });
|
||||
|
||||
return message.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const stats = GuildStats.getWrapped(guildId);
|
||||
|
||||
if (!stats) {
|
||||
|
||||
Reference in new issue
Block a user