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

Add new channel subscription types #9

Merged
merged 7 commits into from
Oct 17, 2024
Merged
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
56 changes: 56 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ type Client struct {
onEventChannelUnban func(event EventChannelUnban)
onEventChannelModeratorAdd func(event EventChannelModeratorAdd)
onEventChannelModeratorRemove func(event EventChannelModeratorRemove)
onEventChannelVIPAdd func(event EventChannelVIPAdd)
onEventChannelVIPRemove func(event EventChannelVIPRemove)
onEventChannelChannelPointsCustomRewardAdd func(event EventChannelChannelPointsCustomRewardAdd)
onEventChannelChannelPointsCustomRewardUpdate func(event EventChannelChannelPointsCustomRewardUpdate)
onEventChannelChannelPointsCustomRewardRemove func(event EventChannelChannelPointsCustomRewardRemove)
onEventChannelChannelPointsCustomRewardRedemptionAdd func(event EventChannelChannelPointsCustomRewardRedemptionAdd)
onEventChannelChannelPointsCustomRewardRedemptionUpdate func(event EventChannelChannelPointsCustomRewardRedemptionUpdate)
onEventChannelChannelPointsAutomaticRewardRedemptionAdd func(event EventChannelChannelPointsAutomaticRewardRedemptionAdd)
onEventChannelPollBegin func(event EventChannelPollBegin)
onEventChannelPollProgress func(event EventChannelPollProgress)
onEventChannelPollEnd func(event EventChannelPollEnd)
Expand Down Expand Up @@ -121,6 +124,11 @@ type Client struct {
onEventChannelSharedChatUpdate func(event EventChannelSharedChatUpdate)
onEventChannelSharedChatEnd func(event EventChannelSharedChatEnd)
onEventUserWhisperMessage func(event EventUserWhisperMessage)
onEventChannelAdBreakBegin func(event EventChannelAdBreakBegin)
onEventChannelWarningAcknowledge func(event EventChannelWarningAcknowledge)
onEventChannelWarningSend func(event EventChannelWarningSend)
onEventChannelUnbanRequestCreate func(event EventChannelUnbanRequestCreate)
onEventChannelUnbanRequestResolve func(event EventChannelUnbanRequestResolve)
}

func NewClient() *Client {
Expand Down Expand Up @@ -322,6 +330,10 @@ func (c *Client) handleNotification(message NotificationMessage) error {
callFunc(c.onEventChannelModeratorAdd, *event)
case *EventChannelModeratorRemove:
callFunc(c.onEventChannelModeratorRemove, *event)
case *EventChannelVIPAdd:
callFunc(c.onEventChannelVIPAdd, *event)
case *EventChannelVIPRemove:
callFunc(c.onEventChannelVIPRemove, *event)
case *EventChannelChannelPointsCustomRewardAdd:
callFunc(c.onEventChannelChannelPointsCustomRewardAdd, *event)
case *EventChannelChannelPointsCustomRewardUpdate:
Expand All @@ -332,6 +344,8 @@ func (c *Client) handleNotification(message NotificationMessage) error {
callFunc(c.onEventChannelChannelPointsCustomRewardRedemptionAdd, *event)
case *EventChannelChannelPointsCustomRewardRedemptionUpdate:
callFunc(c.onEventChannelChannelPointsCustomRewardRedemptionUpdate, *event)
case *EventChannelChannelPointsAutomaticRewardRedemptionAdd:
callFunc(c.onEventChannelChannelPointsAutomaticRewardRedemptionAdd, *event)
case *EventChannelPollBegin:
callFunc(c.onEventChannelPollBegin, *event)
case *EventChannelPollProgress:
Expand Down Expand Up @@ -426,6 +440,16 @@ func (c *Client) handleNotification(message NotificationMessage) error {
callFunc(c.onEventChannelSharedChatEnd, *event)
case *EventUserWhisperMessage:
callFunc(c.onEventUserWhisperMessage, *event)
case *EventChannelAdBreakBegin:
callFunc(c.onEventChannelAdBreakBegin, *event)
case *EventChannelWarningAcknowledge:
callFunc(c.onEventChannelWarningAcknowledge, *event)
case *EventChannelWarningSend:
callFunc(c.onEventChannelWarningSend, *event)
case *EventChannelUnbanRequestCreate:
callFunc(c.onEventChannelUnbanRequestCreate, *event)
case *EventChannelUnbanRequestResolve:
callFunc(c.onEventChannelUnbanRequestResolve, *event)
default:
c.onError(fmt.Errorf("unknown event type %s", subscription.Type))
}
Expand Down Expand Up @@ -531,6 +555,14 @@ func (c *Client) OnEventChannelModeratorRemove(callback func(event EventChannelM
c.onEventChannelModeratorRemove = callback
}

func (c *Client) OnEventChannelVIPAdd(callback func(event EventChannelVIPAdd)) {
c.onEventChannelVIPAdd = callback
}

func (c *Client) OnEventChannelVIPRemove(callback func(event EventChannelVIPRemove)) {
c.onEventChannelVIPRemove = callback
}

func (c *Client) OnEventChannelChannelPointsCustomRewardAdd(callback func(event EventChannelChannelPointsCustomRewardAdd)) {
c.onEventChannelChannelPointsCustomRewardAdd = callback
}
Expand All @@ -551,6 +583,10 @@ func (c *Client) OnEventChannelChannelPointsCustomRewardRedemptionUpdate(callbac
c.onEventChannelChannelPointsCustomRewardRedemptionUpdate = callback
}

func (c *Client) OnEventChannelChannelPointsAutomaticRewardRedemptionAdd(callback func(event EventChannelChannelPointsAutomaticRewardRedemptionAdd)) {
c.onEventChannelChannelPointsAutomaticRewardRedemptionAdd = callback
}

func (c *Client) OnEventChannelPollBegin(callback func(event EventChannelPollBegin)) {
c.onEventChannelPollBegin = callback
}
Expand Down Expand Up @@ -738,3 +774,23 @@ func (c *Client) OnEventChannelSharedChatEnd(callback func(event EventChannelSha
func (c *Client) OnEventUserWhisperMessage(callback func(event EventUserWhisperMessage)) {
c.onEventUserWhisperMessage = callback
}

func (c *Client) OnEventChannelAdBreakBegin(callback func(event EventChannelAdBreakBegin)) {
c.onEventChannelAdBreakBegin = callback
}

func (c *Client) OnEventChannelWarningAcknowledge(callback func(event EventChannelWarningAcknowledge)) {
c.onEventChannelWarningAcknowledge = callback
}

func (c *Client) OnEventChannelWarningSend(callback func(event EventChannelWarningSend)) {
c.onEventChannelWarningSend = callback
}

func (c *Client) OnEventChannelUnbanRequestCreate(callback func(event EventChannelUnbanRequestCreate)) {
c.onEventChannelUnbanRequestCreate = callback
}

func (c *Client) OnEventChannelUnbanRequestResolve(callback func(event EventChannelUnbanRequestResolve)) {
c.onEventChannelUnbanRequestResolve = callback
}
80 changes: 80 additions & 0 deletions connEvent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ func TestEventChannelModeratorRemove(t *testing.T) {
}, twitch.SubChannelModeratorRemove)
}

func TestEventChannelVIPAdd(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelVIPAdd(func(event twitch.EventChannelVIPAdd) {
close(ch)
})
}, twitch.SubChannelVIPAdd)
}

func TestEventChannelVIPRemove(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelVIPRemove(func(event twitch.EventChannelVIPRemove) {
close(ch)
})
}, twitch.SubChannelVIPRemove)
}

func TestEventChannelChannelPointsCustomRewardAdd(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -234,6 +254,16 @@ func TestEventChannelChannelPointsCustomRewardRedemptionUpdate(t *testing.T) {
}, twitch.SubChannelChannelPointsCustomRewardRedemptionUpdate)
}

