Skip to content

Commit

Permalink
Merge branch 'master' into role-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
FedorLap2006 authored Jan 3, 2024
2 parents 0e15f35 + 1ffd696 commit 5a9bdf8
Show file tree
Hide file tree
Showing 18 changed files with 565 additions and 107 deletions.
28 changes: 25 additions & 3 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ type SelectMenuOption struct {
Default bool `json:"default"`
}

// SelectMenuDefaultValueType represents the type of an entity selected by default in auto-populated select menus.
type SelectMenuDefaultValueType string

// SelectMenuDefaultValue types.
const (
SelectMenuDefaultValueUser SelectMenuDefaultValueType = "user"
SelectMenuDefaultValueRole SelectMenuDefaultValueType = "role"
SelectMenuDefaultValueChannel SelectMenuDefaultValueType = "channel"
)

// SelectMenuDefaultValue represents an entity selected by default in auto-populated select menus.
type SelectMenuDefaultValue struct {
// ID of the entity.
ID string `json:"id"`
// Type of the entity.
Type SelectMenuDefaultValueType `json:"type"`
}

// SelectMenuType represents select menu type.
type SelectMenuType ComponentType

Expand All @@ -198,9 +216,13 @@ type SelectMenu struct {
MinValues *int `json:"min_values,omitempty"`
// This value determines the maximal amount of selected items in the menu.
// If MaxValues or MinValues are greater than one then the user can select multiple items in the component.
MaxValues int `json:"max_values,omitempty"`
Options []SelectMenuOption `json:"options,omitempty"`
Disabled bool `json:"disabled"`
MaxValues int `json:"max_values,omitempty"`
// List of default values for auto-populated select menus.
// NOTE: Number of entries should be in the range defined by MinValues and MaxValues.
DefaultValues []SelectMenuDefaultValue `json:"default_values,omitempty"`

Options []SelectMenuOption `json:"options,omitempty"`
Disabled bool `json:"disabled"`

// NOTE: Can only be used in SelectMenu with Channel menu type.
ChannelTypes []ChannelType `json:"channel_types,omitempty"`
Expand Down
31 changes: 16 additions & 15 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
const VERSION = "0.27.0"
const VERSION = "0.27.1"

// New creates a new Discord session with provided token.
// If the token is for a bot, it must be prefixed with "Bot "
Expand All @@ -33,20 +33,21 @@ func New(token string) (s *Session, err error) {

// Create an empty Session interface.
s = &Session{
State: NewState(),
Ratelimiter: NewRatelimiter(),
StateEnabled: true,
Compress: true,
ShouldReconnectOnError: true,
ShouldRetryOnRateLimit: true,
ShardID: 0,
ShardCount: 1,
MaxRestRetries: 3,
Client: &http.Client{Timeout: (20 * time.Second)},
Dialer: websocket.DefaultDialer,
UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
sequence: new(int64),
LastHeartbeatAck: time.Now().UTC(),
State: NewState(),
Ratelimiter: NewRatelimiter(),
StateEnabled: true,
Compress: true,
ShouldReconnectOnError: true,
ShouldReconnectVoiceOnSessionError: true,
ShouldRetryOnRateLimit: true,
ShardID: 0,
ShardCount: 1,
MaxRestRetries: 3,
Client: &http.Client{Timeout: (20 * time.Second)},
Dialer: websocket.DefaultDialer,
UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
sequence: new(int64),
LastHeartbeatAck: time.Now().UTC(),
}

// Initialize the Identify Package with defaults
Expand Down
2 changes: 1 addition & 1 deletion docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You must already have a working Go environment setup to use DiscordGo. If you
are new to Go and have not yet installed and tested it on your computer then
please visit [this page](https://golang.org/doc/install) first then I highly
recommend you walk though [A Tour of Go](https://tour.golang.org/welcome/1) to
help get your familiar with the Go language. Also checkout the relevent Go plugin
help get your familiar with the Go language. Also checkout the relevant Go plugin
for your editor — they are hugely helpful when developing Go code.

* Vim — [vim-go](https://github.com/fatih/vim-go)
Expand Down
15 changes: 8 additions & 7 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,15 @@ var (
EndpointCDNBanners = EndpointCDN + "banners/"
EndpointCDNGuilds = EndpointCDN + "guilds/"
EndpointCDNRoleIcons = EndpointCDN + "role-icons/"
EndpointRoleIcon = func(rID, cID string) string {
return EndpointCDNRoleIcons + rID + "/" + cID + ".png"
}

EndpointVoice = EndpointAPI + "/voice/"
EndpointVoiceRegions = EndpointVoice + "regions"

EndpointUser = func(uID string) string { return EndpointUsers + uID }
EndpointUserAvatar = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".png" }
EndpointUserAvatarAnimated = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".gif" }
EndpointDefaultUserAvatar = func(uDiscriminator string) string {
uDiscriminatorInt, _ := strconv.Atoi(uDiscriminator)
return EndpointCDN + "embed/avatars/" + strconv.Itoa(uDiscriminatorInt%5) + ".png"
EndpointDefaultUserAvatar = func(idx int) string {
return EndpointCDN + "embed/avatars/" + strconv.Itoa(idx) + ".png"
}
EndpointUserBanner = func(uID, cID string) string {
return EndpointCDNBanners + uID + "/" + cID + ".png"
Expand Down Expand Up @@ -108,7 +104,8 @@ var (
EndpointGuildScheduledEvents = func(gID string) string { return EndpointGuilds + gID + "/scheduled-events" }
EndpointGuildScheduledEvent = func(gID, eID string) string { return EndpointGuilds + gID + "/scheduled-events/" + eID }
EndpointGuildScheduledEventUsers = func(gID, eID string) string { return EndpointGuildScheduledEvent(gID, eID) + "/users" }
EndpointGuildTemplate = func(tID string) string { return EndpointGuilds + "/templates/" + tID }
EndpointGuildOnboarding = func(gID string) string { return EndpointGuilds + gID + "/onboarding" }
EndpointGuildTemplate = func(tID string) string { return EndpointGuilds + "templates/" + tID }
EndpointGuildTemplates = func(gID string) string { return EndpointGuilds + gID + "/templates" }
EndpointGuildTemplateSync = func(gID, tID string) string { return EndpointGuilds + gID + "/templates/" + tID }
EndpointGuildMemberAvatar = func(gId, uID, aID string) string {
Expand All @@ -118,6 +115,10 @@ var (
return EndpointCDNGuilds + gId + "/users/" + uID + "/avatars/" + aID + ".gif"
}

EndpointRoleIcon = func(rID, hash string) string {
return EndpointCDNRoleIcons + rID + "/" + hash + ".png"
}

EndpointChannel = func(cID string) string { return EndpointChannels + cID }
EndpointChannelThreads = func(cID string) string { return EndpointChannel(cID) + "/threads" }
EndpointChannelActiveThreads = func(cID string) string { return EndpointChannelThreads(cID) + "/active" }
Expand Down
24 changes: 24 additions & 0 deletions eventhandlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,8 @@ type AutoModerationActionExecution struct {
MatchedKeyword string `json:"matched_keyword"`
MatchedContent string `json:"matched_content"`
}

// GuildAuditLogEntryCreate is the data for a GuildAuditLogEntryCreate event.
type GuildAuditLogEntryCreate struct {
*AuditLogEntry
}
2 changes: 1 addition & 1 deletion examples/modals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This example demonstrates how to utilize DiscordGo to send and process text
inputs in modals. If you have not read `slash_commands` and `components`
examples yet it is recommended to do so before proceesing. As this example
examples yet it is recommended to do so before proceeding. As this example
is built using interactions and Slash Commands.

**Join [Discord Gophers](https://discord.gg/0f1SbxBZjYoCtNPP)
Expand Down
8 changes: 5 additions & 3 deletions interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,10 @@ type InteractionData interface {

// ApplicationCommandInteractionData contains the data of application command interaction.
type ApplicationCommandInteractionData struct {
ID string `json:"id"`
Name string `json:"name"`
Resolved *ApplicationCommandInteractionDataResolved `json:"resolved"`
ID string `json:"id"`
Name string `json:"name"`
CommandType ApplicationCommandType `json:"type"`
Resolved *ApplicationCommandInteractionDataResolved `json:"resolved"`

// Slash command options
Options []*ApplicationCommandInteractionDataOption `json:"options"`
Expand Down Expand Up @@ -553,6 +554,7 @@ type InteractionResponseData struct {
Embeds []*MessageEmbed `json:"embeds"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
Files []*File `json:"-"`
Attachments *[]*MessageAttachment `json:"attachments,omitempty"`

// NOTE: only MessageFlagsSuppressEmbeds and MessageFlagsEphemeral can be set.
Flags MessageFlags `json:"flags,omitempty"`
Expand Down
34 changes: 26 additions & 8 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ const (
MessageFlagsLoading MessageFlags = 1 << 7
// MessageFlagsFailedToMentionSomeRolesInThread this message failed to mention some roles and add their members to the thread.
MessageFlagsFailedToMentionSomeRolesInThread MessageFlags = 1 << 8
// MessageFlagsSuppressNotifications this message will not trigger push and desktop notifications.
MessageFlagsSuppressNotifications MessageFlags = 1 << 12
// MessageFlagsIsVoiceMessage this message is a voice message.
MessageFlagsIsVoiceMessage MessageFlags = 1 << 13
)

// File stores info about files you e.g. send in messages.
Expand All @@ -233,6 +237,8 @@ type MessageSend struct {
Files []*File `json:"-"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
Reference *MessageReference `json:"message_reference,omitempty"`
StickerIDs []string `json:"sticker_ids"`
Flags MessageFlags `json:"flags,omitempty"`

// TODO: Remove this when compatibility is not required.
File *File `json:"-"`
Expand Down Expand Up @@ -460,20 +466,32 @@ type MessageApplication struct {

// MessageReference contains reference data sent with crossposted messages
type MessageReference struct {
MessageID string `json:"message_id"`
ChannelID string `json:"channel_id,omitempty"`
GuildID string `json:"guild_id,omitempty"`
MessageID string `json:"message_id"`
ChannelID string `json:"channel_id,omitempty"`
GuildID string `json:"guild_id,omitempty"`
FailIfNotExists *bool `json:"fail_if_not_exists,omitempty"`
}

// Reference returns MessageReference of given message
func (m *Message) Reference() *MessageReference {
func (m *Message) reference(failIfNotExists bool) *MessageReference {
return &MessageReference{
GuildID: m.GuildID,
ChannelID: m.ChannelID,
MessageID: m.ID,
GuildID: m.GuildID,
ChannelID: m.ChannelID,
MessageID: m.ID,
FailIfNotExists: &failIfNotExists,
}
}

// Reference returns a MessageReference of the given message.
func (m *Message) Reference() *MessageReference {
return m.reference(true)
}

// SoftReference returns a MessageReference of the given message.
// If the message doesn't exist it will instead be sent as a non-reply message.
func (m *Message) SoftReference() *MessageReference {
return m.reference(false)
}

// ContentWithMentionsReplaced will replace all @<id> mentions with the
// username of the mention.
func (m *Message) ContentWithMentionsReplaced() (content string) {
Expand Down
Loading

0 comments on commit 5a9bdf8

Please sign in to comment.