Skip to content

Commit

Permalink
Add Invite Create/Delete (#1105)
Browse files Browse the repository at this point in the history
* Add Invite Create/Delete

* rename const

* Refactor Application

* Feedback & deprecation

* lint fix for godoc comment

* review feedback
  • Loading branch information
pixelrazor committed Feb 25, 2022
1 parent 4cc53b7 commit 70e8296
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 47 deletions.
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"`
}
31 changes: 6 additions & 25 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 Expand Up @@ -88,10 +71,9 @@ func (s *Session) Applications() (st []*Application, err error) {
func (s *Session) ApplicationCreate(ap *Application) (st *Application, err error) {

data := struct {
Name string `json:"name"`
Description string `json:"description"`
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
}{ap.Name, ap.Description, ap.RedirectURIs}
Name string `json:"name"`
Description string `json:"description"`
}{ap.Name, ap.Description}

body, err := s.RequestWithBucketID("POST", EndpointOAuth2Applications, data, EndpointOAuth2Applications)
if err != nil {
Expand All @@ -107,10 +89,9 @@ func (s *Session) ApplicationCreate(ap *Application) (st *Application, err error
func (s *Session) ApplicationUpdate(appID string, ap *Application) (st *Application, err error) {

data := struct {
Name string `json:"name"`
Description string `json:"description"`
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
}{ap.Name, ap.Description, ap.RedirectURIs}
Name string `json:"name"`
Description string `json:"description"`
}{ap.Name, ap.Description}

body, err := s.RequestWithBucketID("PUT", EndpointOAuth2Application(appID), data, EndpointOAuth2Application(""))
if err != nil {
Expand Down
68 changes: 46 additions & 22 deletions structs.go
Expand Up @@ -128,6 +128,28 @@ 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"`
}

// UserConnection is a Connection returned from the UserConnections endpoint
type UserConnection struct {
ID string `json:"id"`
Expand Down Expand Up @@ -191,36 +213,38 @@ 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"`
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
type TargetUserType int

// Block contains known TargetUserType values
const (
TargetUserTypeStream TargetUserType = 1
)

// ChannelType is the type of a Channel
type ChannelType int

Expand Down

0 comments on commit 70e8296

Please sign in to comment.