From fe1e009392b61205a84934381fad8db76171e28e Mon Sep 17 00:00:00 2001 From: jaydenfyi <213395523+jaydenfyi@users.noreply.github.com> Date: Sun, 25 Jan 2026 23:30:37 +0800 Subject: [PATCH] remove whisper functionality --- extensions/twitch/src/plugin.ts | 2 +- extensions/twitch/src/twitch-client.test.ts | 38 +-------------------- extensions/twitch/src/twitch-client.ts | 27 --------------- extensions/twitch/src/types.ts | 2 +- 4 files changed, 3 insertions(+), 66 deletions(-) diff --git a/extensions/twitch/src/plugin.ts b/extensions/twitch/src/plugin.ts index b741f9d57..2064722b0 100644 --- a/extensions/twitch/src/plugin.ts +++ b/extensions/twitch/src/plugin.ts @@ -66,7 +66,7 @@ export const twitchPlugin: ChannelPlugin = { /** Supported chat capabilities */ capabilities: { - chatTypes: ["group", "direct"], + chatTypes: ["group"], } satisfies ChannelCapabilities, /** Configuration schema for Twitch channel */ diff --git a/extensions/twitch/src/twitch-client.test.ts b/extensions/twitch/src/twitch-client.test.ts index 43bf712ac..b6e270acd 100644 --- a/extensions/twitch/src/twitch-client.test.ts +++ b/extensions/twitch/src/twitch-client.test.ts @@ -3,7 +3,7 @@ * * Tests cover: * - Client connection and reconnection - * - Message handling (chat and whispers) + * - Message handling (chat) * - Message sending with rate limiting * - Disconnection scenarios * - Error handling and edge cases @@ -23,7 +23,6 @@ const mockUnbind = vi.fn(); // Event handler storage for testing const messageHandlers: Array<(channel: string, user: string, message: string, msg: any) => void> = []; -const whisperHandlers: Array<(user: string, message: string, msg: any) => void> = []; // Mock functions that track handlers and return unbind objects const mockOnMessage = vi.fn((handler: any) => { @@ -31,11 +30,6 @@ const mockOnMessage = vi.fn((handler: any) => { return { unbind: mockUnbind }; }); -const mockOnWhisper = vi.fn((handler: any) => { - whisperHandlers.push(handler); - return { unbind: mockUnbind }; -}); - const mockAddUserForToken = vi.fn().mockResolvedValue("123456"); const mockOnRefresh = vi.fn(); const mockOnRefreshFailure = vi.fn(); @@ -43,7 +37,6 @@ const mockOnRefreshFailure = vi.fn(); vi.mock("@twurple/chat", () => ({ ChatClient: class { onMessage = mockOnMessage; - onWhisper = mockOnWhisper; connect = mockConnect; join = mockJoin; say = mockSay; @@ -111,7 +104,6 @@ describe("TwitchClientManager", () => { // Clear handler arrays messageHandlers.length = 0; - whisperHandlers.length = 0; // Re-set up the default token mock implementation after clearing const { resolveTwitchToken } = await import("./token.js"); @@ -240,7 +232,6 @@ describe("TwitchClientManager", () => { await manager.getClient(testAccount); expect(mockOnMessage).toHaveBeenCalled(); - expect(mockOnWhisper).toHaveBeenCalled(); expect(mockLogger.info).toHaveBeenCalledWith(expect.stringContaining("Set up handlers for")); }); @@ -450,33 +441,6 @@ describe("TwitchClientManager", () => { expect(capturedMessage?.chatType).toBe("group"); }); - it("should handle whispers (DMs)", async () => { - await manager.getClient(testAccount); - - // Get the onWhisper callback - const onWhisperCallback = whisperHandlers[0]; - if (!onWhisperCallback) throw new Error("onWhisperCallback not found"); - - // Simulate Twitch whisper - onWhisperCallback("whisperuser", "Secret message", { - userInfo: { - userName: "whisperuser", - displayName: "WhisperUser", - userId: "67890", - isMod: true, - isBroadcaster: false, - isVip: false, - isSubscriber: true, - }, - }); - - expect(capturedMessage).not.toBeNull(); - expect(capturedMessage?.username).toBe("whisperuser"); - expect(capturedMessage?.message).toBe("Secret message"); - expect(capturedMessage?.chatType).toBe("direct"); - expect(capturedMessage?.id).toBeUndefined(); - }); - it("should normalize channel names without # prefix", async () => { await manager.getClient(testAccount); diff --git a/extensions/twitch/src/twitch-client.ts b/extensions/twitch/src/twitch-client.ts index 0e2815121..f76435aa4 100644 --- a/extensions/twitch/src/twitch-client.ts +++ b/extensions/twitch/src/twitch-client.ts @@ -186,33 +186,6 @@ export class TwitchClientManager { } }); - // Handle whispers (DMs) - client.onWhisper((_user, messageText, msg) => { - const handler = this.messageHandlers.get(key); - if (handler) { - const from = `twitch:${msg.userInfo.userName}`; - const preview = messageText.slice(0, 100).replace(/\n/g, "\\n"); - this.logger.debug?.( - `twitch inbound: whisper from=${from} len=${messageText.length} preview="${preview}"`, - ); - - handler({ - username: msg.userInfo.userName, - displayName: msg.userInfo.displayName, - userId: msg.userInfo.userId, - message: messageText, - channel: msg.userInfo.userName, - id: undefined, // Whisper doesn't have id property - timestamp: new Date(), - isMod: msg.userInfo.isMod, - isOwner: msg.userInfo.isBroadcaster, - isVip: msg.userInfo.isVip, - isSub: msg.userInfo.isSubscriber, - chatType: "direct", - }); - } - }); - this.logger.info(`Set up handlers for ${key}`); } diff --git a/extensions/twitch/src/types.ts b/extensions/twitch/src/types.ts index 99d9e9af1..74b2b4acf 100644 --- a/extensions/twitch/src/types.ts +++ b/extensions/twitch/src/types.ts @@ -102,7 +102,7 @@ export interface TwitchChatMessage { /** Whether the sender is a subscriber */ isSub?: boolean; /** Chat type */ - chatType?: "direct" | "group"; + chatType?: "group"; } /**