Skip to content

Commit

Permalink
add communityGiftId to SubGift in UserNotices
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Nov 9, 2023
1 parent 8980f3d commit 036f703
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ let package = Package(
products: [
.library(
name: "TwitchIRC",
targets: ["TwitchIRC"]),
targets: ["TwitchIRC"]
),
],
targets: [
.target(name: "TwitchIRC"),
.testTarget(
name: "TwitchIRCTests",
dependencies: ["TwitchIRC"]),
dependencies: ["TwitchIRC"]
),
]
)
20 changes: 13 additions & 7 deletions Sources/TwitchIRC/IncomingMessage/UserNotice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ public struct UserNotice: MessageWithBadges {
public var goalDescription: String
public var goalTargetContributions: String
public var goalUserContributions: String

public var communityGiftId: String

internal init(
months: UInt,
recipientDisplayName: String,
Expand All @@ -186,7 +187,8 @@ public struct UserNotice: MessageWithBadges {
goalCurrentContributions: String,
goalDescription: String,
goalTargetContributions: String,
goalUserContributions: String
goalUserContributions: String,
communityGiftId: String
) {
self.months = months
self.recipientDisplayName = recipientDisplayName
Expand All @@ -204,6 +206,7 @@ public struct UserNotice: MessageWithBadges {
self.goalDescription = goalDescription
self.goalTargetContributions = goalTargetContributions
self.goalUserContributions = goalUserContributions
self.communityGiftId = communityGiftId
}

public init() {
Expand All @@ -223,7 +226,8 @@ public struct UserNotice: MessageWithBadges {
goalCurrentContributions: String(),
goalDescription: String(),
goalTargetContributions: String(),
goalUserContributions: String()
goalUserContributions: String(),
communityGiftId: String()
)
}
}
Expand Down Expand Up @@ -662,9 +666,10 @@ public struct UserNotice: MessageWithBadges {
goalCurrentContributions: parser.string(for: "msg-param-goal-current-contributions"),
goalDescription: parser.string(for: "msg-param-goal-description"),
goalTargetContributions: parser.string(for: "msg-param-goal-target-contributions"),
goalUserContributions: parser.string(for: "msg-param-goal-user-contributions")
goalUserContributions: parser.string(for: "msg-param-goal-user-contributions"),
communityGiftId: parser.string(for: "msg-param-community-gift-id")
))
occasionalSubDependentKeyGroups = [["msg-param-sender-count"], ["msg-param-goal-description"], ["msg-param-gift-theme"], ["msg-param-fun-string"], ["msg-param-gift-months", "msg-param-origin-id"], ["msg-param-goal-contribution-type", "msg-param-goal-current-contributions", "msg-param-goal-description", "msg-param-goal-target-contributions", "msg-param-goal-user-contributions"]]
occasionalSubDependentKeyGroups = [["msg-param-sender-count"], ["msg-param-goal-description"], ["msg-param-gift-theme"], ["msg-param-fun-string"], ["msg-param-gift-months", "msg-param-origin-id"], ["msg-param-goal-contribution-type", "msg-param-goal-current-contributions", "msg-param-goal-description", "msg-param-goal-target-contributions", "msg-param-goal-user-contributions"], ["msg-param-community-gift-id"]]
case "anonsubgift":
self.messageId = .anonSubGift(.init(
months: parser.uint(for: "msg-param-months"),
Expand All @@ -682,9 +687,10 @@ public struct UserNotice: MessageWithBadges {
goalCurrentContributions: parser.string(for: "msg-param-goal-current-contributions"),
goalDescription: parser.string(for: "msg-param-goal-description"),
goalTargetContributions: parser.string(for: "msg-param-goal-target-contributions"),
goalUserContributions: parser.string(for: "msg-param-goal-user-contributions")
goalUserContributions: parser.string(for: "msg-param-goal-user-contributions"),
communityGiftId: parser.string(for: "msg-param-community-gift-id")
))
occasionalSubDependentKeyGroups = [["msg-param-sender-count"], ["msg-param-fun-string"], ["msg-param-gift-theme"], ["msg-param-gift-months", "msg-param-origin-id"], ["msg-param-goal-contribution-type", "msg-param-goal-current-contributions", "msg-param-goal-description", "msg-param-goal-target-contributions", "msg-param-goal-user-contributions"]]
occasionalSubDependentKeyGroups = [["msg-param-sender-count"], ["msg-param-fun-string"], ["msg-param-gift-theme"], ["msg-param-gift-months", "msg-param-origin-id"], ["msg-param-goal-contribution-type", "msg-param-goal-current-contributions", "msg-param-goal-description", "msg-param-goal-target-contributions", "msg-param-goal-user-contributions"], ["msg-param-community-gift-id"]]
case "submysterygift":
self.messageId = .subMysteryGift(.init(
massGiftCount: parser.uint(for: "msg-param-mass-gift-count"),
Expand Down
45 changes: 45 additions & 0 deletions Tests/TwitchIRCTests/IncomingMessageTests/UserNoticeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,51 @@ final class UserNoticeTests: XCTestCase {
XCTAssertEqual(info.id, "f05b2393-3bee-451c-bcb2-d12ea06781d7")
XCTAssertEqual(info.value, 3)
}

func testParsedValues15() throws {
let string = #"@badge-info=subscriber/5;badges=subscriber/3,sub-gifter/10;color=;display-name=EABare;emotes=;flags=;id=aadbe3eb-7d44-46d9-a596-d2d45dbe5f68;login=eabare;mod=0;msg-id=subgift;msg-param-community-gift-id=b9\\s31\\s3e\\s61\\s1f\\s74\\sa1\\s59\\scc\\sa1\\sb7\\s96\\sbb\\sdb\\s8c\\s10\\sd9\\s90\\s68\\sea;msg-param-gift-months=1;msg-param-months=9;msg-param-origin-id=b9\\s31\\s3e\\s61\\s1f\\s74\\sa1\\s59\\scc\\sa1\\sb7\\s96\\sbb\\sdb\\s8c\\s10\\sd9\\s90\\s68\\sea;msg-param-recipient-display-name=josefernandezxc;msg-param-recipient-id=497056606;msg-param-recipient-user-name=josefernandezxc;msg-param-sender-count=0;msg-param-sub-plan-name=Channel\\sSubscription\\s(zsheli);msg-param-sub-plan=1000;room-id=54443609;subscriber=1;system-msg=EABare\\sgifted\\sa\\sTier\\s1\\ssub\\sto\\sjosefernandezxc!;tmi-sent-ts=1699496601758;user-id=816456923;user-type=;vip=0 :tmi.twitch.tv USERNOTICE #shellive"#

let un: UserNotice = try TestUtils.parseAndUnwrap(string: string)

XCTAssertEqual(un.channel, "shellive")
XCTAssertEqual(un.message, "")
XCTAssertEqual(un.badgeInfo, ["subscriber/5"])
XCTAssertEqual(un.badges, ["subscriber/3", "sub-gifter/10"])
XCTAssertEqual(un.color, "")
XCTAssertEqual(un.displayName, "EABare")
XCTAssertEqual(un.emotes, "")
XCTAssertEqual(un.flags, [])
XCTAssertEqual(un.id, "aadbe3eb-7d44-46d9-a596-d2d45dbe5f68")
XCTAssertEqual(un.userLogin, "eabare")
XCTAssertEqual(un.roomId, "54443609")
XCTAssertEqual(
un.systemMessage,
#"EABare\\sgifted\\sa\\sTier\\s1\\ssub\\sto\\sjosefernandezxc!"#
)
XCTAssertEqual(un.tmiSentTs, 1699496601758)
XCTAssertEqual(un.userId, "816456923")
XCTAssertTrue(un.parsingLeftOvers.isEmpty, "Non-empty parsing left-overs: \(un.parsingLeftOvers)")

let info: Action.SubGiftInfo = try unwrapInnerValue(action: un.messageId)

XCTAssertEqual(info.months, 9)
XCTAssertEqual(info.recipientDisplayName, "josefernandezxc")
XCTAssertEqual(info.recipientId, "497056606")
XCTAssertEqual(info.recipientUserName, "josefernandezxc")
XCTAssertEqual(info.subPlan, .tier1)
XCTAssertEqual(info.subPlanName, #"Channel\\sSubscription\\s(zsheli)"#)
XCTAssertEqual(info.giftMonths, 1)
XCTAssertEqual(info.originId, #"b9\\s31\\s3e\\s61\\s1f\\s74\\sa1\\s59\\scc\\sa1\\sb7\\s96\\sbb\\sdb\\s8c\\s10\\sd9\\s90\\s68\\sea"#)
XCTAssertEqual(info.senderCount, 0)
XCTAssertEqual(info.funString, "")
XCTAssertEqual(info.giftTheme, "")
XCTAssertEqual(info.goalContributionType, "")
XCTAssertEqual(info.goalCurrentContributions, "")
XCTAssertEqual(info.goalDescription, "")
XCTAssertEqual(info.goalTargetContributions, "")
XCTAssertEqual(info.goalUserContributions, "")
XCTAssertEqual(info.communityGiftId, #"b9\\s31\\s3e\\s61\\s1f\\s74\\sa1\\s59\\scc\\sa1\\sb7\\s96\\sbb\\sdb\\s8c\\s10\\sd9\\s90\\s68\\sea"#)
}
}

// MARK: - UserNotice.MessageID anyValue
Expand Down

0 comments on commit 036f703

Please sign in to comment.