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 Invite Create/Delete #1105

Merged
merged 6 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions eventhandlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions events.go
Expand Up @@ -341,3 +341,17 @@ type InteractionCreate struct {
func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &i.Interaction)
}

// InviteCreate is the data for a InviteCreate event
type InviteCreate struct {
*Invite
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id"`
}

// InviteDelete is the data for a InviteDelete event
type InviteDelete struct {
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id"`
Code string `json:"code"`
}
2 changes: 2 additions & 0 deletions message.go
Expand Up @@ -434,6 +434,8 @@ const (
)

// MessageApplication is sent with Rich Presence-related chat embeds
// This is used instead of Application to reduce the amount of memory consumption
// of message objects
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this PR would be right place to add this comment

type MessageApplication struct {
ID string `json:"id"`
CoverImage string `json:"cover_image"`
Expand Down
17 changes: 0 additions & 17 deletions oauth2.go
Expand Up @@ -40,23 +40,6 @@ type Team struct {
Members []*TeamMember `json:"members"`
}

// An Application struct stores values for a Discord OAuth2 Application
type Application struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Icon string `json:"icon,omitempty"`
Secret string `json:"secret,omitempty"`
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
BotPublic bool `json:"bot_public,omitempty"`
RPCApplicationState int `json:"rpc_application_state,omitempty"`
Flags int `json:"flags,omitempty"`
Owner *User `json:"owner"`
Bot *User `json:"bot"`
Team *Team `json:"team"`
}

// Application returns an Application structure of a specific Application
// appID : The ID of an Application
func (s *Session) Application(appID string) (st *Application, err error) {
Expand Down
67 changes: 53 additions & 14 deletions structs.go
Expand Up @@ -128,6 +128,32 @@ type Session struct {
wsMutex sync.Mutex
}

// Application stores values for a Discord Application
type Application struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Icon string `json:"icon,omitempty"`
Description string `json:"description,omitempty"`
RPCOrigins []string `json:"rpc_origins,omitempty"`
BotPublic bool `json:"bot_public,omitempty"`
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
TermsOfServiceURL string `json:"terms_of_service_url"`
PrivacyProxyURL string `json:"privacy_policy_url"`
Owner *User `json:"owner"`
Summary string `json:"summary"`
VerifyKey string `json:"verify_key"`
Team *Team `json:"team"`
GuildID string `json:"guild_id"`
PrimarySKUID string `json:"primary_sku_id"`
Slug string `json:"slug"`
CoverImage string `json:"cover_image"`
Flags int `json:"flags,omitempty"`

// TODO: Remove this when compatibility is not required
// Deprecated
RedirectURIs *[]string `json:"-"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to remove this field, since it doesn't have a purpose anymore.

}

// UserConnection is a Connection returned from the UserConnections endpoint
type UserConnection struct {
ID string `json:"id"`
Expand Down Expand Up @@ -191,32 +217,45 @@ type ICEServer struct {
Credential string `json:"credential"`
}

// InviteTargetType indicates the type of target of an invite
// https://discord.com/developers/docs/resources/invite#invite-object-invite-target-types
type InviteTargetType uint8

// Invite target types
const (
InviteTargetStream InviteTargetType = 1
InviteTargetEmbeddedAppliction InviteTargetType = 2
)

// A Invite stores all data related to a specific Discord Guild or Channel invite.
type Invite struct {
Guild *Guild `json:"guild"`
Channel *Channel `json:"channel"`
Inviter *User `json:"inviter"`
Code string `json:"code"`
CreatedAt time.Time `json:"created_at"`
MaxAge int `json:"max_age"`
Uses int `json:"uses"`
MaxUses int `json:"max_uses"`
Revoked bool `json:"revoked"`
Temporary bool `json:"temporary"`
Unique bool `json:"unique"`
TargetUser *User `json:"target_user"`
TargetUserType TargetUserType `json:"target_user_type"`
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
Guild *Guild `json:"guild"`
Channel *Channel `json:"channel"`
Inviter *User `json:"inviter"`
Code string `json:"code"`
CreatedAt time.Time `json:"created_at"`
MaxAge int `json:"max_age"`
Uses int `json:"uses"`
MaxUses int `json:"max_uses"`
Revoked bool `json:"revoked"`
Temporary bool `json:"temporary"`
Unique bool `json:"unique"`
TargetUser *User `json:"target_user"`
TargetType InviteTargetType `json:"target_type"`
TargetApplication *Application `json:"target_application"`

// will only be filled when using InviteWithCounts
ApproximatePresenceCount int `json:"approximate_presence_count"`
ApproximateMemberCount int `json:"approximate_member_count"`
}

// TargetUserType is the type of the target user
// https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
// TODO: Remove this when compatibility is not required
// Deprecated: see InviteTargetType
type TargetUserType int

// Block contains known TargetUserType values
// Deprecated: see InviteTargetType
const (
TargetUserTypeStream TargetUserType = 1
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the type is meant to be renamed I think it would be fair to remove the old one.

Expand Down