mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-11 01:12:49 +08:00
fix(profile): move the now-playing channel description with the bot (#159)
When the bot was moved to another channel, the channel it left kept the now-playing description forever: updateChannelDescription always targeted getChannelId(), which by then already reported the new channel. Remember which channel we last wrote to. On a self clientMoved event, clear that channel and, if a song is playing, write the description to the new one. Stop now clears the channel we actually wrote to, so a missed move event can't leave a stale description behind either. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8ff51ea6e0
commit
faf6ac09ec
3 files changed
+115
-6
No files matched your search
@@ -202,3 +202,65 @@ describe("BotProfileManager loadCustomAvatar (pre-connect load, #148)", () => {
|
||||
expect(ts.uploadCalls[0].equals(Buffer.from([2, 2]))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("BotProfileManager channel description follows the bot (#159)", () => {
|
||||
const cfgChannelDesc = { ...cfgOff, channelDescEnabled: true };
|
||||
let ts: ReturnType<typeof makeMockTs> & { cid: bigint };
|
||||
let channelEdits: () => string[];
|
||||
|
||||
beforeEach(() => {
|
||||
ts = makeMockTs() as any;
|
||||
ts.cid = 5n;
|
||||
(ts as any).getChannelId = () => ts.cid;
|
||||
channelEdits = () =>
|
||||
(ts.sendCommandNoWait as any).mock.calls
|
||||
.map((c: any[]) => c[0] as string)
|
||||
.filter((cmd: string) => cmd.startsWith("channeledit"));
|
||||
});
|
||||
|
||||
it("clears the old channel and fills the new one when moved while playing", async () => {
|
||||
const pm = new BotProfileManager(ts as any, noopLogger, cfgChannelDesc, "Bot");
|
||||
await pm.onSongChange(fakeSong);
|
||||
expect(channelEdits()).toEqual([
|
||||
expect.stringMatching(/^channeledit cid=5 channel_description=\S+/),
|
||||
]);
|
||||
|
||||
ts.cid = 9n;
|
||||
await pm.onChannelMoved(9n);
|
||||
|
||||
const edits = channelEdits();
|
||||
expect(edits[1]).toBe("channeledit cid=5 channel_description=");
|
||||
expect(edits[2]).toMatch(/^channeledit cid=9 channel_description=\S+/);
|
||||
});
|
||||
|
||||
it("stopping after a move clears the channel the bot is in now, not the old one", async () => {
|
||||
const pm = new BotProfileManager(ts as any, noopLogger, cfgChannelDesc, "Bot");
|
||||
await pm.onSongChange(fakeSong);
|
||||
ts.cid = 9n;
|
||||
await pm.onChannelMoved(9n);
|
||||
await pm.onSongChange(null);
|
||||
expect(channelEdits().at(-1)).toBe("channeledit cid=9 channel_description=");
|
||||
});
|
||||
|
||||
it("a move while idle touches no channel description", async () => {
|
||||
const pm = new BotProfileManager(ts as any, noopLogger, cfgChannelDesc, "Bot");
|
||||
ts.cid = 9n;
|
||||
await pm.onChannelMoved(9n);
|
||||
expect(channelEdits()).toEqual([]);
|
||||
});
|
||||
|
||||
it("a move is ignored when the channel description feature is off", async () => {
|
||||
const pm = new BotProfileManager(ts as any, noopLogger, cfgOff, "Bot");
|
||||
await pm.onSongChange(fakeSong);
|
||||
ts.cid = 9n;
|
||||
await pm.onChannelMoved(9n);
|
||||
expect(channelEdits()).toEqual([]);
|
||||
});
|
||||
|
||||
it("an event for the channel the description is already in is a no-op", async () => {
|
||||
const pm = new BotProfileManager(ts as any, noopLogger, cfgChannelDesc, "Bot");
|
||||
await pm.onSongChange(fakeSong);
|
||||
await pm.onChannelMoved(5n);
|
||||
expect(channelEdits()).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user