Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 434deda

Browse files
author
jonas747
committed
various tweaks and api cleanups
1 parent 1f5def1 commit 434deda

File tree

3 files changed

+62
-21
lines changed

3 files changed

+62
-21
lines changed

events.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ type GuildMemberAdd struct {
150150
*Member
151151
}
152152

153+
func (e *GuildMemberAdd) GetGuildID() int64 {
154+
return e.GuildID
155+
}
156+
153157
// GuildMemberUpdate is the data for a GuildMemberUpdate event.
154158
type GuildMemberUpdate struct {
155159
*Member
@@ -427,5 +431,5 @@ type InviteDelete struct {
427431
}
428432

429433
type InteractionCreate struct {
430-
*Interaction
434+
Interaction
431435
}

restapi.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,17 +2590,9 @@ func (s *Session) GetOriginalInteractionResponse(applicationID int64, token stri
25902590
return
25912591
}
25922592

2593-
type EditWebhookMessageRequest struct {
2594-
Content *string `json:"content,omitempty"` // the message contents (up to 2000 characters)
2595-
Embeds *[]*MessageEmbed `json:"embeds,omitempty"` // of up to 10 embed objects embedded rich content
2596-
AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"` // object allowed mentions for the message
2597-
// File file `json:"file"` // the contents of the file being sent/edited
2598-
// PayloadJson string `json:"payload_json"` // See message create
2599-
}
2600-
26012593
// Edits the initial Interaction response. Functions the same as Edit Webhook Message.
26022594
// PATCH /webhooks/{application.id}/{interaction.token}/messages/@original
2603-
func (s *Session) EditOriginalInteractionResponse(applicationID int64, token string, data *EditWebhookMessageRequest) (st *Message, err error) {
2595+
func (s *Session) EditOriginalInteractionResponse(applicationID int64, token string, data *WebhookParams) (st *Message, err error) {
26042596
body, err := s.RequestWithBucketID("PATCH", EndpointInteractionOriginalMessage(applicationID, token), data, EndpointInteractionOriginalMessage(0, ""))
26052597
if err != nil {
26062598
return
@@ -2631,7 +2623,7 @@ func (s *Session) CreateFollowupMessage(applicationID int64, token string, data
26312623

26322624
// EditFollowupMessage Edits a followup message for an Interaction. Functions the same as Edit Webhook Message.
26332625
// PATCH /webhooks/{application.id}/{interaction.token}/messages/{message.id}
2634-
func (s *Session) EditFollowupMessage(applicationID int64, token string, messageID int64, data *EditWebhookMessageRequest) (st *Message, err error) {
2626+
func (s *Session) EditFollowupMessage(applicationID int64, token string, messageID int64, data *WebhookParams) (st *Message, err error) {
26352627
body, err := s.RequestWithBucketID("PATCH", EndpointInteractionFollowupMessage(applicationID, token, messageID), data, EndpointInteractionFollowupMessage(0, "", 0))
26362628
if err != nil {
26372629
return

structs.go

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,16 +1212,61 @@ const (
12121212

12131213
// Interaction is the base "thing" that is sent when a user invokes a command, and is the same for Slash Commands and other future interaction types.
12141214
type Interaction struct {
1215-
ID int64 `json:"id,string"` // id of the interaction
1216-
ApplicationID int64 `json:"application_id,string"` // id of the application this interaction is for
1217-
Kind InteractionType `json:"type"` // the type of interaction
1218-
Data *ApplicationCommandInteractionData `json:"data"` // the command data payload
1219-
GuildID int64 `json:"guild_id,string"` // the guild it was sent from
1220-
ChannelID int64 `json:"channel_id,string"` // the channel it was sent from
1221-
Member *Member `json:"member"` // member object guild member data for the invoking user, including permissions
1222-
User *User `json:"user"` // object user object for the invoking user, if invoked in a DM
1223-
Token string `json:"token"` // a continuation token for responding to the interaction
1224-
Version int `json:"version"` // read-only property, always
1215+
ID int64 `json:"id,string"` // id of the interaction
1216+
ApplicationID int64 `json:"application_id,string"` // id of the application this interaction is for
1217+
Kind InteractionType `json:"type"` // the type of interaction
1218+
GuildID int64 `json:"guild_id,string"` // the guild it was sent from
1219+
ChannelID int64 `json:"channel_id,string"` // the channel it was sent from
1220+
Member *Member `json:"member"` // member object guild member data for the invoking user, including permissions
1221+
User *User `json:"user"` // object user object for the invoking user, if invoked in a DM
1222+
Token string `json:"token"` // a continuation token for responding to the interaction
1223+
Version int `json:"version"` // read-only property, always
1224+
1225+
DataCommand *ApplicationCommandInteractionData
1226+
}
1227+
1228+
type interactionTemp struct {
1229+
ID int64 `json:"id,string"` // id of the interaction
1230+
ApplicationID int64 `json:"application_id,string"` // id of the application this interaction is for
1231+
Kind InteractionType `json:"type"` // the type of interaction
1232+
Data json.RawMessage `json:"data"` // data payload
1233+
GuildID int64 `json:"guild_id,string"` // the guild it was sent from
1234+
ChannelID int64 `json:"channel_id,string"` // the channel it was sent from
1235+
Member *Member `json:"member"` // member object guild member data for the invoking user, including permissions
1236+
User *User `json:"user"` // object user object for the invoking user, if invoked in a DM
1237+
Token string `json:"token"` // a continuation token for responding to the interaction
1238+
Version int `json:"version"` // read-only property, always
1239+
}
1240+
1241+
// Interaction requires custom unmarshal logic because of the Data field being dependant on the interaction type
1242+
func (a *Interaction) UnmarshalJSON(b []byte) error {
1243+
var temp *interactionTemp
1244+
err := json.Unmarshal(b, &temp)
1245+
if err != nil {
1246+
return err
1247+
}
1248+
1249+
*a = Interaction{
1250+
ID: temp.ID,
1251+
ApplicationID: temp.ApplicationID,
1252+
Kind: temp.Kind,
1253+
GuildID: temp.GuildID,
1254+
ChannelID: temp.ChannelID,
1255+
Member: temp.Member,
1256+
User: temp.User,
1257+
Token: temp.Token,
1258+
Version: temp.Version,
1259+
}
1260+
1261+
switch temp.Kind {
1262+
case InteractionTypeApplicationCommand:
1263+
err = json.Unmarshal(temp.Data, &a.DataCommand)
1264+
if err != nil {
1265+
return err
1266+
}
1267+
}
1268+
1269+
return nil
12251270
}
12261271

12271272
type InteractionType int

0 commit comments

Comments
 (0)