Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/disgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Disgo interface {

GetTemplate(code string) (*GuildTemplate, restclient.RestError)
CreateGuildFromTemplate(templateCode string, createGuildFromTemplate CreateGuildFromTemplate) (*Guild, restclient.RestError)

GetAllStickerPacks() ([]*StickerPack, restclient.RestError)
}

// GetOS returns the simplified version of the operating system for sending to Discord in the IdentifyCommandDataProperties.OS payload
Expand Down
15 changes: 15 additions & 0 deletions api/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,21 @@ func (g *Guild) DeleteTemplate(code string) (*GuildTemplate, restclient.RestErro
return g.Disgo.RestClient().DeleteGuildTemplate(g.ID, code)
}

// UpdateSticker updates the MessageSticker with the given Snowflake id with the UpdateMessageSticker new sticker
func (g *Guild) UpdateSticker(stickerID Snowflake, newSticker UpdateMessageSticker) (*MessageSticker, restclient.RestError) {
return g.Disgo.RestClient().UpdateGuildSticker(g.ID, stickerID, newSticker)
}

// DeleteSticker deletes the sticker with the given Snowflake id
func (g *Guild) DeleteSticker(stickerID Snowflake) restclient.RestError {
return g.Disgo.RestClient().DeleteGuildSticker(g.ID, stickerID)
}

// GetStickers returns all the stickers for this Guild
func (g *Guild) GetStickers() ([]*MessageSticker, restclient.RestError) {
return g.Disgo.RestClient().GetGuildStickers(g.ID)
}