func TestEventChannelChannelPointsAutomaticRewardRedemptionAdd(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelChannelPointsAutomaticRewardRedemptionAdd(func(event twitch.EventChannelChannelPointsAutomaticRewardRedemptionAdd) {
close(ch)
})
}, twitch.SubChannelChannelPointsAutomaticRewardRedemptionAdd)
}

func TestEventChannelPollBegin(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -723,3 +753,53 @@ func TestEventUserWhisperMessage(t *testing.T) {
})
}, twitch.SubUserWhisperMessage)
}

func TestEventChannelAdBreakBegin(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelAdBreakBegin(func(event twitch.EventChannelAdBreakBegin) {
close(ch)
})
}, twitch.SubChannelAdBreakBegin)
}

func TestEventChannelWarningAcknowledge(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelWarningAcknowledge(func(event twitch.EventChannelWarningAcknowledge) {
close(ch)
})
}, twitch.SubChannelWarningAcknowledge)
}

func TestEventChannelWarningSend(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelWarningSend(func(event twitch.EventChannelWarningSend) {
close(ch)
})
}, twitch.SubChannelWarningSend)
}

func TestEventChannelUnbanRequestCreate(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelUnbanRequestCreate(func(event twitch.EventChannelUnbanRequestCreate) {
close(ch)
})
}, twitch.SubChannelUnbanRequestCreate)
}

func TestEventChannelUnbanRequestResolve(t *testing.T) {
t.Parallel()

assertSpecificEventOccured(t, func(client *twitch.Client, ch chan struct{}) {
client.OnEventChannelUnbanRequestResolve(func(event twitch.EventChannelUnbanRequestResolve) {
close(ch)
})
}, twitch.SubChannelUnbanRequestResolve)
}
Loading
Loading