Add Invite Create/Delete (#1105)
* Add Invite Create/Delete * rename const * Refactor Application * Feedback & deprecation * lint fix for godoc comment * review feedback
This commit is contained in:
parent
4cc53b7ed4
commit
70e829694d
4 changed files with 114 additions and 47 deletions
|
@ -29,6 +29,8 @@ const (
|
||||||
guildRoleUpdateEventType = "GUILD_ROLE_UPDATE"
|
guildRoleUpdateEventType = "GUILD_ROLE_UPDATE"
|
||||||
guildUpdateEventType = "GUILD_UPDATE"
|
guildUpdateEventType = "GUILD_UPDATE"
|
||||||
interactionCreateEventType = "INTERACTION_CREATE"
|
interactionCreateEventType = "INTERACTION_CREATE"
|
||||||
|
inviteCreateEventType = "INVITE_CREATE"
|
||||||
|
inviteDeleteEventType = "INVITE_DELETE"
|
||||||
messageAckEventType = "MESSAGE_ACK"
|
messageAckEventType = "MESSAGE_ACK"
|
||||||
messageCreateEventType = "MESSAGE_CREATE"
|
messageCreateEventType = "MESSAGE_CREATE"
|
||||||
messageDeleteEventType = "MESSAGE_DELETE"
|
messageDeleteEventType = "MESSAGE_DELETE"
|
||||||
|
@ -485,6 +487,46 @@ func (eh interactionCreateEventHandler) Handle(s *Session, i interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inviteCreateEventHandler is an event handler for InviteCreate events.
|
||||||
|
type inviteCreateEventHandler func(*Session, *InviteCreate)
|
||||||
|
|
||||||
|
// Type returns the event type for InviteCreate events.
|
||||||
|
func (eh inviteCreateEventHandler) Type() string {
|
||||||
|
return inviteCreateEventType
|
||||||
|
}
|
||||||
|
|
||||||
|
// New returns a new instance of InviteCreate.
|
||||||
|
func (eh inviteCreateEventHandler) New() interface{} {
|
||||||
|
return &InviteCreate{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle is the handler for InviteCreate events.
|
||||||
|
func (eh inviteCreateEventHandler) Handle(s *Session, i interface{}) {
|
||||||
|
if t, ok := i.(*InviteCreate); ok {
|
||||||
|
eh(s, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// inviteDeleteEventHandler is an event handler for InviteDelete events.
|
||||||
|
type inviteDeleteEventHandler func(*Session, *InviteDelete)
|
||||||
|
|
||||||
|
// Type returns the event type for InviteDelete events.
|
||||||
|
func (eh inviteDeleteEventHandler) Type() string {
|
||||||
|
return inviteDeleteEventType
|
||||||
|
}
|
||||||
|
|
||||||
|
// New returns a new instance of InviteDelete.
|
||||||
|
func (eh inviteDeleteEventHandler) New() interface{} {
|
||||||
|
return &InviteDelete{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle is the handler for InviteDelete events.
|
||||||
|
func (eh inviteDeleteEventHandler) Handle(s *Session, i interface{}) {
|
||||||
|
if t, ok := i.(*InviteDelete); ok {
|
||||||
|
eh(s, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// messageAckEventHandler is an event handler for MessageAck events.
|
// messageAckEventHandler is an event handler for MessageAck events.
|
||||||
type messageAckEventHandler func(*Session, *MessageAck)
|
type messageAckEventHandler func(*Session, *MessageAck)
|
||||||
|
|
||||||
|
@ -1108,6 +1150,10 @@ func handlerForInterface(handler interface{}) EventHandler {
|
||||||
return guildUpdateEventHandler(v)
|
return guildUpdateEventHandler(v)
|
||||||
case func(*Session, *InteractionCreate):
|
case func(*Session, *InteractionCreate):
|
||||||
return interactionCreateEventHandler(v)
|
return interactionCreateEventHandler(v)
|
||||||
|
case func(*Session, *InviteCreate):
|
||||||
|
return inviteCreateEventHandler(v)
|
||||||
|
case func(*Session, *InviteDelete):
|
||||||
|
return inviteDeleteEventHandler(v)
|
||||||
case func(*Session, *MessageAck):
|
case func(*Session, *MessageAck):
|
||||||
return messageAckEventHandler(v)
|
return messageAckEventHandler(v)
|
||||||
case func(*Session, *MessageCreate):
|
case func(*Session, *MessageCreate):
|
||||||
|
@ -1191,6 +1237,8 @@ func init() {
|
||||||
registerInterfaceProvider(guildRoleUpdateEventHandler(nil))
|
registerInterfaceProvider(guildRoleUpdateEventHandler(nil))
|
||||||
registerInterfaceProvider(guildUpdateEventHandler(nil))
|
registerInterfaceProvider(guildUpdateEventHandler(nil))
|
||||||
registerInterfaceProvider(interactionCreateEventHandler(nil))
|
registerInterfaceProvider(interactionCreateEventHandler(nil))
|
||||||
|
registerInterfaceProvider(inviteCreateEventHandler(nil))
|
||||||
|
registerInterfaceProvider(inviteDeleteEventHandler(nil))
|
||||||
registerInterfaceProvider(messageAckEventHandler(nil))
|
registerInterfaceProvider(messageAckEventHandler(nil))
|
||||||
registerInterfaceProvider(messageCreateEventHandler(nil))
|
registerInterfaceProvider(messageCreateEventHandler(nil))
|
||||||
registerInterfaceProvider(messageDeleteEventHandler(nil))
|
registerInterfaceProvider(messageDeleteEventHandler(nil))
|
||||||
|
|
14
events.go
14
events.go
|
@ -341,3 +341,17 @@ type InteractionCreate struct {
|
||||||
func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
|
func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
|
||||||
return json.Unmarshal(b, &i.Interaction)
|
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
oauth2.go
31
oauth2.go
|
@ -40,23 +40,6 @@ type Team struct {
|
||||||
Members []*TeamMember `json:"members"`
|
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
|
// Application returns an Application structure of a specific Application
|
||||||
// appID : The ID of an Application
|
// appID : The ID of an Application
|
||||||
func (s *Session) Application(appID string) (st *Application, err error) {
|
func (s *Session) Application(appID string) (st *Application, err error) {
|
||||||
|
@ -88,10 +71,9 @@ func (s *Session) Applications() (st []*Application, err error) {
|
||||||
func (s *Session) ApplicationCreate(ap *Application) (st *Application, err error) {
|
func (s *Session) ApplicationCreate(ap *Application) (st *Application, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
|
}{ap.Name, ap.Description}
|
||||||
}{ap.Name, ap.Description, ap.RedirectURIs}
|
|
||||||
|
|
||||||
body, err := s.RequestWithBucketID("POST", EndpointOAuth2Applications, data, EndpointOAuth2Applications)
|
body, err := s.RequestWithBucketID("POST", EndpointOAuth2Applications, data, EndpointOAuth2Applications)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -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) {
|
func (s *Session) ApplicationUpdate(appID string, ap *Application) (st *Application, err error) {
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
RedirectURIs *[]string `json:"redirect_uris,omitempty"`
|
}{ap.Name, ap.Description}
|
||||||
}{ap.Name, ap.Description, ap.RedirectURIs}
|
|
||||||
|
|
||||||
body, err := s.RequestWithBucketID("PUT", EndpointOAuth2Application(appID), data, EndpointOAuth2Application(""))
|
body, err := s.RequestWithBucketID("PUT", EndpointOAuth2Application(appID), data, EndpointOAuth2Application(""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
68
structs.go
68
structs.go
|
@ -128,6 +128,28 @@ type Session struct {
|
||||||
wsMutex sync.Mutex
|
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
|
// UserConnection is a Connection returned from the UserConnections endpoint
|
||||||
type UserConnection struct {
|
type UserConnection struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
@ -191,36 +213,38 @@ type ICEServer struct {
|
||||||
Credential string `json:"credential"`
|
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.
|
// A Invite stores all data related to a specific Discord Guild or Channel invite.
|
||||||
type Invite struct {
|
type Invite struct {
|
||||||
Guild *Guild `json:"guild"`
|
Guild *Guild `json:"guild"`
|
||||||
Channel *Channel `json:"channel"`
|
Channel *Channel `json:"channel"`
|
||||||
Inviter *User `json:"inviter"`
|
Inviter *User `json:"inviter"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
MaxAge int `json:"max_age"`
|
MaxAge int `json:"max_age"`
|
||||||
Uses int `json:"uses"`
|
Uses int `json:"uses"`
|
||||||
MaxUses int `json:"max_uses"`
|
MaxUses int `json:"max_uses"`
|
||||||
Revoked bool `json:"revoked"`
|
Revoked bool `json:"revoked"`
|
||||||
Temporary bool `json:"temporary"`
|
Temporary bool `json:"temporary"`
|
||||||
Unique bool `json:"unique"`
|
Unique bool `json:"unique"`
|
||||||
TargetUser *User `json:"target_user"`
|
TargetUser *User `json:"target_user"`
|
||||||
TargetUserType TargetUserType `json:"target_user_type"`
|
TargetType InviteTargetType `json:"target_type"`
|
||||||
|
TargetApplication *Application `json:"target_application"`
|
||||||
|
|
||||||
// will only be filled when using InviteWithCounts
|
// will only be filled when using InviteWithCounts
|
||||||
ApproximatePresenceCount int `json:"approximate_presence_count"`
|
ApproximatePresenceCount int `json:"approximate_presence_count"`
|
||||||
ApproximateMemberCount int `json:"approximate_member_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
|
// ChannelType is the type of a Channel
|
||||||
type ChannelType int
|
type ChannelType int
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue