pyTwitchAPI icon indicating copy to clipboard operation
pyTwitchAPI copied to clipboard

Add message filter for shared chat from other rooms

Open Latent-Logic opened this issue 1 year ago • 3 comments

Twitch is rolling out shared chat rooms between streamers, and it can result in a bot responding to commands or messages from other chatrooms. This adds an optional (default on) filter for messages to only pay attention to the message if has a source-room-id that matches the current room-id. I'm still investigating to see if this needs to be one level higher in the stack to also handle chat events like RAID and SUB

Latent-Logic avatar Oct 15 '24 01:10 Latent-Logic

Looks good so far, I am gonna wait with the merge till your investigation is done

Teekeks avatar Oct 15 '24 01:10 Teekeks

yes most USERNOTICEs are also shared: sub, resub, subgift, submysterygift, giftpaidupgrade, primepaidupgrade, pay forward gifts, raid, announcement

iProdigy avatar Oct 15 '24 02:10 iProdigy

Yeah, I was thinking that was the case, unfortunately I didn't have any subs/raids in the shared-chat stream my bot was working in yesterday to verify in debug logs. I'll move the logic up one level to just before the handler logic: https://github.com/Teekeks/pyTwitchAPI/blob/bcfd8d1/twitchAPI/chat/init.py#L936

Separately your list of USERNOTICE highlighted something else I saw while looking over wider debug logs, in that the ChatEvent.SUB only happens with parsed['tags'].get('msg-id') in ('sub', 'resub', 'subgift') not communitypayforward/giftpaidupgrade/primepaidupgrade/standardpayforward/submysterygift. ~~I'll open a separate ticket for that~~ Investigated and doesn't need an issue https://github.com/Teekeks/pyTwitchAPI/blob/bcfd8d1/twitchAPI/chat/init.py#L1037

(( To close the loop, double checked the USERNOTICE I was concerned about and they don't matter for ChatEvent.SUB

  • communitypayforward This is always immediately followed by a separate message about a msg-id=submysterygift (and then another message msg-id=subgift) so we don't need to handle this as a ChatEvent.SUB separately
  • giftpaidupgrade / primepaidupgrade This is not immediately surrounded by any other consistent message types, but also IIRC this is a promise to pay, not an immediate sub event, as the subscription will start when the gift subscription ends.
  • standardpayforward This is always immediately followed with a separate message about a msg-id=subgift so we don't need to handle this as a ChatEvent.SUB separately
  • submysterygift This is always followed by a subgift message (or multiple) so doesn't need to be it's own message

))

Latent-Logic avatar Oct 15 '24 02:10 Latent-Logic

ok, so it isn't needed for subscription notices, because they have msg-id=sharedchatnotice and a source-msg-id=subgift, so anything looking at a parsed['tags'].get('msg-id') in ('sub', 'resub', 'subgift') won't trigger a ChatEvent.SUB

twitchAPI.chat < @badge-info=subscriber/8;badges=moderator/1,subscriber/6,gold-pixel-heart/1;color=#008000;display-name=<redact>;emotes=;flags=;id=<redact>;login=<redact>;mod=1;msg-id=sharedchatnotice;msg-param-community-gift-id=<redact>;msg-param-gift-months=1;msg-param-months=1;msg-param-origin-id=<redact>;msg-param-recipient-display-name=<redact>;msg-param-recipient-id=<redact>;msg-param-recipient-user-name=<redact>;msg-param-sender-count=<redact>;msg-param-sub-plan-name=Channel\sSubscription\s(<redact>);msg-param-sub-plan=1000;room-id=<redact>;source-badge-info=;source-badges=sub-gift-leader/1;source-id=<redact>;source-msg-id=subgift;source-room-id=<redact>;subscriber=1;system-msg=<redact>\sgifted\sa\sTier\s1\ssub\sto\s<redact>!;tmi-sent-ts=<redact>;user-id=<redact>;user-type=mod;vip=0 :tmi.twitch.tv USERNOTICE #<redact>

I'll remove the commit that moves where the filter lives as I think given we have msg-id=sharedchatnotice we only need the filer on ChatEvent.MESSAGE/Commands

Latent-Logic avatar Oct 24 '24 04:10 Latent-Logic