Files
fluxer/commands/lastfm.mjs
T
NoLogicAlan 253d11cd57 Remix — the complete rewrite
Upgrades the bot from fluxerjs 2.2 to 3.0 and restructures everything
into a layered architecture (~28K lines):

Dependencies:
- @fluxerjs/core, util, voice: ^2.2.0 -> ^3.0.0 (typed events,
  PartialMessage payloads, camelCase API)
- @fluxerjs/sharding ^3.0.0 added — built-in sharding mode
  (shard.mjs, one process per shard)
- @discordjs/opus dropped — opusscript + prism-media cover encoding

Architecture:
- commands: every command split into submodules (player, lastfm,
  settings, debug) with a shared CommandBuilder/Loader/Handler core
- ui: embeds, paginators, help command, permission checks
- voice: gateway event routing, rejoin/247 boot recovery, state resolver
- music: player split into Queue/Search/Playback/Display mixins,
  stream pipeline + WebM/Opus muxer (no FFmpeg needed)
- dashboard: Redis pub/sub, RPC handlers, serializers
- db: MySQL manager + per-guild settings
- services: LastFm manager split into focused mixins
- utils: sharding, 24/7 helpers, API client

Runtime fixes over v2:
- Redis v5 reconnect: capped numeric backoff (0.5s ramp to 15s),
  never exhausts, auto-recovers when the server comes back
- Redis main/subscriber clients connect in parallel; clean shutdown
- Logger storm guard: identical error/warn lines deduped in a 60s window
- self-deaf fix on voice join
- config example uses redis://127.0.0.1 (avoids IPv6 ENETUNREACH)

Housekeeping: dead code removed (Tuna.mjs + follow-redirects dep),
.gitignore added (config.json, .env, node_modules, runtime state).
2026-09-09 02:04:33 +03:00

98 lines
4.3 KiB
JavaScript

/**
* @module commands/lastfm
* @description Last.fm integration command supporting account linking, scrobbling,
* profile viewing, leaderboards, whoknows, and playlist playback. The action
* implementations live in commands/lastfm/ (one module per action family);
* run() below dispatches to them via their action sets.
*/
import { CommandBuilder } from "../src/commands/index.mjs";
import {
ACCOUNT_ACTIONS, runAccountActions,
PLAYBACK_ACTIONS, runPlaybackActions,
LISTENING_ACTIONS, runListeningActions,
WHOKNOWS_ACTIONS, runWhoknowsActions,
INFO_ACTIONS, runInfoActions,
TAG_ACTIONS, runTagActions,
DISCOVERY_ACTIONS, runDiscoveryActions,
runLastFmHelp,
notConfigured,
} from "./lastfm/index.mjs";
export { playLastFmCategory } from "./lastfm/playback.mjs";
/**
* @type {CommandBuilder}
* @description Command definition for the lastfm command.
*/
export const command = new CommandBuilder()
.setName("lastfm")
.setDescription("Link your Last.fm account, toggle scrobbling, or view your profile.", "commands.lastfm")
.setCategory("util")
.addAliases("lf", "lfm")
.addChoiceOption(o =>
o.setName("action")
.setDescription("The action to perform: link, unlink, np, profile, loved, top, recent, playlists, play, scrobble, leaderboard, whoknows, artistinfo, albuminfo, trackinfo, topalbums, toptags, tag, compare, cover, refreshmembers, affinity, crowns, whoknowstrack, whoknowsalbum, artisttags, albumtags, tracktags, friends, weekly, trending, geo, tagalbums, artisttracks, search", "options.lastfm.action")
.addChoices(
"link", "confirm", "unlink", "np", "profile", "loved", "top", "recent",
"playlists", "play", "scrobble", "leaderboard", "lb", "love", "unlove",
"artists", "whoknows", "wk", "artistinfo", "ai", "albuminfo", "ali",
"trackinfo", "ti", "topalbums", "toptags", "tags", "tag", "compare",
"fmc", "cover", "art", "refreshmembers", "rm", "affinity", "af",
"crowns", "cr", "whoknowstrack", "wkt", "whoknowsalbum", "wka",
"artisttags", "at", "albumtags", "alt", "tracktags", "tt",
"friends", "fr", "weekly", "wc", "trending", "tr",
"geo", "g", "tagalbums", "ta", "artisttracks", "atr",
"search", "s"
)
.setRequired(false)
)
.addUserOption(o =>
o.setName("user")
.setDescription("Another user (for compare/profile). Use: -user @mention or -u @mention")
.setRequired(false)
.addFlagAliases("u"),
true
)
.addTextOption(o =>
o.setName("token")
.setDescription("The auth token from Last.fm (used with 'confirm' action), or a search query / period")
.setRequired(false)
);
/**
* Run handler for the lastfm command.
* Routes to the appropriate subcommand based on the action option.
*
* @param {object} msg - The command message wrapper.
* @param {object} data - Parsed command data containing action, user, and token options.
* @returns {Promise<void>}
*/
export async function run(msg, data) {
const lastfm = this.lastfm;
if (!lastfm || !lastfm.enabled) return msg.reply(notConfigured(this, msg));
const prefix = this.handler.getPrefix(msg.message?.guildId);
const action = data.get("action")?.value ?? "profile";
const userId = msg.message?.author?.id ?? msg.author?.id;
const targetUserId = data.get("user")?.value ?? null;
if (ACCOUNT_ACTIONS.has(action))
return runAccountActions.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
if (PLAYBACK_ACTIONS.has(action))
return runPlaybackActions.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
if (LISTENING_ACTIONS.has(action))
return runListeningActions.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
if (WHOKNOWS_ACTIONS.has(action))
return runWhoknowsActions.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
if (INFO_ACTIONS.has(action))
return runInfoActions.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
if (TAG_ACTIONS.has(action))
return runTagActions.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
if (DISCOVERY_ACTIONS.has(action))
return runDiscoveryActions.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
return runLastFmHelp.call(this, msg, data, lastfm, prefix, userId, targetUserId, action);
}