mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
fix(profile): add timeout to clientedit, guard clearAvatar with generation
- Wrap clientedit (description) with 5s timeout to prevent blocking channel description and now-playing updates if the command hangs - Check generation counter in clearAvatar to avoid clearing a newer song's avatar when stop→play happens in quick succession Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b4ad78ce84
commit
e92628a6b4
1 file changed
+11
-4
+11
-4
@@ -114,7 +114,7 @@ export class BotProfileManager {
|
|||||||
if (!this.config.avatarEnabled || this.permDenied.avatar) return;
|
if (!this.config.avatarEnabled || this.permDenied.avatar) return;
|
||||||
try {
|
try {
|
||||||
if (!coverUrl) {
|
if (!coverUrl) {
|
||||||
await this.clearAvatar();
|
await this.clearAvatar(gen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Request a thumbnail from the CDN to stay within TS3's avatar size limit.
|
// Request a thumbnail from the CDN to stay within TS3's avatar size limit.
|
||||||
@@ -152,7 +152,7 @@ export class BotProfileManager {
|
|||||||
await this.tsClient.sendCommandNoWait(`clientupdate client_flag_avatar=${escapeTS3(md5)}`);
|
await this.tsClient.sendCommandNoWait(`clientupdate client_flag_avatar=${escapeTS3(md5)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async clearAvatar(): Promise<void> {
|
private async clearAvatar(gen: number): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await this.withTimeout(
|
await this.withTimeout(
|
||||||
this.tsClient.fileTransferDeleteFile(0n, ["/avatar"]),
|
this.tsClient.fileTransferDeleteFile(0n, ["/avatar"]),
|
||||||
@@ -161,6 +161,8 @@ export class BotProfileManager {
|
|||||||
} catch {
|
} catch {
|
||||||
// File may not exist or transfer timed out — that's fine
|
// File may not exist or transfer timed out — that's fine
|
||||||
}
|
}
|
||||||
|
// Bail if a newer song started while we were deleting
|
||||||
|
if (this.generation !== gen) return;
|
||||||
try {
|
try {
|
||||||
await this.tsClient.sendCommandNoWait("clientupdate client_flag_avatar=");
|
await this.tsClient.sendCommandNoWait("clientupdate client_flag_avatar=");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -183,8 +185,13 @@ export class BotProfileManager {
|
|||||||
// TS3AudioBot does via TSLib's ChangeDescription().
|
// TS3AudioBot does via TSLib's ChangeDescription().
|
||||||
const clid = this.tsClient.getClientId();
|
const clid = this.tsClient.getClientId();
|
||||||
if (clid <= 0) return;
|
if (clid <= 0) return;
|
||||||
await this.tsClient.execCommand(
|
// Use a 5s timeout — if clientedit hangs, don't block the
|
||||||
`clientedit clid=${clid} client_description=${escapeTS3(text)}`,
|
// remaining profile updates (channeledit, now-playing msg).
|
||||||
|
await this.withTimeout(
|
||||||
|
this.tsClient.execCommand(
|
||||||
|
`clientedit clid=${clid} client_description=${escapeTS3(text)}`,
|
||||||
|
),
|
||||||
|
5000,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.logger.info("Description updated");
|
this.logger.info("Description updated");
|
||||||
|
|||||||
Reference in new issue
Block a user