Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into feature/message-forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Jun 28, 2024
2 parents 72f9130 + 7dbeaeb commit 9dd2df6
Show file tree
Hide file tree
Showing 50 changed files with 363 additions and 127 deletions.
2 changes: 1 addition & 1 deletion _examples/application_commands/http/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func commandListener(event *events.ApplicationCommandInteractionCreate) {
SetEphemeral(data.Bool("ephemeral")).
Build(),
); err != nil {
event.Client().Logger().Error("error on sending response: ", err)
event.Client().Logger().Error("error on sending response", slog.Any("err", err))
}
}
}
2 changes: 1 addition & 1 deletion _examples/application_commands/localization/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func commandListener(event *events.ApplicationCommandInteractionCreate) {
Build(),
)
if err != nil {
event.Client().Logger().Error("error on sending response: ", err)
event.Client().Logger().Error("error on sending response", slog.Any("err", err))
}
}
}
4 changes: 2 additions & 2 deletions _examples/components/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func main() {
}),
)
if err != nil {
slog.Error("error while building bot: ", err)
slog.Error("error while building bot", slog.Any("err", err))
return
}
defer client.Close(context.TODO())

if err = client.OpenGateway(context.TODO()); err != nil {
slog.Error("error while connecting to gateway: ", err)
slog.Error("error while connecting to gateway", slog.Any("err", err))
return
}

Expand Down
4 changes: 2 additions & 2 deletions _examples/ping_pong/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func main() {
bot.WithEventListenerFunc(onMessageCreate),
)
if err != nil {
slog.Error("error while building disgo", slog.String("err", err.Error()))
slog.Error("error while building disgo", slog.Any("err", err))
return
}

defer client.Close(context.TODO())

if err = client.OpenGateway(context.TODO()); err != nil {
slog.Error("errors while connecting to gateway", slog.String("err", err.Error()))
slog.Error("errors while connecting to gateway", slog.Any("err", err))
return
}

Expand Down
2 changes: 1 addition & 1 deletion bot/member_chunking_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (m *memberChunkingManagerImpl) HandleChunk(payload gateway.EventGuildMember
request, ok := m.chunkingRequests[payload.Nonce]
m.chunkingRequestsMu.RUnlock()
if !ok {
m.logger.Debug("received unknown member chunk event: ", slog.Any("payload", payload))
m.logger.Debug("received unknown member chunk event", slog.Any("payload", payload))
return
}

Expand Down
1 change: 1 addition & 0 deletions discord/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type Attachment struct {
ID snowflake.ID `json:"id,omitempty"`
Filename string `json:"filename,omitempty"`
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
ContentType *string `json:"content_type,omitempty"`
Size int `json:"size,omitempty"`
Expand Down
26 changes: 13 additions & 13 deletions discord/audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (
// AuditLogEvent is an 8-bit unsigned integer representing an audit log event.
type AuditLogEvent int

// AuditLogEventGuildUpdate ...
const (
AuditLogEventGuildUpdate AuditLogEvent = 1
)

// AuditLogEventChannelCreate
const (
AuditLogEventChannelCreate AuditLogEvent = iota + 10
AuditLogEventChannelUpdate
Expand All @@ -23,7 +21,6 @@ const (
AuditLogEventChannelOverwriteDelete
)

// AuditLogEventMemberKick
const (
AuditLogEventMemberKick AuditLogEvent = iota + 20
AuditLogEventMemberPrune
Expand All @@ -36,43 +33,37 @@ const (
AuditLogEventBotAdd
)

// AuditLogEventRoleCreate
const (
AuditLogEventRoleCreate AuditLogEvent = iota + 30
AuditLogEventRoleUpdate
AuditLogEventRoleDelete
)

// AuditLogEventInviteCreate
const (
AuditLogEventInviteCreate AuditLogEvent = iota + 40
AuditLogEventInviteUpdate
AuditLogEventInviteDelete
)

// AuditLogEventWebhookCreate
const (
AuditLogEventWebhookCreate AuditLogEvent = iota + 50
AuditLogEventWebhookUpdate
AuditLogEventWebhookDelete
)

// AuditLogEventEmojiCreate
const (
AuditLogEventEmojiCreate AuditLogEvent = iota + 60
AuditLogEventEmojiUpdate
AuditLogEventEmojiDelete
)

// AuditLogEventMessageDelete
const (
AuditLogEventMessageDelete AuditLogEvent = iota + 72
AuditLogEventMessageBulkDelete
AuditLogEventMessagePin
AuditLogEventMessageUnpin
)

// AuditLogEventIntegrationCreate
const (
AuditLogEventIntegrationCreate AuditLogEvent = iota + 80
AuditLogEventIntegrationUpdate
Expand All @@ -82,28 +73,24 @@ const (
AuditLogEventStageInstanceDelete
)

// AuditLogEventStickerCreate
const (
AuditLogEventStickerCreate AuditLogEvent = iota + 90
AuditLogEventStickerUpdate
AuditLogEventStickerDelete
)

// AuditLogGuildScheduledEventCreate
const (
AuditLogGuildScheduledEventCreate AuditLogEvent = iota + 100
AuditLogGuildScheduledEventUpdate
AuditLogGuildScheduledEventDelete
)

// AuditLogThreadCreate
const (
AuditLogThreadCreate AuditLogEvent = iota + 110
AuditLogThreadUpdate
AuditLogThreadDelete
)

// AuditLogApplicationCommandPermissionUpdate ...
const (
AuditLogApplicationCommandPermissionUpdate AuditLogEvent = 121
)
Expand All @@ -122,6 +109,19 @@ const (
AuditLogCreatorMonetizationTermsAccepted
)

const (
AuditLogOnboardingPromptCreate AuditLogEvent = iota + 163
AuditLogOnboardingPromptUpdate
AuditLogOnboardingPromptDelete
AuditLogOnboardingCreate
AuditLogOnboardingUpdate
)

const (
AuditLogHomeSettingsCreate AuditLogEvent = iota + 190
AuditLogHomeSettingsUpdate
)

// AuditLog (https://discord.com/developers/docs/resources/audit-log) These are logs of events that occurred, accessible via the Discord
type AuditLog struct {
ApplicationCommands []ApplicationCommand `json:"application_commands"`
Expand Down
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
2 changes: 2 additions & 0 deletions discord/cdn_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var (
GuildDiscoverySplash = NewCDN("/discovery-splashes/{guild.id}/{guild.discovery.splash.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP)
GuildBanner = NewCDN("/banners/{guild.id}/{guild.banner.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF)

GuildScheduledEventCover = NewCDN("/guild-events/{event.id}/{event.cover.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP)

RoleIcon = NewCDN("/role-icons/{role.id}/{role.icon.hash}", FileFormatPNG, FileFormatJPEG)

UserBanner = NewCDN("/banners/{user.id}/{user.banner.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF)
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
Loading

0 comments on commit 9dd2df6

Please sign in to comment.