mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 13:02:49 +08:00
fix(profile): apply custom avatar immediately on idle setCustomAvatar / connect
Review feedback on PR #56: 1. setCustomAvatar(buf) now triggers applyIdleAvatar when the bot is idle (currentSong=null OR avatarEnabled=false). Spec said this; original impl only stored the buffer, so a fresh upload from Settings was invisible until next stop event. Track currentSong in BotProfileManager for the idle check. 2. onConnect drops the !avatarEnabled guard — on a fresh connect there's no song playing yet, so the spec matrix wants the custom avatar shown regardless of sync. Previously bots reconnected with a stale TS3 server-side avatar. 3. CustomAvatarRow: defer the initializing=false flip to nextTick so the load-time data-url assignment's queued watcher sees initializing=true and bails. Removes the redundant PUT-on-mount that echoed the just- loaded bytes back to the server. 4. BotInstance avatar load wrapped in try/catch — a corrupt/locked file no longer crashes startup; we log and continue with no custom avatar. Tests rewritten: 10 cases covering the full behavior matrix (idle vs playing × sync on/off × custom set/null × stop/connect). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
0f9c7b3c4c
commit
88ff62c829
4 files changed
+130
-27
No files matched your search
+27
-2
@@ -26,6 +26,12 @@ export class BotProfileManager {
|
||||
private config: ProfileConfig;
|
||||
private defaultNickname: string;
|
||||
private customAvatar: Buffer | null = null;
|
||||
/**
|
||||
* Tracks the last song handed to onSongChange. null means stopped/idle.
|
||||
* Used by setCustomAvatar to decide whether the new buffer should be
|
||||
* pushed immediately (idle) or wait for the next stop event (playing).
|
||||
*/
|
||||
private currentSong: QueuedSong | null = null;
|
||||
|
||||
/** Per-feature permission-denied flags. Reset on reconnect. */
|
||||
private permDenied = {
|
||||
@@ -59,9 +65,24 @@ export class BotProfileManager {
|
||||
|
||||
// --- Public API ---
|
||||
|
||||
/** Set/clear the persistent idle avatar. Pass null to remove. */
|
||||
/**
|
||||
* Set/clear the persistent idle avatar. Pass null to remove.
|
||||
*
|
||||
* If the bot is currently in an idle state (no song playing OR
|
||||
* avatarEnabled is off), the new buffer is pushed to TS3 right away;
|
||||
* otherwise the cover-art sync is in charge until the next stop event,
|
||||
* at which point clearAvatar restores from this.customAvatar.
|
||||
*/
|
||||
setCustomAvatar(buffer: Buffer | null): void {
|
||||
this.customAvatar = buffer;
|
||||
const idle = this.currentSong === null || !this.config.avatarEnabled;
|
||||
if (!idle) return;
|
||||
const gen = ++this.generation;
|
||||
if (buffer && buffer.length > 0) {
|
||||
void this.applyIdleAvatar(gen);
|
||||
} else {
|
||||
void this.clearAvatar(gen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +98,7 @@ export class BotProfileManager {
|
||||
*/
|
||||
async onSongChange(song: QueuedSong | null): Promise<void> {
|
||||
const gen = ++this.generation;
|
||||
this.currentSong = song;
|
||||
|
||||
// 1. Avatar first — file transfer uses its own response tracker and
|
||||
// must run before sendCommandNoWait calls whose orphaned responses
|
||||
@@ -97,6 +119,7 @@ export class BotProfileManager {
|
||||
/** Reset permission-denied flags and bump generation on new connection. */
|
||||
onConnect(): void {
|
||||
this.generation++;
|
||||
this.currentSong = null;
|
||||
this.permDenied = {
|
||||
avatar: false,
|
||||
description: false,
|
||||
@@ -105,7 +128,9 @@ export class BotProfileManager {
|
||||
channelDesc: false,
|
||||
nowPlayingMsg: false,
|
||||
};
|
||||
if (!this.config.avatarEnabled && this.customAvatar) {
|
||||
// No song is playing on a fresh connect, so the matrix says the
|
||||
// custom avatar should be visible regardless of avatarEnabled.
|
||||
if (this.customAvatar) {
|
||||
const gen = this.generation;
|
||||
void this.applyIdleAvatar(gen);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user