MahdiBM / TwitchIRC

A dependancy-free Swift package for parsing and serializing Twitch IRC messages
MIT License
14 stars 3 forks source link

Message types in `switch` not working #2

Closed markhaehnel closed 1 year ago

markhaehnel commented 1 year ago

Hi @MahdiBM, first of all, thank you for the work on that library!

For some reason i cannot resolve the message type in a switch statement like in the examples.

This is my code:

print(rawString)

let twitchMessages: [(message: IncomingMessage?, text: String)] = IncomingMessage.parse(ircOutput: rawString)

for (message, _) in twitchMessages {
  if let message = message {

    print(message)

    switch message {
    case .privateMessage(let privateMessage):
      print("In channel \(privateMessage.channel), user \(privateMessage.displayName) sent a message: \(privateMessage.message)")
    default: break
    }
  }
}

It does not go into the case let .privateMessage(privateMessage): and always falls through to the default.

The print statements i've added print the following output to the console:

// print(rawString)
@badge-info=subscriber/22;badges=subscriber/18;client-nonce=a2d200e925041b5e800bf32c47039ed7;color=#D2691E;display-name=MNT7_Matze;emotes=306934184:79-88;first-msg=0;flags=;id=42e74668-a2a0-4f26-85b6-a2c00563b926;mod=0;returning-chatter=0;room-id=73437396;subscriber=1;tmi-sent-ts=1670779577985;turbo=0;user-id=24647541;user-type= :mnt7_matze!mnt7_matze@mnt7_matze.tmi.twitch.tv PRIVMSG #bonjwa :@Omphis weiß nicht ob die StarCraft-Ehre das zulassen würde extra zu verlieren bonjwaCute
// print(message)
privateMessage(TwitchIRC.PrivateMessage(channel: "bonjwa", message: "@Omphis weiß nicht ob die StarCraft-Ehre das zulassen würde extra zu verlieren bonjwaCute", badgeInfo: ["subscriber/22"], badges: ["subscriber/18"], bits: "", color: "#D2691E", displayName: "MNT7_Matze", userLogin: "mnt7_matze", emotes: "306934184:79-88", emoteOnly: false, flags: [], firstMessage: false, returningChatter: false, messageId: "", id: "42e74668-a2a0-4f26-85b6-a2c00563b926", crowdChantParentMessageId: "", customRewardId: "", roomId: "73437396", tmiSentTs: 1670779577985, clientNonce: "a2d200e925041b5e800bf32c47039ed7", userId: "24647541", replyParent: TwitchIRC.PrivateMessage.ReplyParent(displayName: "", userLogin: "", message: "", id: "", userId: ""), pinnedChat: TwitchIRC.PrivateMessage.PinnedChat(amount: 0, canonicalAmount: 0, currency: "", exponent: 0), parsingLeftOvers: TwitchIRC.ParsingLeftOvers(unusedPairs: [], unavailableKeys: [], unparsedKeys: [])))

So it looks like it has the proper type but why doesn't it work?

Additional info:

Lib Version: v1.0.7
Platform: iOS 16 / tvOS 16
Swift: 5.7
XCode: 14.1

If you need additional info just hit me up here and i will follow your request.

markhaehnel commented 1 year ago

Oh my gosh. Forgive me for the stupidity of creating this issue here. One should clear the filter in the console. 🙈 Everything is working fine and as expected... Again, this library saved me hours of work, thank you!