mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
fix(qq-fm): guard FM start when offline + reset radar page on re-login [#88 review]
- startFm() now refuses with 'Bot is not connected to TeamSpeak' before mutating the queue, so POST /api/player/:id/fm can no longer wipe the queue and flip the bot into FM mode while disconnected (the !fm chat command already had this guard). - The /fm route's success detection also treats 'not connected' as a failure so the toast type is correct. - QQMusicProvider.setCookie() resets radarPage to 1 so a re-login with a different account no longer inherits the previous account's radar pagination cursor.
This commit is contained in:
1 parent
9bfe831022
commit
6e10764d28
3 files changed
+16
-1
No files matched your search
@@ -747,6 +747,12 @@ export class BotInstance extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async startFm(provider: MusicProvider = this.neteaseProvider): Promise<string> {
|
async startFm(provider: MusicProvider = this.neteaseProvider): Promise<string> {
|
||||||
|
// Match the !fm chat-command guard: refuse before mutating the queue when
|
||||||
|
// offline, so the web /fm route can't wipe the queue + flip into FM mode
|
||||||
|
// while nothing can actually play.
|
||||||
|
if (!this.connected) {
|
||||||
|
return "Bot is not connected to TeamSpeak";
|
||||||
|
}
|
||||||
if (!provider.getPersonalFm) {
|
if (!provider.getPersonalFm) {
|
||||||
return `Personal FM is not available for ${provider.platform}`;
|
return `Personal FM is not available for ${provider.platform}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -462,6 +462,9 @@ export class QQMusicProvider implements MusicProvider {
|
|||||||
|
|
||||||
setCookie(cookie: string): void {
|
setCookie(cookie: string): void {
|
||||||
this.cookie = cookie;
|
this.cookie = cookie;
|
||||||
|
// Reset radar pagination so a re-login (different account) starts from the
|
||||||
|
// first page rather than inheriting the previous account's cursor.
|
||||||
|
this.radarPage = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCookie(): string {
|
getCookie(): string {
|
||||||
|
|||||||
@@ -97,7 +97,13 @@ export function createPlayerRouter(
|
|||||||
: "netease"
|
: "netease"
|
||||||
);
|
);
|
||||||
const message = await bot.startFm(provider);
|
const message = await bot.startFm(provider);
|
||||||
res.json({ ok: !message.startsWith("No FM songs") && !message.includes("not available"), message });
|
res.json({
|
||||||
|
ok:
|
||||||
|
!message.startsWith("No FM songs") &&
|
||||||
|
!message.includes("not available") &&
|
||||||
|
!message.includes("not connected"),
|
||||||
|
message,
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(500).json({ error: (err as Error).message });
|
res.status(500).json({ error: (err as Error).message });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user