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 role subscriptions #218

Merged
merged 14 commits into from
Aug 18, 2023
51 changes: 28 additions & 23 deletions discord/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
SystemChannelFlagSuppressPremiumSubscriptions
SystemChannelFlagSuppressGuildReminderNotifications
SystemChannelFlagSuppressJoinNotificationReplies
SystemChannelFlagSuppressRoleSubscriptionPurchaseNotifications
SystemChannelFlagSuppressRoleSubscriptionPurchaseNotificationReplies
)

// Add allows you to add multiple bits together, producing a new bit
Expand Down Expand Up @@ -96,29 +98,32 @@ type GuildFeature string

// Constants for GuildFeature
const (
GuildFeatureAnimatedBanner GuildFeature = "ANIMATED_BANNER"
GuildFeatureAnimatedIcon GuildFeature = "ANIMATED_ICON"
GuildFeatureAutoModeration GuildFeature = "AUTO_MODERATION"
GuildFeatureBanner GuildFeature = "BANNER"
GuildFeatureCommunity GuildFeature = "COMMUNITY"
GuildFeatureDeveloperSupportServer GuildFeature = "DEVELOPER_SUPPORT_SERVER"
GuildFeatureDiscoverable GuildFeature = "DISCOVERABLE"
GuildFeatureFeaturable GuildFeature = "FEATURABLE"
GuildFeatureInvitesDisabled GuildFeature = "INVITES_DISABLED"
GuildFeatureInviteSplash GuildFeature = "INVITE_SPLASH"
GuildFeatureMemberVerificationGateEnabled GuildFeature = "MEMBER_VERIFICATION_GATE_ENABLED"
GuildFeatureMonetizationEnabled GuildFeature = "MONETIZATION_ENABLED"
GuildFeatureMoreStickers GuildFeature = "MORE_STICKERS"
GuildFeatureNews GuildFeature = "NEWS"
GuildFeaturePartnered GuildFeature = "PARTNERED"
GuildFeaturePreviewEnabled GuildFeature = "PREVIEW_ENABLED"
GuildFeatureRaidAlertsDisabled GuildFeature = "RAID_ALERTS_DISABLED"
GuildFeatureRoleIcons GuildFeature = "ROLE_ICONS"
GuildFeatureTicketedEventsEnabled GuildFeature = "TICKETED_EVENTS_ENABLED"
GuildFeatureVanityURL GuildFeature = "VANITY_URL"
GuildFeatureVerified GuildFeature = "VERIFIED"
GuildFeatureVipRegions GuildFeature = "VIP_REGIONS"
GuildFeatureWelcomeScreenEnabled GuildFeature = "WELCOME_SCREEN_ENABLED"
GuildFeatureAnimatedBanner GuildFeature = "ANIMATED_BANNER"
GuildFeatureAnimatedIcon GuildFeature = "ANIMATED_ICON"
GuildFeatureAutoModeration GuildFeature = "AUTO_MODERATION"
GuildFeatureBanner GuildFeature = "BANNER"
GuildFeatureCommunity GuildFeature = "COMMUNITY"
GuildFeatureCreatorMonetizableProvisional GuildFeature = "CREATOR_MONETIZABLE_PROVISIONAL"
GuildFeatureCreatorStorePage GuildFeature = "CREATOR_STORE_PAGE"
GuildFeatureDeveloperSupportServer GuildFeature = "DEVELOPER_SUPPORT_SERVER"
GuildFeatureDiscoverable GuildFeature = "DISCOVERABLE"
GuildFeatureFeaturable GuildFeature = "FEATURABLE"
GuildFeatureInvitesDisabled GuildFeature = "INVITES_DISABLED"
GuildFeatureInviteSplash GuildFeature = "INVITE_SPLASH"
GuildFeatureMemberVerificationGateEnabled GuildFeature = "MEMBER_VERIFICATION_GATE_ENABLED"
GuildFeatureMoreStickers GuildFeature = "MORE_STICKERS"
GuildFeatureNews GuildFeature = "NEWS"
GuildFeaturePartnered GuildFeature = "PARTNERED"
GuildFeaturePreviewEnabled GuildFeature = "PREVIEW_ENABLED"
GuildFeatureRaidAlertsDisabled GuildFeature = "RAID_ALERTS_DISABLED"
GuildFeatureRoleIcons GuildFeature = "ROLE_ICONS"
GuildFeatureRoleSubscriptionsAvailableForPurchase GuildFeature = "ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE"
GuildFeatureRoleSubscriptionsEnabled GuildFeature = "ROLE_SUBSCRIPTIONS_ENABLED"
GuildFeatureTicketedEventsEnabled GuildFeature = "TICKETED_EVENTS_ENABLED"
GuildFeatureVanityURL GuildFeature = "VANITY_URL"
GuildFeatureVerified GuildFeature = "VERIFIED"
GuildFeatureVipRegions GuildFeature = "VIP_REGIONS"
GuildFeatureWelcomeScreenEnabled GuildFeature = "WELCOME_SCREEN_ENABLED"
)

