twitch-cli icon indicating copy to clipboard operation
twitch-cli copied to clipboard

[Bug] Simulated websocket event `channel.subscription.message`: wrong emote indexes?

Open Felk opened this issue 1 year ago • 1 comments

What is the problem?

The emote indexes in the mocked message of type channel.subscription.message v1 seems to be wrong. It provides the message Hello from the Twitch CLI! twitchdevLeek with the emote indexes Begin: 26 and End: 39.
Those indexes give you twitchdevLee instead of twitchdevLeek

See the code: https://github.com/twitchdev/twitch-cli/blame/v1.1.24/internal/events/types/subscription_message/subscription_message.go#L66

Because the commit introducing this code is labelled "updating eventsub to match production" (3f42430a1965c702b694a4b061ad2cc76d45becc), I'm wondering if this is just an error in the CLI, or whether there's actually an off-by-one on Twitch. I don't have any production subscription message on hand to compare.

Operating System

Windows 10

Architecture Version (x86, x64, arm, etc)

x64

Steps to reproduce

triggering

PS C:\Users\felk> twitch event trigger channel.subscription.message --transport=websocket
✔ Forwarded for use in mock EventSub WebSocket server

gives you (prettified):

{
  "subscription": {
    "id": "2bd37600-24c5-742a-4c18-5d93fe6c111f",
    "status": "enabled",
    "type": "channel.subscription.message",
    "version": "1",
    "condition": {
      "broadcaster_user_id": "94257613"
    },
    "transport": {
      "method": "websocket",
      "session_id": "WebSocket-Server-Will-Set"
    },
    "created_at": "2024-10-15T17:28:31.7523926Z",
    "cost": 0
  },
  "event": {
    "broadcaster_user_id": "94257613",
    "broadcaster_user_login": "testBroadcaster",
    "broadcaster_user_name": "testBroadcaster",
    "cumulative_months": 41,
    "duration_months": 1,
    "message": {
      "emotes": [
        {
          "begin": 26,
          "end": 39,
          "id": "304456816"
        }
      ],
      "text": "Hello from the Twitch CLI! twitchdevLeek"
    },
    "streak_months": 41,
    "tier": "1000",
    "user_id": "83967978",
    "user_login": "testFromUser",
    "user_name": "testFromUser"
  }
}

Relevant log output

No response

Felk avatar Oct 15 '24 17:10 Felk

I do now have actual production data from a real channel.subscription.message event:

{
  ...
  "payload": {
    ...
    "event": {
      ...
      "message": {
        "text": "test Kappa 🌿 BabyRage 🐍 PogChamp 🎅🏿 RaccAttack ♥ PraiseIt 12345678901234567890",
        "emotes": [
          {"begin": 5, "end": 9, "id": "25"},
          {"begin": 16, "end": 23, "id": "22639"},
          {"begin": 30, "end": 37, "id": "305954156"},
          {"begin": 48, "end": 57, "id": "114870"},
          {"begin": 63, "end": 70, "id": "38586"}
        ]
      },
      ...
    }
  }
}

So in reality the indices are:

  • left-inclusive
  • right-inclusive
  • counted in utf-8 bytes I suppose (not characters at least)

In that sense, the CLI example should range from 27-39, not 26-39. Right now the indices indicate that the emote is twitchdevLeek (1 leading space).

Felk avatar Jan 03 '25 00:01 Felk