mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-12-02 19:02:50 +08:00
Merge remote-tracking branch 'origin/main' into review/185-hardening
# Conflicts: # src/music/netease.ts
This commit is contained in:
commit
ea05787cb7
25 files changed
+1592
-34
No files matched your search
@@ -29,6 +29,10 @@ function makeBot() {
|
||||
player.getVolume = () => 50;
|
||||
player.pause = AudioPlayer.prototype.pause;
|
||||
player.resume = AudioPlayer.prototype.resume;
|
||||
// The real pause()/resume() drive the de-click transport ramp
|
||||
// (a0f0b49..6f165b5). A stub player must expose it too, or the prototype
|
||||
// methods throw "setTransportRamp is not a function".
|
||||
player.setTransportRamp = vi.fn();
|
||||
player.play = vi.fn((_url: string, position: number) => { player.sessionId++; player.elapsed = position; player.state = "playing"; });
|
||||
player.stop = vi.fn(() => { player.sessionId++; player.state = "idle"; });
|
||||
const provider = { getSongUrl: vi.fn(async (): Promise<{ url: string } | null> => ({ url: "fresh" })) };
|
||||
|
||||
@@ -1544,6 +1544,36 @@ describe("BotInstance live-queue persistence (#119)", () => {
|
||||
});
|
||||
|
||||
describe("BotInstance Bilibili multi-P resolution", () => {
|
||||
it("passes the page from a TeamSpeak video link to the Bilibili provider", async () => {
|
||||
const song = {
|
||||
id: "BV1yxHQeYEuE?p=2",
|
||||
name: "Video - P2",
|
||||
artist: "Uploader",
|
||||
album: "",
|
||||
duration: 180,
|
||||
coverUrl: "",
|
||||
platform: "bilibili" as const,
|
||||
};
|
||||
const provider = { platform: "bilibili", getSongDetail: vi.fn().mockResolvedValue(song) };
|
||||
const ctx = {
|
||||
config: { commandPrefix: "!" },
|
||||
assertProviderEnabled: vi.fn(),
|
||||
getProviderFor: vi.fn().mockReturnValue(provider),
|
||||
};
|
||||
const args = "[URL]https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2[/URL]";
|
||||
|
||||
const result = await (BotInstance.prototype as any).resolvePlayQuery.call(ctx, {
|
||||
name: "play",
|
||||
args,
|
||||
rawArgs: [args],
|
||||
flags: new Set(),
|
||||
});
|
||||
|
||||
expect(ctx.getProviderFor).toHaveBeenCalledWith("bilibili");
|
||||
expect(provider.getSongDetail).toHaveBeenCalledWith("BV1yxHQeYEuE?p=2");
|
||||
expect(result.song).toEqual(song);
|
||||
});
|
||||
|
||||
it("resolves multi-P search result to P1 with accurate duration and name", async () => {
|
||||
const multiPSongDetail = {
|
||||
id: "BV1multiP?p=1",
|
||||
@@ -1780,6 +1810,10 @@ describe("BotInstance trackEnd — stale playback sessions", () => {
|
||||
player.getPlaybackSessionId = AudioPlayer.prototype.getPlaybackSessionId;
|
||||
player.pause = AudioPlayer.prototype.pause;
|
||||
player.resume = AudioPlayer.prototype.resume;
|
||||
// The real pause()/resume() drive the de-click transport ramp
|
||||
// (a0f0b49..6f165b5). A stub player must expose it too, or the prototype
|
||||
// methods throw "setTransportRamp is not a function".
|
||||
player.setTransportRamp = vi.fn();
|
||||
player.play = vi.fn(() => { player.sessionId++; player.state = "playing"; });
|
||||
const provider = { getSongUrl: vi.fn(async () => ({ url: "fresh" })) };
|
||||
const advances: string[] = [];
|
||||
|
||||
@@ -101,6 +101,34 @@ describe("parseSongRef (#90 exact-song selection)", () => {
|
||||
expect(parseSongRef("https://www.bilibili.com/video/BV1yxHQeYEuE")).toEqual({ id: "BV1yxHQeYEuE", platform: "bilibili" });
|
||||
expect(parseSongRef("https://b23.tv/BV1yxHQeYEuE")).toEqual({ id: "BV1yxHQeYEuE", platform: "bilibili" });
|
||||
});
|
||||
|
||||
it.each([
|
||||
"https://www.bilibili.com/video/BV1yxHQeYEuE?p=2",
|
||||
"https://b23.tv/BV1yxHQeYEuE?p=2",
|
||||
"https://www.bilibili.com/video/BV1yxHQeYEuE/?from=share&p=2&vd_source=test#reply",
|
||||
"https://www.bilibili.com/video/BV1yxHQeYEuE/?from=share?p=3&p=2",
|
||||
"https://www.bilibili.com/video/BV1yxHQeYEuE/?p=%32",
|
||||
"[URL]https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2[/URL]",
|
||||
"[url]https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2#reply[/url]",
|
||||
"[URL=https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2]点击播放[/URL]",
|
||||
"参考 https://example.com/?p=9 视频 https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2 请播放",
|
||||
])("preserves the Bilibili page query in %s", (input) => {
|
||||
expect(parseSongRef(input)).toEqual({ id: "BV1yxHQeYEuE?p=2", platform: "bilibili" });
|
||||
});
|
||||
|
||||
it.each([
|
||||
"?p=2extra",
|
||||
"?p=-2",
|
||||
"?page=2",
|
||||
"?sp=2",
|
||||
"?from=share?p=2",
|
||||
"?from=share%3Fp%3D2",
|
||||
"?from=share#reply&p=2",
|
||||
"#reply?p=2",
|
||||
])("ignores an invalid or unrelated Bilibili page query %s", (query) => {
|
||||
expect(parseSongRef(`https://www.bilibili.com/video/BV1yxHQeYEuE${query}`))
|
||||
.toEqual({ id: "BV1yxHQeYEuE", platform: "bilibili" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseSelectionIndex (#90 pick from last search)", () => {
|
||||
|
||||
+5
-1
@@ -69,7 +69,11 @@ export function parseSongRef(raw: string): SongRef | null {
|
||||
// a "BV..." token never collides with them).
|
||||
const bv = /BV[0-9A-Za-z]{8,12}/.exec(q);
|
||||
if (bv && (/^BV[0-9A-Za-z]{8,12}$/.test(q) || /bilibili\.com|b23\.tv/i.test(q))) {
|
||||
return { id: bv[0], platform: "bilibili" };
|
||||
// Extract the query attached to this BV id, including in [URL=...] tags.
|
||||
const suffix = q.slice(bv.index + bv[0].length);
|
||||
const query = /^\/?\?([^#\s[\]]*)/.exec(suffix)?.[1];
|
||||
const page = new URLSearchParams(query).get("p");
|
||||
return { id: page && /^\d+$/.test(page) ? `${bv[0]}?p=${page}` : bv[0], platform: "bilibili" };
|
||||
}
|
||||
|
||||
// NetEase song URL. Only treat `id=N` as a SONG id when the URL is not a
|
||||
|
||||
@@ -65,9 +65,17 @@ describe("BotInstance persistent voice send failure", () => {
|
||||
expect(frames).toBe(50);
|
||||
h.tsClient.emit("voiceSendFailed", { consecutiveFailures: 100, durationMs: 2000 });
|
||||
vi.advanceTimersByTime(3000);
|
||||
expect(frames).toBe(50);
|
||||
expect(h.player.getElapsed()).toBe(1);
|
||||
// Pausing emits a short de-click fade tail (pauseFrames) so the last
|
||||
// audible frames ramp down instead of cutting off (a0f0b49). What this
|
||||
// test guards is what happens AFTER that: the scheduler must go quiet
|
||||
// and elapsed must stop advancing.
|
||||
expect(h.player.getState()).toBe("paused");
|
||||
const framesAfterFade = frames;
|
||||
const elapsedAfterFade = h.player.getElapsed();
|
||||
expect(framesAfterFade).toBeLessThan(50 + 20);
|
||||
vi.advanceTimersByTime(3000);
|
||||
expect(frames).toBe(framesAfterFade);
|
||||
expect(h.player.getElapsed()).toBe(elapsedAfterFade);
|
||||
} finally { h.player.stop(); }
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user