From dd9a1c1bcca1ae6d82afe9f2622a8ef4cd8ef8b1 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 8 Feb 2025 12:56:51 +0100 Subject: [PATCH] feat: Allow customizing `to-user-name`/`from-user-name` Example usage: `twitch-cli event trigger channel.ban --transport=websocket --to-user 11148817 --to-user-name pajlada` --- cmd/events/trigger.go | 4 ++ cmd/events/variables.go | 2 + docs/event.md | 56 ++++++++++++------------ internal/events/trigger/trigger_event.go | 14 +++++- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/cmd/events/trigger.go b/cmd/events/trigger.go index af8811d..f50fd79 100644 --- a/cmd/events/trigger.go +++ b/cmd/events/trigger.go @@ -35,7 +35,9 @@ func TriggerCommand() (command *cobra.Command) { // per-topic flags command.Flags().StringVarP(&toUser, "to-user", "t", "", "User ID of the receiver of the event. For example, the user that receives a follow. In most contexts, this is the broadcaster.") + command.Flags().StringVarP(&toUserName, "to-user-name", "", "", "User Name of the receiver of the event. For example, the user that receives a follow. In most contexts, this is the broadcaster.") command.Flags().StringVarP(&fromUser, "from-user", "f", "", "User ID of the user sending the event, for example the user following another user.") + command.Flags().StringVarP(&fromUserName, "from-user-name", "", "", "User Name of the user sending the event, for example the user following another user.") command.Flags().StringVarP(&giftUser, "gift-user", "g", "", "Used only for \"gift\" events. Denotes the User ID of the gifting user.") command.Flags().BoolVarP(&isAnonymous, "anonymous", "a", false, "Denotes if the event is anonymous. Only applies to Gift and Sub events.") command.Flags().IntVarP(&count, "count", "c", 1, "Number of times to run an event. This can be used to simulate rapid events, such as multiple sub gift, or large number of cheers.") @@ -99,7 +101,9 @@ func triggerCmdRun(cmd *cobra.Command, args []string) error { Transport: transport, ForwardAddress: forwardAddress, FromUser: fromUser, + FromUserName: fromUserName, ToUser: toUser, + ToUserName: toUserName, GiftUser: giftUser, Secret: secret, IsAnonymous: isAnonymous, diff --git a/cmd/events/variables.go b/cmd/events/variables.go index 24cb596..3eba634 100644 --- a/cmd/events/variables.go +++ b/cmd/events/variables.go @@ -8,7 +8,9 @@ var ( transport string noConfig bool fromUser string + fromUserName string toUser string + toUserName string giftUser string subscriptionID string eventMessageID string diff --git a/docs/event.md b/docs/event.md index 9a88cb1..5c13e5f 100644 --- a/docs/event.md +++ b/docs/event.md @@ -88,33 +88,35 @@ This command can take either the Event or Alias listed as an argument. It is pre **Flags** -| Flag | Shorthand | Description | Example | Required? (Y/N) | -|---------------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------| -| `--anonymous` | `-a` | Denotes if the event is anonymous. Only applies to Gift and Sub events. | `-a` | N | -| `--ban-end` | | Sets the timestamp a ban is intended to end at. If not set, the ban event will appear as permanent. | `--ban-end 10d20h12m35s` | N | -| `--ban-start` | | Sets the timestamp a ban started at. | `--ban-start 2017-04-13T14:34:23` | N | -| `--charity-current-value` | | For charity events, manually set the charity dollar value. | `--charity-current-value 11000` | N | -| `--charity-target-value` | | Only used for "charity-*" events. Manually set the target dollar value for charity events. (default 1500000) | `--charity-target-value 23400` | N | -| `--client-id` | | Manually set the Client ID used for revoke, grant, and bits transactions. | `--client-id 4ofh8m0706jqpholgk00u3xvb4spct` | N | -| `--cost` | `-C` | Amount of subscriptions, bits, or channel points redeemed/used in the event. | `-C 250` | N | -| `--count` | `-c` | Count of events to fire. This can be used to simulate an influx of events. | `-c 100` | N | -| `--description` | `-d` | Title the stream should be updated/started with. | `-d Awesome new title!` | N | -| `--event-status` | `-S` | Status of the Event object (.event.status in JSON); Currently applies to channel points redemptions. | `-S fulfilled` | N | -| `--forward-address` | `-F` | Web server address for where to send mock events. | `-F https://localhost:8080` | N | -| `--from-user` | `-f` | Denotes the sender's TUID of the event, for example the user that follows another user or the subscriber to a broadcaster. | `-f 44635596` | N | -| `--game-id` | `-G` | Game ID for Drop or other relevant events. | `-G 1234` | N | -| `--gift-user` | `-g` | Used only for subcription-based events, denotes the gifting user ID. | `-g 44635596` | N | -| `--item-id` | `-i` | Manually set the ID of the event payload item (for example the reward ID in redemption events or game in stream events). | `-i 032e4a6c-4aef-11eb-a9f5-1f703d1f0b92` | N | -| `--item-name` | `-n` | Manually set the name of the event payload item (for example the reward ID in redemption events or game name in stream events). | `-n "Science & Technology"` | N | -| `--no-config` | `-D` | Disables the use of the configuration values should they exist. | `-D` | N | -| `--secret` | `-s` | Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be 10-100 characters in length. | `-s testsecret` | N | -| `--session` | | WebSocket session to target. Only used when forwarding to WebSocket servers with --transport=websocket | `--session e411cc1e_a2613d4e` | N | -| `--subscription-id` | `-u` | Manually set the subscription/event ID of the event itself. | `-u 5d3aed06-d019-11ed-afa1-0242ac120002` | N | -| `--subscription-status` | `-r` | Status of the Subscription object (.subscription.status in JSON). Defaults to "enabled" | `-r revoked` | N | -| `--tier` | | Tier of the subscription. | `--tier 3000` | N | -| `--timestamp` | | Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format. | `--timestamp 2017-04-13T14:34:23` | N | -| `--to-user` | `-t` | Denotes the receiver's TUID of the event, usually the broadcaster. | `-t 44635596` | N | -| `--transport` | `-T` | The method used to send events. Can either be `webhook` or `websocket`. Default is `webhook`. | `-T webhook` | N | +| Flag | Shorthand | Description | Example | Required? (Y/N) | +|---------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------| +| `--anonymous` | `-a` | Denotes if the event is anonymous. Only applies to Gift and Sub events. | `-a` | N | +| `--ban-end` | | Sets the timestamp a ban is intended to end at. If not set, the ban event will appear as permanent. | `--ban-end 10d20h12m35s` | N | +| `--ban-start` | | Sets the timestamp a ban started at. | `--ban-start 2017-04-13T14:34:23` | N | +| `--charity-current-value` | | For charity events, manually set the charity dollar value. | `--charity-current-value 11000` | N | +| `--charity-target-value` | | Only used for "charity-*" events. Manually set the target dollar value for charity events. (default 1500000) | `--charity-target-value 23400` | N | +| `--client-id` | | Manually set the Client ID used for revoke, grant, and bits transactions. | `--client-id 4ofh8m0706jqpholgk00u3xvb4spct` | N | +| `--cost` | `-C` | Amount of subscriptions, bits, or channel points redeemed/used in the event. | `-C 250` | N | +| `--count` | `-c` | Count of events to fire. This can be used to simulate an influx of events. | `-c 100` | N | +| `--description` | `-d` | Title the stream should be updated/started with. | `-d Awesome new title!` | N | +| `--event-status` | `-S` | Status of the Event object (.event.status in JSON); Currently applies to channel points redemptions. | `-S fulfilled` | N | +| `--forward-address` | `-F` | Web server address for where to send mock events. | `-F https://localhost:8080` | N | +| `--from-user` | `-f` | Denotes the sender's TUID of the event, for example the user that follows another user or the subscriber to a broadcaster. | `-f 44635596` | N | +| `--from-user-name` | | Denotes the sender's Twitch Username of the event, for example the user that follows another user or the subscriber to a broadcaster. | `--from-user-name testname` | N | +| `--game-id` | `-G` | Game ID for Drop or other relevant events. | `-G 1234` | N | +| `--gift-user` | `-g` | Used only for subcription-based events, denotes the gifting user ID. | `-g 44635596` | N | +| `--item-id` | `-i` | Manually set the ID of the event payload item (for example the reward ID in redemption events or game in stream events). | `-i 032e4a6c-4aef-11eb-a9f5-1f703d1f0b92` | N | +| `--item-name` | `-n` | Manually set the name of the event payload item (for example the reward ID in redemption events or game name in stream events). | `-n "Science & Technology"` | N | +| `--no-config` | `-D` | Disables the use of the configuration values should they exist. | `-D` | N | +| `--secret` | `-s` | Webhook secret. If defined, signs all forwarded events with the SHA256 HMAC and must be 10-100 characters in length. | `-s testsecret` | N | +| `--session` | | WebSocket session to target. Only used when forwarding to WebSocket servers with --transport=websocket | `--session e411cc1e_a2613d4e` | N | +| `--subscription-id` | `-u` | Manually set the subscription/event ID of the event itself. | `-u 5d3aed06-d019-11ed-afa1-0242ac120002` | N | +| `--subscription-status` | `-r` | Status of the Subscription object (.subscription.status in JSON). Defaults to "enabled" | `-r revoked` | N | +| `--tier` | | Tier of the subscription. | `--tier 3000` | N | +| `--timestamp` | | Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format. | `--timestamp 2017-04-13T14:34:23` | N | +| `--to-user` | `-t` | Denotes the receiver's TUID of the event, usually the broadcaster. | `-t 44635596` | N | +| `--to-user-name` | | Denotes the receiver's Twitch Username of the event, usually the broadcaster. | `--to-user-name testname` | N | +| `--transport` | `-T` | The method used to send events. Can either be `webhook` or `websocket`. Default is `webhook`. | `-T webhook` | N | **Examples** diff --git a/internal/events/trigger/trigger_event.go b/internal/events/trigger/trigger_event.go index 3d3f7da..ac2a549 100644 --- a/internal/events/trigger/trigger_event.go +++ b/internal/events/trigger/trigger_event.go @@ -27,7 +27,9 @@ type TriggerParameters struct { Transport string IsAnonymous bool FromUser string + FromUserName string ToUser string + ToUserName string GiftUser string EventStatus string SubscriptionStatus string @@ -80,10 +82,18 @@ func Fire(p TriggerParameters) (string, error) { p.ToUser = util.RandomUserID() } + if p.ToUserName == "" { + p.ToUserName = "testBroadcaster" + } + if p.FromUser == "" { p.FromUser = util.RandomUserID() } + if p.FromUserName == "" { + p.FromUserName = "testFromUser" + } + if p.GameID == "" { p.GameID = fmt.Sprint(util.RandomInt(10 * 1000)) } @@ -128,9 +138,9 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event` Trigger: p.Event, Transport: p.Transport, FromUserID: p.FromUser, - FromUserName: "testFromUser", + FromUserName: p.FromUserName, ToUserID: p.ToUser, - ToUserName: "testBroadcaster", + ToUserName: p.ToUserName, IsAnonymous: p.IsAnonymous, Cost: p.Cost, EventStatus: p.EventStatus,