feat: prevent recording of audio from bot users
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const speaking = new EventEmitter();
|
||||
const subscribe = vi.fn();
|
||||
@@ -13,6 +13,21 @@ const joinVoiceChannel = vi.fn(() => ({
|
||||
destroy: vi.fn(),
|
||||
}));
|
||||
|
||||
function createChannel() {
|
||||
return {
|
||||
id: "voice-channel",
|
||||
name: "Voice",
|
||||
guild: {
|
||||
id: "guild",
|
||||
voiceAdapterCreator: {},
|
||||
members: {
|
||||
cache: new Map(),
|
||||
fetch: vi.fn(async () => null),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
vi.mock("@discordjs/voice", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("@discordjs/voice")>(
|
||||
@@ -26,19 +41,17 @@ vi.mock("@discordjs/voice", async () => {
|
||||
});
|
||||
|
||||
describe("startRecording", () => {
|
||||
beforeEach(() => {
|
||||
subscribe.mockClear();
|
||||
speaking.removeAllListeners();
|
||||
});
|
||||
|
||||
it("does not subscribe to the bot user's own audio", async () => {
|
||||
const { startRecording } = await import("../src/recorder");
|
||||
const client = {
|
||||
user: { id: "bot-user" },
|
||||
};
|
||||
const channel = {
|
||||
id: "voice-channel",
|
||||
name: "Voice",
|
||||
guild: {
|
||||
id: "guild",
|
||||
voiceAdapterCreator: {},
|
||||
},
|
||||
};
|
||||
const channel = createChannel();
|
||||
|
||||
await startRecording(client as never, channel as never);
|
||||
speaking.emit("start", "bot-user");
|
||||
@@ -46,4 +59,32 @@ describe("startRecording", () => {
|
||||
|
||||
expect(subscribe).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not subscribe to other bot users", async () => {
|
||||
const { startRecording } = await import("../src/recorder");
|
||||
const client = {
|
||||
user: { id: "self-user" },
|
||||
users: {
|
||||
cache: new Map([
|
||||
[
|
||||
"music-bot",
|
||||
{
|
||||
id: "music-bot",
|
||||
username: "Jockie Music",
|
||||
tag: "Jockie Music#8158",
|
||||
bot: true,
|
||||
displayAvatarURL: vi.fn(() => "https://example.com/avatar.png"),
|
||||
},
|
||||
],
|
||||
]),
|
||||
fetch: vi.fn(async () => null),
|
||||
},
|
||||
};
|
||||
|
||||
await startRecording(client as never, createChannel() as never);
|
||||
speaking.emit("start", "music-bot");
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
expect(subscribe).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user