// Guild represents a discord Guild
Expand Down
42 changes: 39 additions & 3 deletions discord/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ type IntegrationType string

// All IntegrationType(s)
const (
IntegrationTypeTwitch IntegrationType = "twitch"
IntegrationTypeYouTube IntegrationType = "youtube"
IntegrationTypeBot IntegrationType = "discord"
IntegrationTypeTwitch IntegrationType = "twitch"
IntegrationTypeYouTube IntegrationType = "youtube"
IntegrationTypeBot IntegrationType = "discord"
IntegrationTypeGuildSubscription IntegrationType = "guild_subscription"
)

// IntegrationAccount (https://discord.com/developers/docs/resources/guild#integration-account-object)
Expand Down Expand Up @@ -76,6 +77,11 @@ func (i *UnmarshalIntegration) UnmarshalJSON(data []byte) error {
err = json.Unmarshal(data, &v)
integration = v

case IntegrationTypeGuildSubscription:
var v GuildSubscriptionIntegration
err = json.Unmarshal(data, &v)
integration = v

default:
err = fmt.Errorf("unknown integration with type %s received", cType.Type)
}
Expand Down Expand Up @@ -203,3 +209,33 @@ func (i BotIntegration) ID() snowflake.ID {
func (i BotIntegration) CreatedAt() time.Time {
return i.IntegrationID.Time()
}

type GuildSubscriptionIntegration struct {
IntegrationID snowflake.ID `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Account IntegrationAccount `json:"account"`
}

func (i GuildSubscriptionIntegration) MarshalJSON() ([]byte, error) {
type subscriptionIntegration GuildSubscriptionIntegration
return json.Marshal(struct {
Type IntegrationType `json:"type"`
subscriptionIntegration
}{
Type: i.Type(),
subscriptionIntegration: subscriptionIntegration(i),
})
}

func (GuildSubscriptionIntegration) Type() IntegrationType {
return IntegrationTypeGuildSubscription
}

func (i GuildSubscriptionIntegration) ID() snowflake.ID {
return i.IntegrationID
}

func (i GuildSubscriptionIntegration) CreatedAt() time.Time {
return i.IntegrationID.Time()
}
1 change: 1 addition & 0 deletions discord/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type InviteTargetType int
const (
InviteTargetTypeStream InviteTargetType = iota + 1
InviteTargetTypeEmbeddedApplication
InviteTargetTypeRoleSubscriptionsPurchase
)

// Invite is a partial invite struct
Expand Down
72 changes: 40 additions & 32 deletions discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
MessageTypeGuildInviteReminder
MessageTypeContextMenuCommand
MessageTypeAutoModerationAction
_
MessageTypeRoleSubscriptionPurchase
MessageTypeInteractionPremiumUpsell
MessageTypeStageStart
MessageTypeStageEnd
Expand Down Expand Up @@ -81,37 +81,38 @@ func MessageURL(guildID snowflake.ID, channelID snowflake.ID, messageID snowflak

// Message is a struct for messages sent in discord text-based channels
type Message struct {
ID snowflake.ID `json:"id"`
GuildID *snowflake.ID `json:"guild_id"`
Reactions []MessageReaction `json:"reactions"`
Attachments []Attachment `json:"attachments"`
TTS bool `json:"tts"`
Embeds []Embed `json:"embeds,omitempty"`
Components []ContainerComponent `json:"components,omitempty"`
CreatedAt time.Time `json:"timestamp"`
Mentions []User `json:"mentions"`
MentionEveryone bool `json:"mention_everyone"`
MentionRoles []snowflake.ID `json:"mention_roles"`
MentionChannels []Channel `json:"mention_channels"`
Pinned bool `json:"pinned"`
EditedTimestamp *time.Time `json:"edited_timestamp"`
Author User `json:"author"`
Member *Member `json:"member"`
Content string `json:"content,omitempty"`
ChannelID snowflake.ID `json:"channel_id"`
Type MessageType `json:"type"`
Flags MessageFlags `json:"flags"`
MessageReference *MessageReference `json:"message_reference,omitempty"`
Interaction *MessageInteraction `json:"interaction,omitempty"`
WebhookID *snowflake.ID `json:"webhook_id,omitempty"`
Activity *MessageActivity `json:"activity,omitempty"`
Application *MessageApplication `json:"application,omitempty"`
ApplicationID *snowflake.ID `json:"application_id,omitempty"`
StickerItems []MessageSticker `json:"sticker_items,omitempty"`
ReferencedMessage *Message `json:"referenced_message,omitempty"`
LastUpdated *time.Time `json:"last_updated,omitempty"`
Thread *MessageThread `json:"thread,omitempty"`
Position *int `json:"position,omitempty"`
ID snowflake.ID `json:"id"`
GuildID *snowflake.ID `json:"guild_id"`
Reactions []MessageReaction `json:"reactions"`
Attachments []Attachment `json:"attachments"`
TTS bool `json:"tts"`
Embeds []Embed `json:"embeds,omitempty"`
Components []ContainerComponent `json:"components,omitempty"`
CreatedAt time.Time `json:"timestamp"`
Mentions []User `json:"mentions"`
MentionEveryone bool `json:"mention_everyone"`
MentionRoles []snowflake.ID `json:"mention_roles"`
MentionChannels []Channel `json:"mention_channels"`
Pinned bool `json:"pinned"`
EditedTimestamp *time.Time `json:"edited_timestamp"`
Author User `json:"author"`
Member *Member `json:"member"`
Content string `json:"content,omitempty"`
ChannelID snowflake.ID `json:"channel_id"`
Type MessageType `json:"type"`
Flags MessageFlags `json:"flags"`
MessageReference *MessageReference `json:"message_reference,omitempty"`
Interaction *MessageInteraction `json:"interaction,omitempty"`
WebhookID *snowflake.ID `json:"webhook_id,omitempty"`
Activity *MessageActivity `json:"activity,omitempty"`
Application *MessageApplication `json:"application,omitempty"`
ApplicationID *snowflake.ID `json:"application_id,omitempty"`
StickerItems []MessageSticker `json:"sticker_items,omitempty"`
ReferencedMessage *Message `json:"referenced_message,omitempty"`
LastUpdated *time.Time `json:"last_updated,omitempty"`
Thread *MessageThread `json:"thread,omitempty"`
Position *int `json:"position,omitempty"`
RoleSubscriptionData *RoleSubscriptionData `json:"role_subscription_data,omitempty"`
}

func (m *Message) UnmarshalJSON(data []byte) error {
Expand Down Expand Up @@ -439,3 +440,10 @@ func (f MessageFlags) Has(bits ...MessageFlags) bool {
func (f MessageFlags) Missing(bits ...MessageFlags) bool {
return flags.Missing(f, bits...)
}

type RoleSubscriptionData struct {
RoleSubscriptionListingID snowflake.ID `json:"role_subscription_listing_id"`
TierName string `json:"tier_name"`
TotalMonthsSubscribed int `json:"total_months_subscribed"`
IsRenewal bool `json:"is_renewal"`
}
10 changes: 6 additions & 4 deletions discord/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ func (r Role) CreatedAt() time.Time {

// RoleTag are tags a Role has
type RoleTag struct {
BotID *snowflake.ID `json:"bot_id,omitempty"`
IntegrationID *snowflake.ID `json:"integration_id,omitempty"`
PremiumSubscriber bool `json:"premium_subscriber"`
GuildConnections bool `json:"guild_connections"`
BotID *snowflake.ID `json:"bot_id,omitempty"`
IntegrationID *snowflake.ID `json:"integration_id,omitempty"`
PremiumSubscriber bool `json:"premium_subscriber"`
SubscriptionListingID *snowflake.ID `json:"subscription_listing_id,omitempty"`
AvailableForPurchase bool `json:"available_for_purchase"`
GuildConnections bool `json:"guild_connections"`
}

type RoleFlags int
Expand Down