Skip to content

Commit

Permalink
fix(parsing): SubMysteryGift missing tag during SUBtember
Browse files Browse the repository at this point in the history
- Tag `msg-param-sender-count` is missing during (some?) promotions
- Only seen with sender twitch, therefore handled as an edge case
- If sent by twitch and the tag is missing, then assume u64::MAX
  • Loading branch information
Larandar committed Sep 29, 2024
1 parent c0e2409 commit 4c7e507
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Version numbers follow [Semantic Versioning](https://semver.org/).
applies to the `client_secret` in `RefreshingLoginCredentials`. (#199)
- Minor: Added example demonstrating usage of `metrics-collection` feature as well as an exemplary grafana
dashboard template. (#203, #208)
- Minor: Fixed missing tag durring SUBtember (#215)

## v5.0.1

Expand Down
41 changes: 40 additions & 1 deletion src/message/commands/usernotice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,14 @@ impl TryFrom<IRCMessage> for UserNoticeMessage {
// this takes over all other cases of submysterygift.
"submysterygift" => UserNoticeEvent::SubMysteryGift {
mass_gift_count: source.try_get_number("msg-param-mass-gift-count")?,
sender_total_gifts: source.try_get_number("msg-param-sender-count")?,
sender_total_gifts: if sender.login != "twitch" {
source.try_get_number("msg-param-sender-count")?
} else {
// - this seems to be missing if sender the sender is twitch (user-id=12826) on subtembers
source
.try_get_number("msg-param-sender-count")
.unwrap_or(std::u64::MAX) // unlimited gifts
},
sub_plan: source
.try_get_nonempty_tag_value("msg-param-sub-plan")?
.to_owned(),
Expand Down Expand Up @@ -781,6 +788,38 @@ mod tests {
)
}

#[test]
pub fn test_submysterygift_twitch() {
let src = "@badge-info=;badges=sub-gifter/50;color=;display-name=twitch;emotes=;flags=;id=049e6371-7023-4fca-8605-7dec60e72e12;login=twitch;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=20;msg-param-sender-count=50;msg-param-origin-id=1f\\sbe\\sbb\\s4a\\s81\\s9a\\s65\\sd1\\s4b\\s77\\sf5\\s23\\s16\\s4a\\sd3\\s13\\s09\\se7\\sbe\\s55;msg-param-sub-plan=1000;room-id=71092938;subscriber=0;system-msg=AdamAtReflectStudios\\sis\\sgifting\\s20\\sTier\\s1\\sSubs\\sto\\sxQcOW's\\scommunity!\\sThey've\\sgifted\\sa\\stotal\\sof\\s100\\sin\\sthe\\schannel!;tmi-sent-ts=1594583777669;user-id=12826;user-type= :tmi.twitch.tv USERNOTICE #xqcow";
let irc_message = IRCMessage::parse(src).unwrap();
let msg = UserNoticeMessage::try_from(irc_message).unwrap();

assert_eq!(
msg.event,
UserNoticeEvent::SubMysteryGift {
mass_gift_count: 20,
sender_total_gifts: 50,
sub_plan: "1000".to_owned(),
}
)
}

#[test]
pub fn test_submysterygift_twitch_missing_count() {
let src = "@badge-info=;badges=sub-gifter/50;color=;display-name=twitch;emotes=;flags=;id=049e6371-7023-4fca-8605-7dec60e72e12;login=twitch;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=20;msg-param-origin-id=1f\\sbe\\sbb\\s4a\\s81\\s9a\\s65\\sd1\\s4b\\s77\\sf5\\s23\\s16\\s4a\\sd3\\s13\\s09\\se7\\sbe\\s55;msg-param-sub-plan=1000;room-id=71092938;subscriber=0;system-msg=AdamAtReflectStudios\\sis\\sgifting\\s20\\sTier\\s1\\sSubs\\sto\\sxQcOW's\\scommunity!\\sThey've\\sgifted\\sa\\stotal\\sof\\s100\\sin\\sthe\\schannel!;tmi-sent-ts=1594583777669;user-id=12826;user-type= :tmi.twitch.tv USERNOTICE #xqcow";
let irc_message = IRCMessage::parse(src).unwrap();
let msg = UserNoticeMessage::try_from(irc_message).unwrap();

assert_eq!(
msg.event,
UserNoticeEvent::SubMysteryGift {
mass_gift_count: 20,
sender_total_gifts: std::u64::MAX,
sub_plan: "1000".to_owned(),
}
)
}

#[test]
pub fn test_submysterygift_ananonymousgifter() {
let src = "@badge-info=;badges=;color=;display-name=AnAnonymousGifter;emotes=;flags=;id=8db97752-3dee-460b-9001-e925d0e2ba5b;login=ananonymousgifter;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=10;msg-param-origin-id=13\\s33\\sed\\sc0\\sef\\sa0\\s7b\\s9b\\s48\\s59\\scb\\scc\\se4\\s39\\s7b\\s90\\sf9\\s54\\s75\\s66;msg-param-sub-plan=1000;room-id=71092938;subscriber=0;system-msg=An\\sanonymous\\suser\\sis\\sgifting\\s10\\sTier\\s1\\sSubs\\sto\\sxQcOW's\\scommunity!;tmi-sent-ts=1585447099603;user-id=274598607;user-type= :tmi.twitch.tv USERNOTICE #xqcow";
Expand Down

0 comments on commit 4c7e507

Please sign in to comment.