Skip to content

Commit dd9a1c1

Browse files
committed
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`
1 parent a367bec commit dd9a1c1

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

cmd/events/trigger.go

+4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func TriggerCommand() (command *cobra.Command) {
3535

3636
// per-topic flags
3737
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.")
38+
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.")
3839
command.Flags().StringVarP(&fromUser, "from-user", "f", "", "User ID of the user sending the event, for example the user following another user.")
40+
command.Flags().StringVarP(&fromUserName, "from-user-name", "", "", "User Name of the user sending the event, for example the user following another user.")
3941
command.Flags().StringVarP(&giftUser, "gift-user", "g", "", "Used only for \"gift\" events. Denotes the User ID of the gifting user.")
4042
command.Flags().BoolVarP(&isAnonymous, "anonymous", "a", false, "Denotes if the event is anonymous. Only applies to Gift and Sub events.")
4143
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 {
99101
Transport: transport,
100102
ForwardAddress: forwardAddress,
101103
FromUser: fromUser,
104+
FromUserName: fromUserName,
102105
ToUser: toUser,
106+
ToUserName: toUserName,
103107
GiftUser: giftUser,
104108
Secret: secret,
105109
IsAnonymous: isAnonymous,

cmd/events/variables.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ var (
88
transport string
99
noConfig bool
1010
fromUser string
11+
fromUserName string
1112
toUser string
13+
toUserName string
1214
giftUser string
1315
subscriptionID string
1416
eventMessageID string

docs/event.md

+29-27
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,35 @@ This command can take either the Event or Alias listed as an argument. It is pre
8888

8989
**Flags**
9090

91-
| Flag | Shorthand | Description | Example | Required? (Y/N) |
92-
|---------------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------|
93-
| `--anonymous` | `-a` | Denotes if the event is anonymous. Only applies to Gift and Sub events. | `-a` | N |
94-
| `--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 |
95-
| `--ban-start` | | Sets the timestamp a ban started at. | `--ban-start 2017-04-13T14:34:23` | N |
96-
| `--charity-current-value` | | For charity events, manually set the charity dollar value. | `--charity-current-value 11000` | N |
97-
| `--charity-target-value` | | Only used for "charity-*" events. Manually set the target dollar value for charity events. (default 1500000) | `--charity-target-value 23400` | N |
98-
| `--client-id` | | Manually set the Client ID used for revoke, grant, and bits transactions. | `--client-id 4ofh8m0706jqpholgk00u3xvb4spct` | N |
99-
| `--cost` | `-C` | Amount of subscriptions, bits, or channel points redeemed/used in the event. | `-C 250` | N |
100-
| `--count` | `-c` | Count of events to fire. This can be used to simulate an influx of events. | `-c 100` | N |
101-
| `--description` | `-d` | Title the stream should be updated/started with. | `-d Awesome new title!` | N |
102-
| `--event-status` | `-S` | Status of the Event object (.event.status in JSON); Currently applies to channel points redemptions. | `-S fulfilled` | N |
103-
| `--forward-address` | `-F` | Web server address for where to send mock events. | `-F https://localhost:8080` | N |
104-
| `--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 |
105-
| `--game-id` | `-G` | Game ID for Drop or other relevant events. | `-G 1234` | N |
106-
| `--gift-user` | `-g` | Used only for subcription-based events, denotes the gifting user ID. | `-g 44635596` | N |
107-
| `--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 |
108-
| `--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 |
109-
| `--no-config` | `-D` | Disables the use of the configuration values should they exist. | `-D` | N |
110-
| `--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 |
111-
| `--session` | | WebSocket session to target. Only used when forwarding to WebSocket servers with --transport=websocket | `--session e411cc1e_a2613d4e` | N |
112-
| `--subscription-id` | `-u` | Manually set the subscription/event ID of the event itself. | `-u 5d3aed06-d019-11ed-afa1-0242ac120002` | N |
113-
| `--subscription-status` | `-r` | Status of the Subscription object (.subscription.status in JSON). Defaults to "enabled" | `-r revoked` | N |
114-
| `--tier` | | Tier of the subscription. | `--tier 3000` | N |
115-
| `--timestamp` | | Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format. | `--timestamp 2017-04-13T14:34:23` | N |
116-
| `--to-user` | `-t` | Denotes the receiver's TUID of the event, usually the broadcaster. | `-t 44635596` | N |
117-
| `--transport` | `-T` | The method used to send events. Can either be `webhook` or `websocket`. Default is `webhook`. | `-T webhook` | N |
91+
| Flag | Shorthand | Description | Example | Required? (Y/N) |
92+
|---------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------|
93+
| `--anonymous` | `-a` | Denotes if the event is anonymous. Only applies to Gift and Sub events. | `-a` | N |
94+
| `--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 |
95+
| `--ban-start` | | Sets the timestamp a ban started at. | `--ban-start 2017-04-13T14:34:23` | N |
96+
| `--charity-current-value` | | For charity events, manually set the charity dollar value. | `--charity-current-value 11000` | N |
97+
| `--charity-target-value` | | Only used for "charity-*" events. Manually set the target dollar value for charity events. (default 1500000) | `--charity-target-value 23400` | N |
98+
| `--client-id` | | Manually set the Client ID used for revoke, grant, and bits transactions. | `--client-id 4ofh8m0706jqpholgk00u3xvb4spct` | N |
99+
| `--cost` | `-C` | Amount of subscriptions, bits, or channel points redeemed/used in the event. | `-C 250` | N |
100+
| `--count` | `-c` | Count of events to fire. This can be used to simulate an influx of events. | `-c 100` | N |
101+
| `--description` | `-d` | Title the stream should be updated/started with. | `-d Awesome new title!` | N |
102+
| `--event-status` | `-S` | Status of the Event object (.event.status in JSON); Currently applies to channel points redemptions. | `-S fulfilled` | N |
103+
| `--forward-address` | `-F` | Web server address for where to send mock events. | `-F https://localhost:8080` | N |
104+
| `--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 |
105+
| `--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 |
106+
| `--game-id` | `-G` | Game ID for Drop or other relevant events. | `-G 1234` | N |
107+
| `--gift-user` | `-g` | Used only for subcription-based events, denotes the gifting user ID. | `-g 44635596` | N |
108+
| `--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 |
109+
| `--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 |
110+
| `--no-config` | `-D` | Disables the use of the configuration values should they exist. | `-D` | N |
111+
| `--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 |
112+
| `--session` | | WebSocket session to target. Only used when forwarding to WebSocket servers with --transport=websocket | `--session e411cc1e_a2613d4e` | N |
113+
| `--subscription-id` | `-u` | Manually set the subscription/event ID of the event itself. | `-u 5d3aed06-d019-11ed-afa1-0242ac120002` | N |
114+
| `--subscription-status` | `-r` | Status of the Subscription object (.subscription.status in JSON). Defaults to "enabled" | `-r revoked` | N |
115+
| `--tier` | | Tier of the subscription. | `--tier 3000` | N |
116+
| `--timestamp` | | Sets the timestamp to be used in payloads and headers. Must be in RFC3339Nano format. | `--timestamp 2017-04-13T14:34:23` | N |
117+
| `--to-user` | `-t` | Denotes the receiver's TUID of the event, usually the broadcaster. | `-t 44635596` | N |
118+
| `--to-user-name` | | Denotes the receiver's Twitch Username of the event, usually the broadcaster. | `--to-user-name testname` | N |
119+
| `--transport` | `-T` | The method used to send events. Can either be `webhook` or `websocket`. Default is `webhook`. | `-T webhook` | N |
118120

119121
**Examples**
120122

internal/events/trigger/trigger_event.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ type TriggerParameters struct {
2727
Transport string
2828
IsAnonymous bool
2929
FromUser string
30+
FromUserName string
3031
ToUser string
32+
ToUserName string
3133
GiftUser string
3234
EventStatus string
3335
SubscriptionStatus string
@@ -80,10 +82,18 @@ func Fire(p TriggerParameters) (string, error) {
8082
p.ToUser = util.RandomUserID()
8183
}
8284

85+
if p.ToUserName == "" {
86+
p.ToUserName = "testBroadcaster"
87+
}
88+
8389
if p.FromUser == "" {
8490
p.FromUser = util.RandomUserID()
8591
}
8692

93+
if p.FromUserName == "" {
94+
p.FromUserName = "testFromUser"
95+
}
96+
8797
if p.GameID == "" {
8898
p.GameID = fmt.Sprint(util.RandomInt(10 * 1000))
8999
}
@@ -128,9 +138,9 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
128138
Trigger: p.Event,
129139
Transport: p.Transport,
130140
FromUserID: p.FromUser,
131-
FromUserName: "testFromUser",
141+
FromUserName: p.FromUserName,
132142
ToUserID: p.ToUser,
133-
ToUserName: "testBroadcaster",
143+
ToUserName: p.ToUserName,
134144
IsAnonymous: p.IsAnonymous,
135145
Cost: p.Cost,
136146
EventStatus: p.EventStatus,

0 commit comments

Comments
 (0)