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

feat: Allow customizing to-user-name/from-user-name #346

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/events/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions cmd/events/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var (
transport string
noConfig bool
fromUser string
fromUserName string
toUser string
toUserName string
giftUser string
subscriptionID string
eventMessageID string
Expand Down
56 changes: 29 additions & 27 deletions docs/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
14 changes: 12 additions & 2 deletions internal/events/trigger/trigger_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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,
Expand Down