Skip to content

Commit 70e8296

Browse files
authored
Add Invite Create/Delete (#1105)
* Add Invite Create/Delete * rename const * Refactor Application * Feedback & deprecation * lint fix for godoc comment * review feedback
1 parent 4cc53b7 commit 70e8296

File tree

4 files changed

+114
-47
lines changed

4 files changed

+114
-47
lines changed

eventhandlers.go

+48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

events.go

+14
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,17 @@ type InteractionCreate struct {
341341
func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
342342
return json.Unmarshal(b, &i.Interaction)
343343
}
344+
345+
// InviteCreate is the data for a InviteCreate event
346+
type InviteCreate struct {
347+
*Invite
348+
ChannelID string `json:"channel_id"`
349+
GuildID string `json:"guild_id"`
350+
}
351+
352+
// InviteDelete is the data for a InviteDelete event
353+
type InviteDelete struct {
354+
ChannelID string `json:"channel_id"`
355+
GuildID string `json:"guild_id"`
356+
Code string `json:"code"`
357+
}

oauth2.go

+6-25
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,6 @@ type Team struct {
4040
Members []*TeamMember `json:"members"`
4141
}
4242

43-
// An Application struct stores values for a Discord OAuth2 Application
44-
type Application struct {
45-
ID string `json:"id,omitempty"`
46-
Name string `json:"name"`
47-
Description string `json:"description,omitempty"`
48-
Icon string `json:"icon,omitempty"`
49-
Secret string `json:"secret,omitempty"`
50-
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
51-
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
52-
BotPublic bool `json:"bot_public,omitempty"`
53-
RPCApplicationState int `json:"rpc_application_state,omitempty"`
54-
Flags int `json:"flags,omitempty"`
55-
Owner *User `json:"owner"`
56-
Bot *User `json:"bot"`
57-
Team *Team `json:"team"`
58-
}
59-
6043
// Application returns an Application structure of a specific Application
6144
// appID : The ID of an Application
6245
func (s *Session) Application(appID string) (st *Application, err error) {
@@ -88,10 +71,9 @@ func (s *Session) Applications() (st []*Application, err error) {
8871
func (s *Session) ApplicationCreate(ap *Application) (st *Application, err error) {
8972

9073
data := struct {
91-
Name string `json:"name"`
92-
Description string `json:"description"`
93-
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
94-
}{ap.Name, ap.Description, ap.RedirectURIs}
74+
Name string `json:"name"`
75+
Description string `json:"description"`
76+
}{ap.Name, ap.Description}
9577

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

10991
data := struct {
110-
Name string `json:"name"`
111-
Description string `json:"description"`
112-
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
113-
}{ap.Name, ap.Description, ap.RedirectURIs}
92+
Name string `json:"name"`
93+
Description string `json:"description"`
94+
}{ap.Name, ap.Description}
11495

11596
body, err := s.RequestWithBucketID("PUT", EndpointOAuth2Application(appID), data, EndpointOAuth2Application(""))
11697
if err != nil {

structs.go

+46-22
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,28 @@ type Session struct {
128128
wsMutex sync.Mutex
129129
}
130130

131+
// Application stores values for a Discord Application
132+
type Application struct {
133+
ID string `json:"id,omitempty"`
134+
Name string `json:"name"`
135+
Icon string `json:"icon,omitempty"`
136+
Description string `json:"description,omitempty"`
137+
RPCOrigins []string `json:"rpc_origins,omitempty"`
138+
BotPublic bool `json:"bot_public,omitempty"`
139+
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
140+
TermsOfServiceURL string `json:"terms_of_service_url"`
141+
PrivacyProxyURL string `json:"privacy_policy_url"`
142+
Owner *User `json:"owner"`
143+
Summary string `json:"summary"`
144+
VerifyKey string `json:"verify_key"`
145+
Team *Team `json:"team"`
146+
GuildID string `json:"guild_id"`
147+
PrimarySKUID string `json:"primary_sku_id"`
148+
Slug string `json:"slug"`
149+
CoverImage string `json:"cover_image"`
150+
Flags int `json:"flags,omitempty"`
151+
}
152+
131153
// UserConnection is a Connection returned from the UserConnections endpoint
132154
type UserConnection struct {
133155
ID string `json:"id"`
@@ -191,36 +213,38 @@ type ICEServer struct {
191213
Credential string `json:"credential"`
192214
}
193215

216+
// InviteTargetType indicates the type of target of an invite
217+
// https://discord.com/developers/docs/resources/invite#invite-object-invite-target-types
218+
type InviteTargetType uint8
219+
220+
// Invite target types
221+
const (
222+
InviteTargetStream InviteTargetType = 1
223+
InviteTargetEmbeddedAppliction InviteTargetType = 2
224+
)
225+
194226
// A Invite stores all data related to a specific Discord Guild or Channel invite.
195227
type Invite struct {
196-
Guild *Guild `json:"guild"`
197-
Channel *Channel `json:"channel"`
198-
Inviter *User `json:"inviter"`
199-
Code string `json:"code"`
200-
CreatedAt time.Time `json:"created_at"`
201-
MaxAge int `json:"max_age"`
202-
Uses int `json:"uses"`
203-
MaxUses int `json:"max_uses"`
204-
Revoked bool `json:"revoked"`
205-
Temporary bool `json:"temporary"`
206-
Unique bool `json:"unique"`
207-
TargetUser *User `json:"target_user"`
208-
TargetUserType TargetUserType `json:"target_user_type"`
228+
Guild *Guild `json:"guild"`
229+
Channel *Channel `json:"channel"`
230+
Inviter *User `json:"inviter"`
231+
Code string `json:"code"`
232+
CreatedAt time.Time `json:"created_at"`
233+
MaxAge int `json:"max_age"`
234+
Uses int `json:"uses"`
235+
MaxUses int `json:"max_uses"`
236+
Revoked bool `json:"revoked"`
237+
Temporary bool `json:"temporary"`
238+
Unique bool `json:"unique"`
239+
TargetUser *User `json:"target_user"`
240+
TargetType InviteTargetType `json:"target_type"`
241+
TargetApplication *Application `json:"target_application"`
209242

210243
// will only be filled when using InviteWithCounts
211244
ApproximatePresenceCount int `json:"approximate_presence_count"`
212245
ApproximateMemberCount int `json:"approximate_member_count"`
213246
}
214247

215-
// TargetUserType is the type of the target user
216-
// https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
217-
type TargetUserType int
218-
219-
// Block contains known TargetUserType values
220-
const (
221-
TargetUserTypeStream TargetUserType = 1
222-
)
223-
224248
// ChannelType is the type of a Channel
225249
type ChannelType int
226250

0 commit comments

Comments
 (0)