Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message filter for shared chat from other rooms #334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Latent-Logic
Copy link
Contributor

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

@Teekeks
Copy link
Owner

Teekeks commented Oct 15, 2024

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

@iProdigy
Copy link
Contributor

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

@Latent-Logic
Copy link
Contributor Author

Latent-Logic commented Oct 15, 2024

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants