Added user notes (#361)
* Added user notes * Added note websocket event (thanks iopred :D) * Added ready event (thanks again, iopred) * Renamed function
This commit is contained in:
parent
2a4314dbdc
commit
43c8b518ad
4 changed files with 46 additions and 0 deletions
|
@ -63,6 +63,7 @@ var (
|
|||
EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
|
||||
EndpointUserDevices = func(uID string) string { return EndpointUsers + uID + "/devices" }
|
||||
EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }
|
||||
EndpointUserNotes = func(uID string) string { return EndpointUsers + "@me/notes/" + uID }
|
||||
|
||||
EndpointGuild = func(gID string) string { return EndpointGuilds + gID }
|
||||
EndpointGuildInivtes = func(gID string) string { return EndpointGuilds + gID + "/invites" }
|
||||
|
|
|
@ -45,6 +45,7 @@ const (
|
|||
resumedEventType = "RESUMED"
|
||||
typingStartEventType = "TYPING_START"
|
||||
userGuildSettingsUpdateEventType = "USER_GUILD_SETTINGS_UPDATE"
|
||||
userNoteUpdateEventType = "USER_NOTE_UPDATE"
|
||||
userSettingsUpdateEventType = "USER_SETTINGS_UPDATE"
|
||||
userUpdateEventType = "USER_UPDATE"
|
||||
voiceServerUpdateEventType = "VOICE_SERVER_UPDATE"
|
||||
|
@ -791,6 +792,26 @@ func (eh userGuildSettingsUpdateEventHandler) Handle(s *Session, i interface{})
|
|||
}
|
||||
}
|
||||
|
||||
// userNoteUpdateEventHandler is an event handler for UserNoteUpdate events.
|
||||
type userNoteUpdateEventHandler func(*Session, *UserNoteUpdate)
|
||||
|
||||
// Type returns the event type for UserNoteUpdate events.
|
||||
func (eh userNoteUpdateEventHandler) Type() string {
|
||||
return userNoteUpdateEventType
|
||||
}
|
||||
|
||||
// New returns a new instance of UserNoteUpdate.
|
||||
func (eh userNoteUpdateEventHandler) New() interface{} {
|
||||
return &UserNoteUpdate{}
|
||||
}
|
||||
|
||||
// Handle is the handler for UserNoteUpdate events.
|
||||
func (eh userNoteUpdateEventHandler) Handle(s *Session, i interface{}) {
|
||||
if t, ok := i.(*UserNoteUpdate); ok {
|
||||
eh(s, t)
|
||||
}
|
||||
}
|
||||
|
||||
// userSettingsUpdateEventHandler is an event handler for UserSettingsUpdate events.
|
||||
type userSettingsUpdateEventHandler func(*Session, *UserSettingsUpdate)
|
||||
|
||||
|
@ -951,6 +972,8 @@ func handlerForInterface(handler interface{}) EventHandler {
|
|||
return typingStartEventHandler(v)
|
||||
case func(*Session, *UserGuildSettingsUpdate):
|
||||
return userGuildSettingsUpdateEventHandler(v)
|
||||
case func(*Session, *UserNoteUpdate):
|
||||
return userNoteUpdateEventHandler(v)
|
||||
case func(*Session, *UserSettingsUpdate):
|
||||
return userSettingsUpdateEventHandler(v)
|
||||
case func(*Session, *UserUpdate):
|
||||
|
@ -999,6 +1022,7 @@ func init() {
|
|||
registerInterfaceProvider(resumedEventHandler(nil))
|
||||
registerInterfaceProvider(typingStartEventHandler(nil))
|
||||
registerInterfaceProvider(userGuildSettingsUpdateEventHandler(nil))
|
||||
registerInterfaceProvider(userNoteUpdateEventHandler(nil))
|
||||
registerInterfaceProvider(userSettingsUpdateEventHandler(nil))
|
||||
registerInterfaceProvider(userUpdateEventHandler(nil))
|
||||
registerInterfaceProvider(voiceServerUpdateEventHandler(nil))
|
||||
|
|
|
@ -48,6 +48,7 @@ type Ready struct {
|
|||
UserGuildSettings []*UserGuildSettings `json:"user_guild_settings"`
|
||||
Relationships []*Relationship `json:"relationships"`
|
||||
Presences []*Presence `json:"presences"`
|
||||
Notes map[string]string `json:"notes"`
|
||||
}
|
||||
|
||||
// ChannelCreate is the data for a ChannelCreate event.
|
||||
|
@ -227,6 +228,12 @@ type UserGuildSettingsUpdate struct {
|
|||
*UserGuildSettings
|
||||
}
|
||||
|
||||
// UserNoteUpdate is the data for a UserNoteUpdate event.
|
||||
type UserNoteUpdate struct {
|
||||
ID string `json:"id"`
|
||||
Note string `json:"note"`
|
||||
}
|
||||
|
||||
// VoiceServerUpdate is the data for a VoiceServerUpdate event.
|
||||
type VoiceServerUpdate struct {
|
||||
Token string `json:"token"`
|
||||
|
|
14
restapi.go
14
restapi.go
|
@ -1846,6 +1846,20 @@ func (s *Session) MessageReactions(channelID, messageID, emojiID string, limit i
|
|||
return
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Functions specific to user notes
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
// UserNoteSet sets the note for a specific user.
|
||||
func (s *Session) UserNoteSet(userID string, message string) (err error) {
|
||||
data := struct {
|
||||
Note string `json:"note"`
|
||||
}{message}
|
||||
|
||||
_, err = s.RequestWithBucketID("PUT", EndpointUserNotes(userID), data, EndpointUserNotes(""))
|
||||
return
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Functions specific to Discord Relationships (Friends list)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue