Skip to content

Commit

Permalink
Merge branch 'development' into patch/forum-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mlnrDev committed Sep 14, 2022
2 parents 403c4bb + 9ebbc6e commit 5aab1ea
Show file tree
Hide file tree
Showing 33 changed files with 298 additions and 108 deletions.
2 changes: 1 addition & 1 deletion _examples/application_commands/localization/example.go
Expand Up @@ -21,7 +21,7 @@ var (
commands = []discord.ApplicationCommandCreate{
discord.SlashCommandCreate{
Name: "say",
CommandNameLocalizations: map[discord.Locale]string{
NameLocalizations: map[discord.Locale]string{
discord.LocaleEnglishGB: "say",
discord.LocaleGerman: "sagen",
},
Expand Down
38 changes: 38 additions & 0 deletions _examples/pagination/examplebot.go
@@ -0,0 +1,38 @@
package main

import (
_ "embed"
"os"

"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/rest"
"github.com/disgoorg/log"
)

var token = os.Getenv("disgo_token")

func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.SetLevel(log.LevelDebug)
log.Info("starting example...")
log.Info("bot version: ", disgo.Version)

client := rest.New(rest.NewClient(token))

page := client.GetMessagesPage(817327182111571989, 1016790288607498240, 3)

var i int
for page.Next() {
for _, m := range page.Items {
println(m.ID)
}
println("---")
i++
if i >= 3 {
break
}
}
if page.Err != nil {
log.Error(page.Err)
}
}
2 changes: 1 addition & 1 deletion discord/application_command.go
Expand Up @@ -67,7 +67,7 @@ func (u *UnmarshalApplicationCommand) UnmarshalJSON(data []byte) error {
applicationCommand = v

default:
err = fmt.Errorf("unkown application command with type %d received", cType.Type)
err = fmt.Errorf("unknown application command with type %d received", cType.Type)
}

if err != nil {
Expand Down
30 changes: 15 additions & 15 deletions discord/application_command_create.go
Expand Up @@ -10,13 +10,13 @@ type ApplicationCommandCreate interface {
}

type SlashCommandCreate struct {
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
Description string `json:"description"`
DescriptionLocalizations map[Locale]string `json:"description_localizations,omitempty"`
Options []ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions,omitempty"`
DMPermission bool `json:"dm_permission"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
Description string `json:"description"`
DescriptionLocalizations map[Locale]string `json:"description_localizations,omitempty"`
Options []ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"` // different behavior for 0 and null, optional
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c SlashCommandCreate) MarshalJSON() ([]byte, error) {
Expand All @@ -41,10 +41,10 @@ func (c SlashCommandCreate) CommandName() string {
func (SlashCommandCreate) applicationCommandCreate() {}

type UserCommandCreate struct {
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c UserCommandCreate) MarshalJSON() ([]byte, error) {
Expand All @@ -69,10 +69,10 @@ func (c UserCommandCreate) CommandName() string {
func (UserCommandCreate) applicationCommandCreate() {}

type MessageCommandCreate struct {
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c MessageCommandCreate) MarshalJSON() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion discord/application_command_option.go
Expand Up @@ -107,7 +107,7 @@ func (u *UnmarshalApplicationCommandOption) UnmarshalJSON(data []byte) error {
applicationCommandOption = v

default:
err = fmt.Errorf("unkown application command option with type %d received", oType.Type)
err = fmt.Errorf("unknown application command option with type %d received", oType.Type)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion discord/application_command_permission.go
Expand Up @@ -87,7 +87,7 @@ func (p *UnmarshalApplicationCommandPermission) UnmarshalJSON(data []byte) error
applicationCommandPermission = v

default:
err = fmt.Errorf("unkown application command permission with type %d received", pType.Type)
err = fmt.Errorf("unknown application command permission with type %d received", pType.Type)
}

if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions discord/application_command_update.go
Expand Up @@ -11,11 +11,11 @@ type ApplicationCommandUpdate interface {

type SlashCommandUpdate struct {
Name *string `json:"name,omitempty"`
CommandNameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
Description *string `json:"description,omitempty"`
DescriptionLocalizations *map[Locale]string `json:"description_localizations,omitempty"`
Options *[]ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions *Permissions `json:"default_member_permissions,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

Expand All @@ -41,10 +41,10 @@ func (c SlashCommandUpdate) CommandName() *string {
func (SlashCommandUpdate) applicationCommandUpdate() {}

type UserCommandUpdate struct {
Name *string `json:"name"`
CommandNameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *Permissions `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
Name *string `json:"name,omitempty"`
NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c UserCommandUpdate) MarshalJSON() ([]byte, error) {
Expand All @@ -69,10 +69,10 @@ func (c UserCommandUpdate) CommandName() *string {
func (UserCommandUpdate) applicationCommandUpdate() {}

type MessageCommandUpdate struct {
Name *string `json:"name"`
CommandNameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *Permissions `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
Name *string `json:"name,omitempty"`
NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c MessageCommandUpdate) MarshalJSON() ([]byte, error) {
Expand Down
8 changes: 0 additions & 8 deletions discord/audit_log.go
Expand Up @@ -132,7 +132,6 @@ func (l *AuditLog) UnmarshalJSON(data []byte) error {
var v struct {
ApplicationCommands []UnmarshalApplicationCommand `json:"application_commands"`
Integrations []UnmarshalIntegration `json:"integrations"`
Threads []UnmarshalChannel `json:"threads"`
Webhooks []UnmarshalWebhook `json:"webhooks"`
auditLog
}
Expand All @@ -155,13 +154,6 @@ func (l *AuditLog) UnmarshalJSON(data []byte) error {
}
}

if v.Threads != nil {
l.Threads = make([]GuildThread, len(v.Threads))
for i := range v.Threads {
l.Threads[i] = v.Threads[i].Channel.(GuildThread)
}
}

if v.Webhooks != nil {
l.Webhooks = make([]Webhook, len(v.Webhooks))
for i := range v.Webhooks {
Expand Down
2 changes: 1 addition & 1 deletion discord/auto_moderation.go
Expand Up @@ -79,7 +79,7 @@ type AutoModerationRuleCreate struct {
TriggerType AutoModerationTriggerType `json:"trigger_type"`
TriggerMetadata *AutoModerationTriggerMetadata `json:"trigger_metadata,omitempty"`
Actions []AutoModerationAction `json:"actions"`
Enabled bool `json:"enabled,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
ExemptRoles []snowflake.ID `json:"exempt_roles,omitempty"`
ExemptChannels []snowflake.ID `json:"exempt_channels,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion discord/channel.go
Expand Up @@ -221,7 +221,7 @@ func (u *UnmarshalChannel) UnmarshalJSON(data []byte) error {
channel = v

default:
err = fmt.Errorf("unkown channel with type %d received", cType.Type)
err = fmt.Errorf("unknown channel with type %d received", cType.Type)
}

if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions discord/channel_update.go
Expand Up @@ -38,8 +38,8 @@ type GuildVoiceChannelUpdate struct {
UserLimit *int `json:"user_limit,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RTCRegion *string `json:"rtc_region"`
VideoQualityMode *VideoQualityMode `json:"video_quality_mode"`
RTCRegion *string `json:"rtc_region,omitempty"`
VideoQualityMode *VideoQualityMode `json:"video_quality_mode,omitempty"`
}

func (GuildVoiceChannelUpdate) channelUpdate() {}
Expand All @@ -62,7 +62,7 @@ type GuildNewsChannelUpdate struct {
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
DefaultAutoArchiveDuration *int `json:"default_auto_archive_duration"`
DefaultAutoArchiveDuration *int `json:"default_auto_archive_duration,omitempty"`
}

func (GuildNewsChannelUpdate) channelUpdate() {}
Expand All @@ -88,7 +88,7 @@ type GuildStageVoiceChannelUpdate struct {
UserLimit *int `json:"user_limit,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RTCRegion *string `json:"rtc_region"`
RTCRegion *string `json:"rtc_region,omitempty"`
}

func (GuildStageVoiceChannelUpdate) channelUpdate() {}
Expand Down Expand Up @@ -117,8 +117,8 @@ type GuildForumThreadChannelUpdate struct {
}

type GuildChannelPositionUpdate struct {
ID snowflake.ID `json:"id"`
Position *json.Nullable[int] `json:"position"`
LockPermissions *json.Nullable[bool] `json:"lock_permissions,omitempty"`
ParentID *json.Nullable[snowflake.ID] `json:"parent_id,omitempty"`
ID snowflake.ID `json:"id"`
Position *json.Nullable[int] `json:"position"`
LockPermissions *json.Nullable[bool] `json:"lock_permissions,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
}
2 changes: 1 addition & 1 deletion discord/component.go
Expand Up @@ -76,7 +76,7 @@ func (u *UnmarshalComponent) UnmarshalJSON(data []byte) error {
component = v

default:
err = fmt.Errorf("unkown component with type %d received", cType.Type)
err = fmt.Errorf("unknown component with type %d received", cType.Type)
}
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions discord/emoji.go
Expand Up @@ -51,8 +51,8 @@ type EmojiCreate struct {
}

type EmojiUpdate struct {
Name string `json:"name,omitempty"`
Roles []snowflake.ID `json:"roles,omitempty"`
Name *string `json:"name,omitempty"`
Roles *[]snowflake.ID `json:"roles,omitempty"`
}

type ReactionEmoji struct {
Expand Down
39 changes: 20 additions & 19 deletions discord/guild.go
Expand Up @@ -79,6 +79,7 @@ const (
GuildFeatureCommunity GuildFeature = "COMMUNITY"
GuildFeatureDiscoverable GuildFeature = "DISCOVERABLE"
GuildFeatureFeaturable GuildFeature = "FEATURABLE"
GuildFeatureInvitesDisabled GuildFeature = "INVITES_DISABLED"
GuildFeatureInviteSplash GuildFeature = "INVITE_SPLASH"
GuildFeatureMemberVerificationGateEnabled GuildFeature = "MEMBER_VERIFICATION_GATE_ENABLED"
GuildFeatureMonetizationEnabled GuildFeature = "MONETIZATION_ENABLED"
Expand Down Expand Up @@ -275,25 +276,25 @@ type GuildCreate struct {

// GuildUpdate is the payload used to update a Guild
type GuildUpdate struct {
Name string `json:"name,omitempty"`
VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
DefaultMessageNotificationLevel *MessageNotificationsLevel `json:"default_message_notification_level,omitempty"`
ExplicitContentFilterLevel *ExplicitContentFilterLevel `json:"explicit_content_filter_level,omitempty"`
AFKChannelID *snowflake.ID `json:"afk_channel_id,omitempty"`
AFKTimeout *int `json:"afk_timeout,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
OwnerID *snowflake.ID `json:"owner_id,omitempty"`
Splash *json.Nullable[Icon] `json:"splash,omitempty"`
DiscoverySplash *json.Nullable[Icon] `json:"discovery_splash,omitempty"`
Banner *json.Nullable[Icon] `json:"banner,omitempty"`
SystemChannelID *snowflake.ID `json:"system_channel_id,omitempty"`
SystemChannelFlags *SystemChannelFlags `json:"system_channel_flags,omitempty"`
RulesChannelID *snowflake.ID `json:"rules_channel_id,omitempty"`
PublicUpdatesChannelID *snowflake.ID `json:"public_updates_channel_id,omitempty"`
PreferredLocale *string `json:"preferred_locale,omitempty"`
Features []GuildFeature `json:"features,omitempty"`
Description *string `json:"description,omitempty"`
BoostProgressBarEnabled *bool `json:"premium_progress_bar_enabled,omitempty"`
Name *string `json:"name,omitempty"`
VerificationLevel *json.Nullable[VerificationLevel] `json:"verification_level,omitempty"`
DefaultMessageNotificationLevel *json.Nullable[MessageNotificationsLevel] `json:"default_message_notification_level,omitempty"`
ExplicitContentFilterLevel *json.Nullable[ExplicitContentFilterLevel] `json:"explicit_content_filter_level,omitempty"`
AFKChannelID *snowflake.ID `json:"afk_channel_id,omitempty"`
AFKTimeout *int `json:"afk_timeout,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
OwnerID *snowflake.ID `json:"owner_id,omitempty"`
Splash *json.Nullable[Icon] `json:"splash,omitempty"`
DiscoverySplash *json.Nullable[Icon] `json:"discovery_splash,omitempty"`
Banner *json.Nullable[Icon] `json:"banner,omitempty"`
SystemChannelID *snowflake.ID `json:"system_channel_id,omitempty"`
SystemChannelFlags *SystemChannelFlags `json:"system_channel_flags,omitempty"`
RulesChannelID *snowflake.ID `json:"rules_channel_id,omitempty"`
PublicUpdatesChannelID *snowflake.ID `json:"public_updates_channel_id,omitempty"`
PreferredLocale *string `json:"preferred_locale,omitempty"`
Features *[]GuildFeature `json:"features,omitempty"`
Description *string `json:"description,omitempty"`
BoostProgressBarEnabled *bool `json:"premium_progress_bar_enabled,omitempty"`
}

type NSFWLevel int
Expand Down
3 changes: 2 additions & 1 deletion discord/guild_scheduled_event.go
Expand Up @@ -35,9 +35,10 @@ type GuildScheduledEventCreate struct {
Name string `json:"name"`
PrivacyLevel ScheduledEventPrivacyLevel `json:"privacy_level"`
ScheduledStartTime time.Time `json:"scheduled_start_time"`
ScheduledEndTime time.Time `json:"scheduled_end_time,omitempty"`
ScheduledEndTime *time.Time `json:"scheduled_end_time,omitempty"`
Description string `json:"description,omitempty"`
EntityType ScheduledEventEntityType `json:"entity_type"`
Image *Icon `json:"image,omitempty"`
}

type GuildScheduledEventUpdate struct {
Expand Down
2 changes: 1 addition & 1 deletion discord/integration.go
Expand Up @@ -77,7 +77,7 @@ func (i *UnmarshalIntegration) UnmarshalJSON(data []byte) error {
integration = v

default:
err = fmt.Errorf("unkown integration with type %s received", cType.Type)
err = fmt.Errorf("unknown integration with type %s received", cType.Type)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion discord/interaction.go
Expand Up @@ -87,7 +87,7 @@ func (i *UnmarshalInteraction) UnmarshalJSON(data []byte) error {
interaction = v

default:
return fmt.Errorf("unkown rawInteraction with type %d received", iType.Type)
return fmt.Errorf("unknown rawInteraction with type %d received", iType.Type)
}
if err != nil {
return err
Expand Down
9 changes: 8 additions & 1 deletion discord/interaction_application_command.go
Expand Up @@ -55,9 +55,16 @@ func (i *ApplicationCommandInteraction) UnmarshalJSON(data []byte) error {
v := MessageCommandInteractionData{}
err = json.Unmarshal(interaction.Data, &v)
interactionData = v
if baseInteraction.GuildID() != nil {
for id := range v.Resolved.Messages {
msg := v.Resolved.Messages[id]
msg.GuildID = baseInteraction.guildID
v.Resolved.Messages[id] = msg
}
}

default:
return fmt.Errorf("unkown application rawInteraction data with type %d received", cType.Type)
return fmt.Errorf("unknown application rawInteraction data with type %d received", cType.Type)
}
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion discord/interaction_component.go
Expand Up @@ -54,7 +54,7 @@ func (i *ComponentInteraction) UnmarshalJSON(data []byte) error {
interactionData = v

default:
return fmt.Errorf("unkown component interaction data with type %d received", cType.Type)
return fmt.Errorf("unknown component interaction data with type %d received", cType.Type)
}
if err != nil {
return err
Expand All @@ -64,6 +64,7 @@ func (i *ComponentInteraction) UnmarshalJSON(data []byte) error {

i.Data = interactionData
i.Message = interaction.Message
i.Message.GuildID = baseInteraction.guildID
return nil
}

Expand Down

0 comments on commit 5aab1ea

Please sign in to comment.