mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 20:01:17 +00:00
[eventsub] Add shoutout_created
event
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
4c7697261b
commit
f066b3fd2a
5 changed files with 56 additions and 1 deletions
|
@ -32,6 +32,7 @@ var (
|
|||
eventTypePermit = ptrStr("permit")
|
||||
eventTypeRaid = ptrStr("raid")
|
||||
eventTypeResub = ptrStr("resub")
|
||||
eventTypeShoutoutCreated = ptrStr("shoutout_created")
|
||||
eventTypeShoutoutReceived = ptrStr("shoutout_received")
|
||||
eventTypeSubgift = ptrStr("subgift")
|
||||
eventTypeSubmysterygift = ptrStr("submysterygift")
|
||||
|
|
|
@ -46,6 +46,7 @@ const (
|
|||
EventSubEventTypeChannelFollow = "channel.follow"
|
||||
EventSubEventTypeChannelPointCustomRewardRedemptionAdd = "channel.channel_points_custom_reward_redemption.add"
|
||||
EventSubEventTypeChannelRaid = "channel.raid"
|
||||
EventSubEventTypeChannelShoutoutCreate = "channel.shoutout.create"
|
||||
EventSubEventTypeChannelShoutoutReceive = "channel.shoutout.receive"
|
||||
EventSubEventTypeChannelUpdate = "channel.update"
|
||||
EventSubEventTypeStreamOffline = "stream.offline"
|
||||
|
@ -133,6 +134,22 @@ type (
|
|||
Viewers int64 `json:"viewers"`
|
||||
}
|
||||
|
||||
EventSubEventShoutoutCreated struct {
|
||||
BroadcasterUserID string `json:"broadcaster_user_id"`
|
||||
BroadcasterUserLogin string `json:"broadcaster_user_login"`
|
||||
BroadcasterUserName string `json:"broadcaster_user_name"`
|
||||
ModeratorUserID string `json:"moderator_user_id"`
|
||||
ModeratorUserLogin string `json:"moderator_user_login"`
|
||||
ModeratorUserName string `json:"moderator_user_name"`
|
||||
ToBroadcasterUserID string `json:"to_broadcaster_user_id"`
|
||||
ToBroadcasterUserLogin string `json:"to_broadcaster_user_login"`
|
||||
ToBroadcasterUserName string `json:"to_broadcaster_user_name"`
|
||||
ViewerCount int64 `json:"viewer_count"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
CooldownEndsAt time.Time `json:"cooldown_ends_at"`
|
||||
TargetCooldownEndsAt time.Time `json:"target_cooldown_ends_at"`
|
||||
}
|
||||
|
||||
EventSubEventShoutoutReceived struct {
|
||||
BroadcasterUserID string `json:"broadcaster_user_id"`
|
||||
BroadcasterUserLogin string `json:"broadcaster_user_login"`
|
||||
|
|
|
@ -12,7 +12,7 @@ var (
|
|||
twitch.ScopeChannelManageVIPS: "manage VIPs",
|
||||
twitch.ScopeChannelReadRedemptions: "see channel-point redemptions",
|
||||
twitch.ScopeModeratorReadFollowers: "see who follows this channel",
|
||||
twitch.ScopeModeratorReadShoutouts: "see shoutouts received",
|
||||
twitch.ScopeModeratorReadShoutouts: "see shoutouts created / received",
|
||||
}
|
||||
|
||||
botDefaultScopes = []string{
|
||||
|
|
|
@ -143,6 +143,13 @@ func (t *twitchWatcher) getTopicRegistrations(userID string) []topicRegistration
|
|||
AnyScope: true,
|
||||
Hook: t.handleEventSubChannelPointCustomRewardRedemptionAdd,
|
||||
},
|
||||
{
|
||||
Topic: twitch.EventSubEventTypeChannelShoutoutCreate,
|
||||
Condition: twitch.EventSubCondition{BroadcasterUserID: userID, ModeratorUserID: userID},
|
||||
RequiredScopes: []string{twitch.ScopeModeratorManageShoutouts, twitch.ScopeModeratorReadShoutouts},
|
||||
AnyScope: true,
|
||||
Hook: t.handleEventSubShoutoutCreated,
|
||||
},
|
||||
{
|
||||
Topic: twitch.EventSubEventTypeChannelShoutoutReceive,
|
||||
Condition: twitch.EventSubCondition{BroadcasterUserID: userID, ModeratorUserID: userID},
|
||||
|
@ -225,6 +232,25 @@ func (t *twitchWatcher) handleEventSubChannelUpdate(m json.RawMessage) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *twitchWatcher) handleEventSubShoutoutCreated(m json.RawMessage) error {
|
||||
var payload twitch.EventSubEventShoutoutCreated
|
||||
if err := json.Unmarshal(m, &payload); err != nil {
|
||||
return errors.Wrap(err, "unmarshalling event")
|
||||
}
|
||||
|
||||
fields := plugins.FieldCollectionFromData(map[string]any{
|
||||
"channel": "#" + payload.BroadcasterUserLogin,
|
||||
"to_id": payload.ToBroadcasterUserID,
|
||||
"to": payload.ToBroadcasterUserLogin,
|
||||
"viewers": payload.ViewerCount,
|
||||
})
|
||||
|
||||
log.WithFields(log.Fields(fields.Data())).Info("Shoutout created")
|
||||
go handleMessage(ircHdl.Client(), nil, eventTypeShoutoutCreated, fields)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *twitchWatcher) handleEventSubShoutoutReceived(m json.RawMessage) error {
|
||||
var payload twitch.EventSubEventShoutoutReceived
|
||||
if err := json.Unmarshal(m, &payload); err != nil {
|
||||
|
|
|
@ -149,6 +149,17 @@ Fields:
|
|||
- `subscribed_months` - How long have they been subscribed
|
||||
- `username` - The login-name of the user who resubscribed
|
||||
|
||||
## `shoutout_created`
|
||||
|
||||
The channel gave another streamer a (Twitch native) shoutout
|
||||
|
||||
Fields:
|
||||
|
||||
- `channel` - The channel the event occurred in
|
||||
- `to_id` - The ID of the channel who received the shoutout
|
||||
- `to` - The login-name of the channel who received the shoutout
|
||||
- `viewers` - The amount of viewers the shoutout was shown to
|
||||
|
||||
## `shoutout_received`
|
||||
|
||||
The channel received a (Twitch native) shoutout by another channel.
|
||||
|
|
Loading…
Reference in a new issue