Skip to content

Commit

Permalink
add reply-thread-parent msg-id and user-login
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Jun 21, 2023
1 parent cecc760 commit 218db80
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
30 changes: 27 additions & 3 deletions Sources/TwitchIRC/IncomingMessage/PrivateMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,24 @@ public struct PrivateMessage: MessageWithBadges {

public init() { }
}


public struct ReplyThreadParent {
/// Replied user's name with no uppercased/Han characters.
public var userLogin = String()
/// Replied thread's message's id.
public var messageId = String()

internal init(
userLogin: String,
messageId: String
) {
self.userLogin = userLogin
self.messageId = messageId
}

public init() { }
}

public struct PinnedChat {
public var amount = UInt()
public var canonicalAmount = UInt()
Expand Down Expand Up @@ -97,6 +114,8 @@ public struct PrivateMessage: MessageWithBadges {
public var userId = String()
/// Info about the replied message, if any.
public var replyParent = ReplyParent()
/// Info about the thread of the replied message, if any.
public var replyThreadParent = ReplyThreadParent()
/// Info of paid pinned messages.
public var pinnedChat = PinnedChat()
/// Contains info about unused info and parsing problems.
Expand Down Expand Up @@ -161,6 +180,10 @@ public struct PrivateMessage: MessageWithBadges {
id: parser.string(for: "reply-parent-msg-id"),
userId: parser.string(for: "reply-parent-user-id")
)
self.replyThreadParent = .init(
userLogin: parser.string(for: "reply-thread-parent-user-login"),
messageId: parser.string(for: "reply-thread-parent-msg-id")
)
self.pinnedChat = .init(
amount: parser.uint(for: "pinned-chat-paid-amount"),
canonicalAmount: parser.uint(for: "pinned-chat-paid-canonical-amount"),
Expand All @@ -169,8 +192,8 @@ public struct PrivateMessage: MessageWithBadges {
)

let deprecatedKeys = ["turbo", "mod", "vip", "subscriber", "user-type"]
let occasionalKeys = [["crowd-chant-parent-msg-id"], ["bits"], ["emote-only"], ["msg-id"], ["custom-reward-id"], ["client-nonce"], ["flags"], ["first-msg"], ["reply-parent-display-name", "reply-parent-user-login", "reply-parent-msg-body", "reply-parent-msg-id", "reply-parent-user-id"], ["pinned-chat-paid-amount", "pinned-chat-paid-canonical-amount", "pinned-chat-paid-currency", "pinned-chat-paid-exponent"]]
let occasionalKeys = [["crowd-chant-parent-msg-id"], ["bits"], ["emote-only"], ["msg-id"], ["custom-reward-id"], ["client-nonce"], ["flags"], ["first-msg"], ["reply-parent-display-name", "reply-parent-user-login", "reply-parent-msg-body", "reply-parent-msg-id", "reply-parent-user-id"], ["pinned-chat-paid-amount", "pinned-chat-paid-canonical-amount", "pinned-chat-paid-currency", "pinned-chat-paid-exponent"], ["reply-thread-parent-user-login", "reply-thread-parent-msg-id"]]

self.parsingLeftOvers = parser.getLeftOvers(
excludedUnusedKeys: deprecatedKeys,
groupsOfExcludedUnavailableKeys: occasionalKeys
Expand All @@ -182,5 +205,6 @@ public struct PrivateMessage: MessageWithBadges {
#if swift(>=5.5)
extension PrivateMessage: Sendable { }
extension PrivateMessage.ReplyParent: Sendable { }
extension PrivateMessage.ReplyThreadParent: Sendable { }
extension PrivateMessage.PinnedChat: Sendable { }
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,39 @@ final class PrivateMessageTests: XCTestCase {
))
XCTAssertTrue(msg.parsingLeftOvers.isEmpty, "Non-empty parsing left-overs: \(msg.parsingLeftOvers)")
}

func testParsedValues9() throws {
let string = #"@badge-info=predictions/Pompeyo;badges=predictions/blue-1,premium/1;client-nonce=c5639d11fdac91cad488f52a0c0a927a;color=#FFF200;display-name=fladhi;emotes=;first-msg=0;flags=;id=c96d75f7-6fe0-41d0-bd27-80643426613c;mod=0;reply-parent-display-name=RoyaleAlchemist;reply-parent-msg-body=Clash\sRoyale\sAPI\sestá\sde\svuelta\sPogChamp\sPogChamp\s.\sSi\shubo\sun\smantenimiento\so\suna\sinterrupción\sdel\sservicio,\sya\sdebería\shaber\sterminado.\sRoyale\sAlchemist\snecesitará\sentre\s5\sy\s1 0\sminutos\spara\srecuperarse\spor\scompleto\s|\s@Pompeyo4;reply-parent-msg-id=0e772349-8bcd-42cb-9c91-1c9eece83af8;reply-parent-user-id=684111155;reply-parent-user-login=royalealchemist;reply-thread-parent-msg-id=0e772349-8bcd-42cb-9c91-1c9eece83af8;reply-thread-parent-user-login=royalealchemist;returning-chatter=0;room-id=118220323;subscriber=0;tmi-sent-ts=1687334511793;turbo=0;user-id=686358047;user-type= :[email protected] PRIVMSG #pompeyo4 :@RoyaleAlchemist whoAsked"#

let msg: PrivateMessage = try TestUtils.parseAndUnwrap(string: string)

XCTAssertEqual(msg.channel, "pompeyo4")
XCTAssertEqual(msg.message, "@RoyaleAlchemist whoAsked")
XCTAssertEqual(msg.badgeInfo, ["predictions/Pompeyo"])
XCTAssertEqual(msg.badges, ["predictions/blue-1", "premium/1"])
XCTAssertEqual(msg.bits, "")
XCTAssertEqual(msg.color, "#FFF200")
XCTAssertEqual(msg.displayName, "fladhi")
XCTAssertEqual(msg.userLogin, "fladhi")
XCTAssertEqual(msg.emotes, "")
XCTAssertEqual(msg.emoteOnly, false)
XCTAssertEqual(msg.flags, [])
XCTAssertEqual(msg.firstMessage, false)
XCTAssertEqual(msg.returningChatter, false)
XCTAssertEqual(msg.messageId, "")
XCTAssertEqual(msg.id, "c96d75f7-6fe0-41d0-bd27-80643426613c")
XCTAssertEqual(msg.crowdChantParentMessageId, "")
XCTAssertEqual(msg.customRewardId, "")
XCTAssertEqual(msg.roomId, "118220323")
XCTAssertEqual(msg.tmiSentTs, 1687334511793)
XCTAssertEqual(msg.clientNonce, "c5639d11fdac91cad488f52a0c0a927a")
XCTAssertEqual(msg.userId, "686358047")
XCTAssertTrue(msg.replyParent == .init(displayName: "RoyaleAlchemist", userLogin: "royalealchemist", message: "Clash\\sRoyale\\sAPI\\sestá\\sde\\svuelta\\sPogChamp\\sPogChamp\\s.\\sSi\\shubo\\sun\\smantenimiento\\so\\suna\\sinterrupción\\sdel\\sservicio,\\sya\\sdebería\\shaber\\sterminado.\\sRoyale\\sAlchemist\\snecesitará\\sentre\\s5\\sy\\s1 0\\sminutos\\spara\\srecuperarse\\spor\\scompleto\\s|\\s@Pompeyo4", id: "0e772349-8bcd-42cb-9c91-1c9eece83af8", userId: "684111155")
)
XCTAssertTrue(msg.replyThreadParent == .init(userLogin: "royalealchemist", messageId: "0e772349-8bcd-42cb-9c91-1c9eece83af8"))
XCTAssertTrue(msg.pinnedChat == .init())
XCTAssertTrue(msg.parsingLeftOvers.isEmpty, "Non-empty parsing left-overs: \(msg.parsingLeftOvers)")
}
}

// MARK: - Emote Equatable
Expand All @@ -302,6 +335,15 @@ private func == (lhs: PrivateMessage.ReplyParent, rhs: PrivateMessage.ReplyParen
&& lhs.userId == rhs.userId
}

// MARK: - PrivateMessage.ReplyThreadParent Equatable (basically)
private func == (
lhs: PrivateMessage.ReplyThreadParent,
rhs: PrivateMessage.ReplyThreadParent
) -> Bool {
lhs.userLogin == rhs.userLogin
&& lhs.messageId == rhs.messageId
}

// MARK: - PrivateMessage.PinnedChat Equatable (basically)
private func == (lhs: PrivateMessage.PinnedChat, rhs: PrivateMessage.PinnedChat) -> Bool {
lhs.amount == rhs.amount
Expand Down

0 comments on commit 218db80

Please sign in to comment.