Skip to content

Commit dc37a04

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 dc37a04

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
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

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)