Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into feature/premium-button
Browse files Browse the repository at this point in the history
# Conflicts:
#	discord/component.go
  • Loading branch information
sebm253 committed Jun 15, 2024
2 parents 0481fa7 + 7380d44 commit a51af11
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 17 deletions.
3 changes: 3 additions & 0 deletions discord/auto_moderation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type AutoModerationEventType int

const (
AutoModerationEventTypeMessageSend AutoModerationEventType = iota + 1
AutoModerationEventTypeMemberUpdate
)

type AutoModerationTriggerType int
Expand All @@ -20,6 +21,7 @@ const (
AutoModerationTriggerTypeSpam
AutoModerationTriggerTypeKeywordPresent
AutoModerationTriggerTypeMentionSpam
AutoModerationTriggerTypeMemberProfile
)

type AutoModerationTriggerMetadata struct {
Expand All @@ -45,6 +47,7 @@ const (
AutoModerationActionTypeBlockMessage AutoModerationActionType = iota + 1
AutoModerationActionTypeSendAlertMessage
AutoModerationActionTypeTimeout
AutoModerationActionTypeBlockMemberInteraction
)

type AutoModerationAction struct {
Expand Down
90 changes: 90 additions & 0 deletions discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ func (u *UnmarshalChannel) UnmarshalJSON(data []byte) error {
err = json.Unmarshal(data, &v)
channel = v

case ChannelTypeGroupDM:
var v GroupDMChannel
err = json.Unmarshal(data, &v)
channel = v

case ChannelTypeGuildCategory:
var v GuildCategoryChannel
err = json.Unmarshal(data, &v)
Expand Down Expand Up @@ -423,6 +428,91 @@ func (c DMChannel) CreatedAt() time.Time {
func (DMChannel) channel() {}
func (DMChannel) messageChannel() {}

var (
_ Channel = (*GroupDMChannel)(nil)
_ MessageChannel = (*GroupDMChannel)(nil)
)

type GroupDMChannel struct {
id snowflake.ID
ownerID *snowflake.ID
name string
lastPinTimestamp *time.Time
lastMessageID *snowflake.ID
icon *string
}

func (c *GroupDMChannel) UnmarshalJSON(data []byte) error {
var v groupDMChannel
if err := json.Unmarshal(data, &v); err != nil {
return err
}

c.id = v.ID
c.ownerID = v.OwnerID
c.name = v.Name
c.lastPinTimestamp = v.LastPinTimestamp
c.lastMessageID = v.LastMessageID
c.icon = v.Icon
return nil
}

func (c GroupDMChannel) MarshalJSON() ([]byte, error) {
return json.Marshal(groupDMChannel{
ID: c.id,
Type: c.Type(),
OwnerID: c.ownerID,
Name: c.name,
LastPinTimestamp: c.lastPinTimestamp,
LastMessageID: c.lastMessageID,
Icon: c.icon,
})
}

func (c GroupDMChannel) String() string {
return channelString(c)
}

func (c GroupDMChannel) ID() snowflake.ID {
return c.id
}

func (GroupDMChannel) Type() ChannelType {
return ChannelTypeGroupDM
}

func (c GroupDMChannel) OwnerID() *snowflake.ID {
return c.ownerID
}

func (c GroupDMChannel) Name() string {
return c.name
}

func (c GroupDMChannel) LastPinTimestamp() *time.Time {
return c.lastPinTimestamp
}

func (c GroupDMChannel) LastMessageID() *snowflake.ID {
return c.lastMessageID
}

func (c GroupDMChannel) CreatedAt() time.Time {
return c.id.Time()
}

// IconURL returns the icon URL of this group DM or nil if not set
func (c GroupDMChannel) IconURL(opts ...CDNOpt) *string {
if c.icon == nil {
return nil
}
url := formatAssetURL(ChannelIcon, opts, c.id, *c.icon)
return &url
}

func (GroupDMChannel) channel() {}
func (GroupDMChannel) messageChannel() {}

var (
_ Channel = (*GuildVoiceChannel)(nil)
_ GuildChannel = (*GuildVoiceChannel)(nil)
Expand Down
10 changes: 10 additions & 0 deletions discord/channels_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ type dmChannel struct {
LastPinTimestamp *time.Time `json:"last_pin_timestamp"`
}

type groupDMChannel struct {
ID snowflake.ID `json:"id"`
Type ChannelType `json:"type"`
OwnerID *snowflake.ID `json:"owner_id"`
Name string `json:"name"`
LastPinTimestamp *time.Time `json:"last_pin_timestamp"`
LastMessageID *snowflake.ID `json:"last_message_id"`
Icon *string `json:"icon"`
}

type guildTextChannel struct {
ID snowflake.ID `json:"id"`
Type ChannelType `json:"type"`
Expand Down
35 changes: 29 additions & 6 deletions discord/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,32 +250,55 @@ func NewButton(style ButtonStyle, label string, customID string, url string, sku

// NewPrimaryButton creates a new ButtonComponent with ButtonStylePrimary & the provided parameters
func NewPrimaryButton(label string, customID string) ButtonComponent {
return NewButton(ButtonStylePrimary, label, customID, "", 0)
return ButtonComponent{
Style: ButtonStylePrimary,
Label: label,
CustomID: customID,
}
}

// NewSecondaryButton creates a new ButtonComponent with ButtonStyleSecondary & the provided parameters
func NewSecondaryButton(label string, customID string) ButtonComponent {
return NewButton(ButtonStyleSecondary, label, customID, "", 0)
return ButtonComponent{
Style: ButtonStyleSecondary,
Label: label,
CustomID: customID,
}
}

// NewSuccessButton creates a new ButtonComponent with ButtonStyleSuccess & the provided parameters
func NewSuccessButton(label string, customID string) ButtonComponent {
return NewButton(ButtonStyleSuccess, label, customID, "", 0)
return ButtonComponent{
Style: ButtonStyleSuccess,
Label: label,
CustomID: customID,
}
}

// NewDangerButton creates a new ButtonComponent with ButtonStyleDanger & the provided parameters
func NewDangerButton(label string, customID string) ButtonComponent {
return NewButton(ButtonStyleDanger, label, customID, "", 0)
return ButtonComponent{
Style: ButtonStyleDanger,
Label: label,
CustomID: customID,
}
}

// NewLinkButton creates a new link ButtonComponent with ButtonStyleLink & the provided parameters
func NewLinkButton(label string, url string) ButtonComponent {
return NewButton(ButtonStyleLink, label, "", url, 0)
return ButtonComponent{
Style: ButtonStyleLink,
Label: label,
URL: url,
}
}

// NewPremiumButton creates a new ButtonComponent with ButtonStylePremium & the provided parameters
func NewPremiumButton(skuID snowflake.ID) ButtonComponent {
return NewButton(ButtonStylePremium, "", "", "", skuID)
return ButtonComponent{
Style: ButtonStylePremium,
SkuID: skuID,
}
}

var (
Expand Down
2 changes: 1 addition & 1 deletion discord/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Interaction interface {
ApplicationID() snowflake.ID
Token() string
Version() int
Guild() *InteractionGuild
PartialGuild() *InteractionGuild
GuildID() *snowflake.ID
// Deprecated: Use Interaction.Channel instead
ChannelID() snowflake.ID
Expand Down
2 changes: 1 addition & 1 deletion discord/interaction_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (i baseInteraction) Token() string {
func (i baseInteraction) Version() int {
return i.version
}
func (i baseInteraction) Guild() *InteractionGuild {
func (i baseInteraction) PartialGuild() *InteractionGuild {
return i.guild
}
func (i baseInteraction) GuildID() *snowflake.ID {
Expand Down
3 changes: 2 additions & 1 deletion discord/interaction_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (i PingInteraction) Version() int {
func (i PingInteraction) CreatedAt() time.Time {
return i.id.Time()
}
func (PingInteraction) Guild() *InteractionGuild {

func (PingInteraction) PartialGuild() *InteractionGuild {
return nil
}

Expand Down
5 changes: 2 additions & 3 deletions discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
_
MessageTypeStageTopic
MessageTypeGuildApplicationPremiumSubscription
MessageTypePurchaseNotification MessageType = 44
)

func (t MessageType) System() bool {
Expand All @@ -63,9 +64,7 @@ func (t MessageType) System() bool {
func (t MessageType) Deleteable() bool {
switch t {
case MessageTypeRecipientAdd, MessageTypeRecipientRemove, MessageTypeCall,
MessageTypeChannelNameChange, MessageTypeChannelIconChange, MessageTypeGuildDiscoveryDisqualified,
MessageTypeGuildDiscoveryRequalified, MessageTypeGuildDiscoveryGracePeriodInitialWarning,
MessageTypeGuildDiscoveryGracePeriodFinalWarning, MessageTypeThreadStarterMessage:
MessageTypeChannelNameChange, MessageTypeChannelIconChange, MessageTypeThreadStarterMessage:
return false

default:
Expand Down
5 changes: 4 additions & 1 deletion discord/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
_
_
PermissionSendPolls
PermissionUseExternalApps

PermissionsAllText = PermissionViewChannel |
PermissionSendMessages |
Expand All @@ -76,7 +77,8 @@ const (
PermissionReadMessageHistory |
PermissionMentionEveryone |
PermissionSendVoiceMessages |
PermissionSendPolls
PermissionSendPolls |
PermissionUseExternalApps

PermissionsAllThread = PermissionManageThreads |
PermissionCreatePublicThreads |
Expand Down Expand Up @@ -175,6 +177,7 @@ var permissions = map[Permissions]string{
PermissionViewGuildInsights: "View Server Insights",
PermissionSendVoiceMessages: "Send Voice Messages",
PermissionSendPolls: "Create Polls",
PermissionUseExternalApps: "Use External Apps",
}

func (p Permissions) String() string {
Expand Down
3 changes: 1 addition & 2 deletions gateway/gateway_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func (g *gatewayImpl) open(ctx context.Context) error {
g.lastHeartbeatSent = time.Now().UTC()
conn, rs, err := g.config.Dialer.DialContext(ctx, gatewayURL, nil)
if err != nil {
g.Close(ctx)
body := "empty"
body := ""
if rs != nil && rs.Body != nil {
defer func() {
_ = rs.Body.Close()
Expand Down
4 changes: 2 additions & 2 deletions rest/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *applicationsImpl) GetGlobalCommands(applicationID snowflake.ID, withLoc

func (s *applicationsImpl) GetGlobalCommand(applicationID snowflake.ID, commandID snowflake.ID, opts ...RequestOpt) (command discord.ApplicationCommand, err error) {
var unmarshalCommand discord.UnmarshalApplicationCommand
err = s.client.Do(GetGlobalCommand.Compile(nil, applicationID, commandID), nil, &command, opts...)
err = s.client.Do(GetGlobalCommand.Compile(nil, applicationID, commandID), nil, &unmarshalCommand, opts...)
if err == nil {
command = unmarshalCommand.ApplicationCommand
}
Expand All @@ -79,7 +79,7 @@ func (s *applicationsImpl) GetGlobalCommand(applicationID snowflake.ID, commandI

func (s *applicationsImpl) CreateGlobalCommand(applicationID snowflake.ID, commandCreate discord.ApplicationCommandCreate, opts ...RequestOpt) (command discord.ApplicationCommand, err error) {
var unmarshalCommand discord.UnmarshalApplicationCommand
err = s.client.Do(CreateGlobalCommand.Compile(nil, applicationID), commandCreate, &command, opts...)
err = s.client.Do(CreateGlobalCommand.Compile(nil, applicationID), commandCreate, &unmarshalCommand, opts...)
if err == nil {
command = unmarshalCommand.ApplicationCommand
}
Expand Down

0 comments on commit a51af11

Please sign in to comment.