remove whisper functionality
This commit is contained in:
parent
4413896a47
commit
fe1e009392
@ -66,7 +66,7 @@ export const twitchPlugin: ChannelPlugin<TwitchAccountConfig> = {
|
||||
|
||||
/** Supported chat capabilities */
|
||||
capabilities: {
|
||||
chatTypes: ["group", "direct"],
|
||||
chatTypes: ["group"],
|
||||
} satisfies ChannelCapabilities,
|
||||
|
||||
/** Configuration schema for Twitch channel */
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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}`);
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ export interface TwitchChatMessage {
|
||||
/** Whether the sender is a subscriber */
|
||||
isSub?: boolean;
|
||||
/** Chat type */
|
||||
chatType?: "direct" | "group";
|
||||
chatType?: "group";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user