From e52e0a15e2c5c9fcdc908c39c7ca0c75a93cb9fe Mon Sep 17 00:00:00 2001 From: LosFarmosCTL <80157503+LosFarmosCTL@users.noreply.github.com> Date: Mon, 22 Jan 2024 07:26:31 +0100 Subject: [PATCH] fix: clean up channel names before sending them over IRC --- Sources/Twitch/Chat/ChatClient.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/Twitch/Chat/ChatClient.swift b/Sources/Twitch/Chat/ChatClient.swift index 3055de9..b47f944 100644 --- a/Sources/Twitch/Chat/ChatClient.swift +++ b/Sources/Twitch/Chat/ChatClient.swift @@ -23,18 +23,23 @@ public class ChatClient { nonce: String? = nil ) async throws { try await client.send( - message, in: channel, replyingTo: messageId, nonce: nonce) + message, in: cleanChannelName(channel), replyingTo: messageId, + nonce: nonce) } public func join(to channel: String) async throws { - try await client.join(to: channel) + try await client.join(to: cleanChannelName(channel)) } public func joinAll(channels: String...) async throws { - for channel in channels { try await join(to: channel) } + for channel in channels { try await join(to: cleanChannelName(channel)) } } public func part(from channel: String) async throws { - try await client.part(from: channel) + try await client.part(from: cleanChannelName(channel)) + } + + private func cleanChannelName(_ channel: String) -> String { + return channel.lowercased().trimmingCharacters(in: ["#", " "]) } }