-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package discord | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/disgoorg/snowflake/v2" | ||
) | ||
|
||
type Subscription struct { | ||
ID snowflake.ID `json:"id"` | ||
UserID snowflake.ID `json:"user_id"` | ||
SkuIDs []snowflake.ID `json:"sku_ids"` | ||
EntitlementIDs []snowflake.ID `json:"entitlement_ids"` | ||
CurrentPeriodStart time.Time `json:"current_period_start"` | ||
CurrentPeriodEnd time.Time `json:"current_period_end"` | ||
Status SubscriptionStatus `json:"status"` | ||
CanceledAt *time.Time `json:"canceled_at"` | ||
Country *string `json:"country"` | ||
} | ||
|
||
type SubscriptionStatus int | ||
|
||
const ( | ||
SubscriptionStatusActive SubscriptionStatus = iota + 1 | ||
SubscriptionStatusEnding | ||
SubscriptionStatusInactive | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package events | ||
|
||
import "github.com/disgoorg/disgo/discord" | ||
|
||
type GenericSubscriptionEvent struct { | ||
*GenericEvent | ||
discord.Subscription | ||
} | ||
|
||
type SubscriptionCreate struct { | ||
*GenericSubscriptionEvent | ||
} | ||
|
||
type SubscriptionUpdate struct { | ||
*GenericSubscriptionEvent | ||
} | ||
|
||
type SubscriptionDelete struct { | ||
*GenericSubscriptionEvent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package handlers | ||
|
||
import ( | ||
"github.com/disgoorg/disgo/bot" | ||
"github.com/disgoorg/disgo/events" | ||
"github.com/disgoorg/disgo/gateway" | ||
) | ||
|
||
func gatewayHandlerSubscriptionCreate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventSubscriptionCreate) { | ||
client.EventManager().DispatchEvent(&events.SubscriptionCreate{ | ||
GenericSubscriptionEvent: &events.GenericSubscriptionEvent{ | ||
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), | ||
Subscription: event.Subscription, | ||
}, | ||
}) | ||
} | ||
|
||
func gatewayHandlerSubscriptionUpdate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventSubscriptionUpdate) { | ||
client.EventManager().DispatchEvent(&events.SubscriptionUpdate{ | ||
GenericSubscriptionEvent: &events.GenericSubscriptionEvent{ | ||
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), | ||
Subscription: event.Subscription, | ||
}, | ||
}) | ||
} | ||
|
||
func gatewayHandlerSubscriptionDelete(client bot.Client, sequenceNumber int, shardID int, event gateway.EventSubscriptionDelete) { | ||
client.EventManager().DispatchEvent(&events.SubscriptionDelete{ | ||
GenericSubscriptionEvent: &events.GenericSubscriptionEvent{ | ||
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), | ||
Subscription: event.Subscription, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package rest | ||
|
||
import ( | ||
"github.com/disgoorg/disgo/discord" | ||
"github.com/disgoorg/snowflake/v2" | ||
) | ||
|
||
var _ SKUs = (*skusImpl)(nil) | ||
|
||
func NewSKUs(client Client) SKUs { | ||
return &skusImpl{client: client} | ||
} | ||
|
||
type SKUs interface { | ||
GetSKUs(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.SKU, error) | ||
|
||
GetSKUSubscriptions(skuID snowflake.ID, before snowflake.ID, after snowflake.ID, limit int, userID snowflake.ID, opts ...RequestOpt) ([]discord.Subscription, error) | ||
GetSKUSubscriptionsPage(skuID snowflake.ID, userID snowflake.ID, startID snowflake.ID, limit int, opts ...RequestOpt) Page[discord.Subscription] | ||
GetSKUSubscription(skuID snowflake.ID, subscriptionID snowflake.ID, opts ...RequestOpt) (*discord.Subscription, error) | ||
} | ||
|
||
type skusImpl struct { | ||
client Client | ||
} | ||
|
||
func (s *skusImpl) GetSKUs(applicationID snowflake.ID, opts ...RequestOpt) (skus []discord.SKU, err error) { | ||
err = s.client.Do(GetSKUs.Compile(nil, applicationID), nil, &skus, opts...) | ||
return | ||
} | ||
|
||
func (s *skusImpl) GetSKUSubscriptions(skuID snowflake.ID, before snowflake.ID, after snowflake.ID, limit int, userID snowflake.ID, opts ...RequestOpt) (subscriptions []discord.Subscription, err error) { | ||
values := discord.QueryValues{} | ||
if before != 0 { | ||
values["before"] = before | ||
} | ||
if after != 0 { | ||
values["after"] = after | ||
} | ||
if limit != 0 { | ||
values["limit"] = limit | ||
} | ||
if userID != 0 { | ||
values["user_id"] = userID | ||
} | ||
err = s.client.Do(GetSKUSubscriptions.Compile(values, skuID), nil, &subscriptions, opts...) | ||
return | ||
} | ||
|
||
func (s *skusImpl) GetSKUSubscriptionsPage(skuID snowflake.ID, userID snowflake.ID, startID snowflake.ID, limit int, opts ...RequestOpt) Page[discord.Subscription] { | ||
return Page[discord.Subscription]{ | ||
getItemsFunc: func(before snowflake.ID, after snowflake.ID) ([]discord.Subscription, error) { | ||
return s.GetSKUSubscriptions(skuID, before, after, limit, userID, opts...) | ||
}, | ||
getIDFunc: func(subscription discord.Subscription) snowflake.ID { | ||
return subscription.ID | ||
}, | ||
ID: startID, | ||
} | ||
} | ||
|
||
func (s *skusImpl) GetSKUSubscription(skuID snowflake.ID, subscriptionID snowflake.ID, opts ...RequestOpt) (subscription *discord.Subscription, err error) { | ||
err = s.client.Do(GetSKUSubscription.Compile(nil, skuID, subscriptionID), nil, &subscription, opts...) | ||
return | ||
} |