// PartialGuild is returned on the restclient.GetGuilds route
type PartialGuild struct {
ID Snowflake `json:"id"`
Expand Down
62 changes: 59 additions & 3 deletions api/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"errors"
"strings"
"time"

"github.com/DisgoOrg/restclient"
Expand Down Expand Up @@ -146,6 +147,16 @@ type MessageApplication struct {
// MessageStickerFormatType is the Format type of MessageSticker
type MessageStickerFormatType int

// MessageStickerType is the Type of a MessageSticker
type MessageStickerType int

// Constants for MessageStickerType
//goland:noinspection GoUnusedConst
const (
MessageStickerTypeStandard = iota + 1
MessageStickerTypeGuild
)

// Constants for MessageStickerFormatType
//goland:noinspection GoUnusedConst
const (
Expand All @@ -156,12 +167,35 @@ const (

// MessageSticker is a sticker sent with a Message
type MessageSticker struct {
Disgo Disgo `json:"-"`
ID Snowflake `json:"id"`
PackID Snowflake `json:"pack_id"`
PackID Snowflake `json:"pack_id,omitempty"`
GuildID Snowflake `json:"guild_id,omitempty"`
Uploader User `json:"user,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Tags *string `json:"tags"`
Description string `json:"description,omitempty"`
RawTags *string `json:"tags,omitempty"`
FormatType MessageStickerFormatType `json:"format_type"`
Type MessageStickerType `json:"type,omitempty"`
Available bool `json:"available,omitempty"`
SortValue int `json:"sort_value,omitempty"`
}

// UpdateMessageSticker is used to update a sticker in a Guild
type UpdateMessageSticker struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Tags string `json:"tags"`
}

// Tags is used to get the tags for a sticker
func (m *MessageSticker) Tags() []string {
return strings.Split(*m.RawTags, " ")
}

// Guild is used to get the guild that created a sticker
func (m *MessageSticker) Guild() *Guild {
return m.Disgo.Cache().Guild(m.GuildID)
}

// Message is a struct for messages sent in discord text-based channels
Expand Down Expand Up @@ -425,6 +459,28 @@ func (m *Message) SelectMenuByID(customID string) *SelectMenu {
return nil
}

// StickerByName is used to get the first sticker with the matching name, or nil
func (m *Message) StickerByName(name string) *MessageSticker {
for _, sticker := range m.Stickers {
if sticker.Name == name {
return sticker
}
}

return nil
}

// StickerByID is used to get the sticker with the matching Snowflake id, or nil
func (m *Message) StickerByID(id Snowflake) *MessageSticker {
for _, sticker := range m.Stickers {
if sticker.ID == id {
return sticker
}
}

return nil
}

// IsEphemeral returns true if the Message has MessageFlagEphemeral
func (m *Message) IsEphemeral() bool {
return m.Flags.Has(MessageFlagEphemeral)
Expand Down
6 changes: 6 additions & 0 deletions api/restclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ type RestClient interface {
SyncGuildTemplate(guildID Snowflake, templateCode string) (*GuildTemplate, restclient.RestError)
UpdateGuildTemplate(guildID Snowflake, templateCode string, updateGuildTemplate UpdateGuildTemplate) (*GuildTemplate, restclient.RestError)
DeleteGuildTemplate(guildID Snowflake, templateCode string) (*GuildTemplate, restclient.RestError)

DeleteGuildSticker(guildID Snowflake, stickerID Snowflake) restclient.RestError
UpdateGuildSticker(guildID Snowflake, stickerID Snowflake, updateMessageSticker UpdateMessageSticker) (*MessageSticker, restclient.RestError)
GetGuildStickers(guildID Snowflake) ([]*MessageSticker, restclient.RestError)

GetAllStickerPacks() ([]*StickerPack, restclient.RestError)
}
12 changes: 12 additions & 0 deletions api/sticker_pack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package api

// StickerPack is a collection of MessageSticker(s) (https://discord.com/developers/docs/resources/sticker#sticker-pack-object)
type StickerPack struct {
ID Snowflake `json:"id"`
Stickers []*MessageSticker `json:"stickers"`
Name string `json:"name"`
SkuID Snowflake `json:"sku_id"`
CoverStickerID Snowflake `json:"cover_sticker_id,omitempty"`
Description string `json:"description"`
BannerAssetID Snowflake `json:"banner_asset_id"`
}
5 changes: 5 additions & 0 deletions internal/disgo_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ type DisgoImpl struct {
largeThreshold int
}

// GetAllStickerPacks returns all the api.StickerPack(s) available to nitro subscribers
func (d *DisgoImpl) GetAllStickerPacks() ([]*api.StickerPack, restclient.RestError) {
return make([]*api.StickerPack, 0), nil
}

// Logger returns the logger instance disgo uses
func (d *DisgoImpl) Logger() log.Logger {
return d.logger
Expand Down
21 changes: 21 additions & 0 deletions internal/restclient_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ type restClientImpl struct {
disgo api.Disgo
}

// GetAllStickerPacks returns all the api.StickerPack(s) available to nitro subscribers
func (r *restClientImpl) GetAllStickerPacks() ([]*api.StickerPack, restclient.RestError) {
return make([]*api.StickerPack, 0), nil
}

// GetGuildStickers returns all the stickers for the given api.Guild
func (r *restClientImpl) GetGuildStickers(guildID api.Snowflake) ([]*api.MessageSticker, restclient.RestError) {
return make([]*api.MessageSticker, 0), nil
}

// DeleteGuildSticker the sticker with the given api.Snowflake id in the given api.Guild
func (r *restClientImpl) DeleteGuildSticker(guildID api.Snowflake, stickerID api.Snowflake) restclient.RestError {
return nil
}

// UpdateGuildSticker updates the api.MessageSticker in the given api.Guild
// with the given api.Snowflake id using the api.UpdateMessageSticker new sticker
func (r *restClientImpl) UpdateGuildSticker(guildID api.Snowflake, stickerID api.Snowflake, updateMessageSticker api.UpdateMessageSticker) (*api.MessageSticker, restclient.RestError) {
return nil, nil
}

// Disgo returns the api.Disgo instance
func (r *restClientImpl) Disgo() api.Disgo {
return r.disgo
Expand Down