diff --git a/api/command.go b/api/command.go index 773d01e8..f17a9f3f 100644 --- a/api/command.go +++ b/api/command.go @@ -30,6 +30,16 @@ func (c Command) FromGuild() bool { return c.GuildID == nil } +// ToCreate return the CommandCreate for this Command +func (c *Command) ToCreate() *CommandCreate { + return &CommandCreate{ + Name: c.Name, + Description: c.Description, + DefaultPermission: c.DefaultPermission, + Options: c.Options, + } +} + // Fetch updates/fetches the current Command from discord func (c *Command) Fetch() error { if c.Disgo == nil { @@ -105,73 +115,6 @@ func (c Command) Delete() error { return c.Disgo.RestClient().DeleteGuildCommand(c.Disgo.ApplicationID(), *c.GuildID, c.ID) } -// CommandOptionType specifies the type of the arguments used in Command.Options -type CommandOptionType int - -// Constants for each slash command option type -const ( - CommandOptionTypeSubCommand CommandOptionType = iota + 1 - CommandOptionTypeSubCommandGroup - CommandOptionTypeString - CommandOptionTypeInteger - CommandOptionTypeBoolean - CommandOptionTypeUser - CommandOptionTypeChannel - CommandOptionTypeRole -) - -// CommandOption are the arguments used in Command.Options -type CommandOption struct { - Type CommandOptionType `json:"type"` - Name string `json:"name"` - Description string `json:"description"` - Required bool `json:"required,omitempty"` - Choices []*OptionChoice `json:"choices,omitempty"` - Options []*CommandOption `json:"options,omitempty"` -} - -// OptionChoice contains the data for a user using your command -type OptionChoice struct { - Name string `json:"name"` - Value interface{} `json:"value"` -} - -// GuildCommandPermissions holds all permissions for a Command -type GuildCommandPermissions struct { - Disgo Disgo - ID Snowflake `json:"id"` - ApplicationID Snowflake `json:"application_id"` - GuildID Snowflake `json:"guild_id"` - Permissions []*CommandPermission `json:"permissions"` -} - -// TODO: add methods to update those - -// CommandPermissionType is the type of the CommandPermission -type CommandPermissionType int - -// types of CommandPermissionType -const ( - CommandPermissionTypeRole = iota + 1 - CommandPermissionTypeUser -) - -// CommandPermission holds a User or Role and if they are allowed to use the Command -type CommandPermission struct { - ID Snowflake `json:"id"` - Type CommandPermissionType `json:"type"` - Permission bool `json:"permission"` -} - -// SetGuildCommandsPermissions holds a slice of SetGuildCommandPermissions -type SetGuildCommandsPermissions []*SetGuildCommandPermissions - -// SetGuildCommandPermissions is used to update CommandPermission ID should be omitted fro bulk update -type SetGuildCommandPermissions struct { - ID Snowflake `json:"id,omitempty"` - Permissions []*CommandPermission `json:"permissions"` -} - // CommandCreate is used to create an Command. all fields are optional type CommandCreate struct { Name string `json:"name,omitempty"` diff --git a/api/command_option.go b/api/command_option.go new file mode 100644 index 00000000..8d883ae4 --- /dev/null +++ b/api/command_option.go @@ -0,0 +1,104 @@ +package api + +// CommandOptionType specifies the type of the arguments used in Command.Options +type CommandOptionType int + +// Constants for each slash command option type +const ( + CommandOptionTypeSubCommand CommandOptionType = iota + 1 + CommandOptionTypeSubCommandGroup + CommandOptionTypeString + CommandOptionTypeInteger + CommandOptionTypeBoolean + CommandOptionTypeUser + CommandOptionTypeChannel + CommandOptionTypeRole + CommandOptionTypeMentionable +) + +// NewCommandOption creates a new CommandOption with the provided params +func NewCommandOption(optionType CommandOptionType, name string, description string, options ...*CommandOption) *CommandOption { + return &CommandOption{ + Type: optionType, + Name: name, + Description: description, + Options: options, + } +} + +// NewSubCommand creates a new CommandOption with CommandOptionTypeSubCommand +func NewSubCommand(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeSubCommand, name, description, options...) +} + +// NewSubCommandGroup creates a new CommandOption with CommandOptionTypeSubCommandGroup +func NewSubCommandGroup(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeSubCommandGroup, name, description, options...) +} + +// NewStringOption creates a new CommandOption with CommandOptionTypeSubCommand +func NewStringOption(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeString, name, description, options...) +} + +// NewIntegerOption creates a new CommandOption with CommandOptionTypeSubCommand +func NewIntegerOption(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeInteger, name, description, options...) +} + +// NewBooleanOption creates a new CommandOption with CommandOptionTypeSubCommand +func NewBooleanOption(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeBoolean, name, description, options...) +} + +// NewUserOption creates a new CommandOption with CommandOptionTypeSubCommand +func NewUserOption(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeUser, name, description, options...) +} + +// NewChannelOption creates a new CommandOption with CommandOptionTypeSubCommand +func NewChannelOption(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeChannel, name, description, options...) +} + +// NewMentionableOption creates a new CommandOption with CommandOptionTypeUser or CommandOptionTypeRole +func NewMentionableOption(name string, description string, options ...*CommandOption) *CommandOption { + return NewCommandOption(CommandOptionTypeMentionable, name, description, options...) +} + +// CommandOption are the arguments used in Command.Options +type CommandOption struct { + Type CommandOptionType `json:"type"` + Name string `json:"name"` + Description string `json:"description"` + Required bool `json:"required,omitempty"` + Choices []*OptionChoice `json:"choices,omitempty"` + Options []*CommandOption `json:"options,omitempty"` +} + +// AddChoice adds a new choice to the the CommandOption +func (o *CommandOption) AddChoice(name string, value interface{}) *CommandOption { + o.Choices = append(o.Choices, &OptionChoice{ + Name: name, + Value: value, + }) + return o +} + +// AddOptions adds multiple choices to the the CommandOption +func (o *CommandOption) AddOptions(options ...*CommandOption) *CommandOption { + o.Options = append(o.Options, options...) + return o +} + +// SetRequired sets if the CommandOption is required +func (o *CommandOption) SetRequired(required bool) *CommandOption { + o.Required = required + return o +} + +// OptionChoice contains the data for a user using your command +type OptionChoice struct { + Name string `json:"name"` + Value interface{} `json:"value"` +} diff --git a/api/command_permission.go b/api/command_permission.go new file mode 100644 index 00000000..3c075091 --- /dev/null +++ b/api/command_permission.go @@ -0,0 +1,37 @@ +package api + +// GuildCommandPermissions holds all permissions for a Command +type GuildCommandPermissions struct { + Disgo Disgo + ID Snowflake `json:"id"` + ApplicationID Snowflake `json:"application_id"` + GuildID Snowflake `json:"guild_id"` + Permissions []*CommandPermission `json:"permissions"` +} + +// TODO: add methods to update those + +// CommandPermissionType is the type of the CommandPermission +type CommandPermissionType int + +// types of CommandPermissionType +const ( + CommandPermissionTypeRole = iota + 1 + CommandPermissionTypeUser +) + +// CommandPermission holds a User or Role and if they are allowed to use the Command +type CommandPermission struct { + ID Snowflake `json:"id"` + Type CommandPermissionType `json:"type"` + Permission bool `json:"permission"` +} + +// SetGuildCommandsPermissions holds a slice of SetGuildCommandPermissions +type SetGuildCommandsPermissions []*SetGuildCommandPermissions + +// SetGuildCommandPermissions is used to update CommandPermission ID should be omitted fro bulk update +type SetGuildCommandPermissions struct { + ID Snowflake `json:"id,omitempty"` + Permissions []*CommandPermission `json:"permissions"` +} diff --git a/api/disgo.go b/api/disgo.go index c491ebea..bf5e152a 100644 --- a/api/disgo.go +++ b/api/disgo.go @@ -39,6 +39,18 @@ type Disgo interface { EditCommand(commandID Snowflake, command *CommandUpdate) (*Command, error) DeleteCommand(commandID Snowflake) error SetCommands(commands ...*CommandCreate) ([]*Command, error) + + GetGuildCommand(guildID Snowflake, commandID Snowflake) (*Command, error) + GetGuildCommands(guildID Snowflake, ) ([]*Command, error) + CreateGuildCommand(guildID Snowflake, command *CommandCreate) (*Command, error) + EditGuildCommand(guildID Snowflake, commandID Snowflake, command *CommandUpdate) (*Command, error) + DeleteGuildCommand(guildID Snowflake, commandID Snowflake) error + SetGuildCommands(guildID Snowflake, commands ...*CommandCreate) ([]*Command, error) + + GetGuildCommandsPermissions(guildID Snowflake) ([]*GuildCommandPermissions, error) + GetGuildCommandPermissions(guildID Snowflake, commandID Snowflake) (*GuildCommandPermissions, error) + SetGuildCommandsPermissions(guildID Snowflake, commandPermissions ...*SetGuildCommandPermissions) ([]*GuildCommandPermissions, error) + SetGuildCommandPermissions(guildID Snowflake, commandID Snowflake, permissions *SetGuildCommandPermissions) (*GuildCommandPermissions, error) } // EventHandler provides info about the EventHandler diff --git a/api/events/listener_adapter.go b/api/events/listener_adapter.go index 75ded836..635db4a7 100644 --- a/api/events/listener_adapter.go +++ b/api/events/listener_adapter.go @@ -123,7 +123,7 @@ type ListenerAdapter struct { // api.Interaction Events OnGenericInteractionEvent func(event *GenericInteractionEvent) - OnCommand func(event *CommandEvent) + OnCommand func(event *CommandEvent) OnButtonClick func(event *ButtonClickEvent) // api.Message Events diff --git a/api/events/ready_event.go b/api/events/ready_event.go index 77bcb301..88fb3631 100644 --- a/api/events/ready_event.go +++ b/api/events/ready_event.go @@ -5,5 +5,5 @@ import "github.com/DisgoOrg/disgo/api" // ReadyEvent indicates we received the ReadyEvent from the api.Gateway type ReadyEvent struct { GenericEvent - api.ReadyGatewayEvent + *api.ReadyGatewayEvent } diff --git a/api/gateway.go b/api/gateway.go index e0835ee7..e617ca80 100644 --- a/api/gateway.go +++ b/api/gateway.go @@ -62,9 +62,9 @@ const ( GatewayEventResumed GatewayEventType = "RESUMED" GatewayEventReconnect GatewayEventType = "RECONNECT" GatewayEventInvalidSession GatewayEventType = "INVALID_SESSION" - GatewayEventCommandCreate GatewayEventType = "APPLICATION_COMMAND_CREATE" - GatewayEventCommandUpdate GatewayEventType = "APPLICATION_COMMAND_UPDATE" - GatewayEventCommandDelete GatewayEventType = "APPLICATION_COMMAND_DELETE" + GatewayEventCommandCreate GatewayEventType = "APPLICATION_COMMAND_CREATE" + GatewayEventCommandUpdate GatewayEventType = "APPLICATION_COMMAND_UPDATE" + GatewayEventCommandDelete GatewayEventType = "APPLICATION_COMMAND_DELETE" GatewayEventChannelCreate GatewayEventType = "CHANNEL_CREATE" GatewayEventChannelUpdate GatewayEventType = "CHANNEL_UPDATE" GatewayEventChannelDelete GatewayEventType = "CHANNEL_DELETE" diff --git a/api/guild.go b/api/guild.go index d56cc3fa..b6d23d90 100644 --- a/api/guild.go +++ b/api/guild.go @@ -7,7 +7,7 @@ import ( "github.com/DisgoOrg/restclient" ) -// PremiumTier tells you the boost level of a guild +// PremiumTier tells you the boost level of a Guild type PremiumTier int // Constants for PremiumTier @@ -18,7 +18,7 @@ const ( PremiumTier3 ) -// SystemChannelFlag contains the settings for the guilds system channel +// SystemChannelFlag contains the settings for the Guild(s) system channel type SystemChannelFlag int // Constants for SystemChannelFlag @@ -27,7 +27,7 @@ const ( SystemChannelFlagSuppressPremiumSubscriptions ) -// The VerificationLevel of a guild that members must be to send messages +// The VerificationLevel of a Guild that members must be to send messages type VerificationLevel int // Constants for VerificationLevel @@ -67,7 +67,7 @@ const ( MFALevelElevated ) -// The GuildFeature (s) that a guild contains +// The GuildFeature (s) that a Guild contains type GuildFeature string // Constants for GuildFeature @@ -103,7 +103,7 @@ type GuildWelcomeChannel struct { EmojiName *string `json:"emoji_name,omitempty"` } -// GuildPreview is used for previewing public guilds before joining them +// GuildPreview is used for previewing public Guild(s) before joining them type GuildPreview struct { Disgo Disgo ID Snowflake `json:"id"` @@ -129,9 +129,10 @@ type FullGuild struct { //Presences []*Presence `json:"presences"` } -// Guild represents a discord guild_events +// Guild represents a discord Guild type Guild struct { Disgo Disgo + Ready bool ID Snowflake `json:"id"` Name string `json:"name"` Icon *string `json:"icon"` @@ -181,12 +182,12 @@ func (g *Guild) CreateRole(role *UpdateRole) (*Role, error) { return g.Disgo.RestClient().CreateRole(g.ID, role) } -// AddMember adds a member to the guild with the oauth2 access token +// AddMember adds a member to the Guild with the oauth2 access token func (g *Guild) AddMember(userID Snowflake, addGuildMemberData *AddGuildMemberData) (*Member, error) { return g.Disgo.RestClient().AddMember(g.ID, userID, addGuildMemberData) } -// IconURL returns the Icon of a guild_events +// IconURL returns the Icon of a Guild func (g *Guild) IconURL(size int) *string { if g.Icon == nil { return nil @@ -204,52 +205,52 @@ func (g *Guild) IconURL(size int) *string { return &u } -// GetCommand fetches a specific guild command +// GetCommand fetches a specific Guild Command func (g *Guild) GetCommand(commandID Snowflake) (*Command, error) { - return g.Disgo.RestClient().GetGuildCommand(g.Disgo.ApplicationID(), g.ID, commandID) + return g.Disgo.GetGuildCommand(g.ID, commandID) } -// GetCommands fetches all guild commands +// GetCommands fetches all Guild Command(s) func (g *Guild) GetCommands() ([]*Command, error) { - return g.Disgo.RestClient().GetGuildCommands(g.Disgo.ApplicationID(), g.ID) + return g.Disgo.GetGuildCommands(g.ID) } -// CreateCommand creates a new command for this guild +// CreateCommand creates a new Command for this Guild func (g *Guild) CreateCommand(command *CommandCreate) (*Command, error) { - return g.Disgo.RestClient().CreateGuildCommand(g.Disgo.ApplicationID(), g.ID, command) + return g.Disgo.CreateGuildCommand(g.ID, command) } -// EditCommand edits a specific guild command +// EditCommand edits a specific Guild Command func (g *Guild) EditCommand(commandID Snowflake, command *CommandUpdate) (*Command, error) { - return g.Disgo.RestClient().EditGuildCommand(g.Disgo.ApplicationID(), g.ID, commandID, command) + return g.Disgo.EditGuildCommand(g.ID, commandID, command) } -// DeleteCommand creates a new command for this guild +// DeleteCommand creates a new Command for this Guild func (g *Guild) DeleteCommand(commandID Snowflake) error { - return g.Disgo.RestClient().DeleteGuildCommand(g.Disgo.ApplicationID(), g.ID, commandID) + return g.Disgo.DeleteGuildCommand(g.ID, commandID) } -// SetCommands overrides all commands for this guild +// SetCommands overrides all Command(s) for this Guild func (g *Guild) SetCommands(commands ...*CommandCreate) ([]*Command, error) { - return g.Disgo.RestClient().SetGuildCommands(g.Disgo.ApplicationID(), g.ID, commands...) + return g.Disgo.SetGuildCommands(g.ID, commands...) } -// GetCommandsPermissions returns the GuildCommandPermissions for a all Command(s) in a guild +// GetCommandsPermissions returns the GuildCommandPermissions for a all Command(s) in a Guild func (g *Guild) GetCommandsPermissions() ([]*GuildCommandPermissions, error) { - return g.Disgo.RestClient().GetGuildCommandsPermissions(g.Disgo.ApplicationID(), g.ID) + return g.Disgo.GetGuildCommandsPermissions(g.ID) } -// GetCommandPermissions returns the GuildCommandPermissions for a specific Command in a guild +// GetCommandPermissions returns the GuildCommandPermissions for a specific Command in a Guild func (g *Guild) GetCommandPermissions(commandID Snowflake) (*GuildCommandPermissions, error) { - return g.Disgo.RestClient().GetGuildCommandPermissions(g.Disgo.ApplicationID(), g.ID, commandID) + return g.Disgo.GetGuildCommandPermissions(g.ID, commandID) } // SetCommandsPermissions sets the GuildCommandPermissions for a all Command(s) func (g *Guild) SetCommandsPermissions(commandPermissions ...*SetGuildCommandPermissions) ([]*GuildCommandPermissions, error) { - return g.Disgo.RestClient().SetGuildCommandsPermissions(g.Disgo.ApplicationID(), g.ID, commandPermissions...) + return g.Disgo.SetGuildCommandsPermissions(g.ID, commandPermissions...) } // SetCommandPermissions sets the GuildCommandPermissions for a specific Command func (g *Guild) SetCommandPermissions(commandID Snowflake, permissions *SetGuildCommandPermissions) (*GuildCommandPermissions, error) { - return g.Disgo.RestClient().SetGuildCommandPermissions(g.Disgo.ApplicationID(), g.ID, commandID, permissions) + return g.Disgo.SetGuildCommandPermissions(g.ID, commandID, permissions) } diff --git a/api/permissions.go b/api/permissions.go index 86346afb..389827e5 100644 --- a/api/permissions.go +++ b/api/permissions.go @@ -178,4 +178,6 @@ const ( PermissionAdministrator | PermissionManageWebhooks | PermissionManageEmojis + + PermissionNone Permissions = 0 ) diff --git a/api/restclient.go b/api/restclient.go index 92b122bc..4dbf0745 100644 --- a/api/restclient.go +++ b/api/restclient.go @@ -6,14 +6,8 @@ import ( "github.com/DisgoOrg/restclient" ) -// Errors when connecting to discord -var ( - ErrBadGateway = errors.New("bad gateway could not reach discord") - ErrUnauthorized = errors.New("not authorized for this endpoint") - ErrBadRequest = errors.New("bad request please check your request") - ErrRatelimited = errors.New("too many requests") - ErrTooMuchCommands = errors.New("you can provide a max of 100 application commands") -) +// ErrMaxCommands returned if a Guild reached max of 100 Command(s) +var ErrMaxCommands = errors.New("you can provide a max of 100 application commands") // UserAgent is the global useragent disgo uses for all its requests var UserAgent = "DiscordBot (" + Github + ", " + Version + ")" diff --git a/example/examplebot.go b/example/examplebot.go index 6792a41d..69f0d0fa 100644 --- a/example/examplebot.go +++ b/example/examplebot.go @@ -44,7 +44,7 @@ func main() { OnRawGateway: rawGatewayEventListener, OnGuildAvailable: guildAvailListener, OnGuildMessageCreate: messageListener, - OnCommand: commandListener, + OnCommand: commandListener, OnButtonClick: buttonClickListener, }). Build() diff --git a/internal/disgo_impl.go b/internal/disgo_impl.go index 901256dd..cea09e4d 100644 --- a/internal/disgo_impl.go +++ b/internal/disgo_impl.go @@ -189,36 +189,86 @@ func (d *DisgoImpl) LargeThreshold() int { } // HasGateway returns whether api.Disgo has an active api.Gateway connection or not -func (d DisgoImpl) HasGateway() bool { +func (d *DisgoImpl) HasGateway() bool { return d.gateway != nil } -// GetCommand fetches a specific guild command -func (d DisgoImpl) GetCommand(commandID api.Snowflake) (*api.Command, error) { +// GetCommand fetches a specific global api.Command +func (d *DisgoImpl) GetCommand(commandID api.Snowflake) (*api.Command, error) { return d.RestClient().GetGlobalCommand(d.ApplicationID(), commandID) } -// GetCommands fetches all guild commands -func (d DisgoImpl) GetCommands() ([]*api.Command, error) { +// GetCommands fetches all global api.Command(s) +func (d *DisgoImpl) GetCommands() ([]*api.Command, error) { return d.RestClient().GetGlobalCommands(d.ApplicationID()) } -// CreateCommand creates a new command for this guild -func (d DisgoImpl) CreateCommand(command *api.CommandCreate) (*api.Command, error) { +// CreateCommand creates a new global api.Command +func (d *DisgoImpl) CreateCommand(command *api.CommandCreate) (*api.Command, error) { return d.RestClient().CreateGlobalCommand(d.ApplicationID(), command) } -// EditCommand edits a specific guild command -func (d DisgoImpl) EditCommand(commandID api.Snowflake, command *api.CommandUpdate) (*api.Command, error) { +// EditCommand edits a specific global api.Command +func (d *DisgoImpl) EditCommand(commandID api.Snowflake, command *api.CommandUpdate) (*api.Command, error) { return d.RestClient().EditGlobalCommand(d.ApplicationID(), commandID, command) } -// DeleteCommand creates a new command for this guild -func (d DisgoImpl) DeleteCommand(commandID api.Snowflake) error { +// DeleteCommand creates a new global api.Command +func (d *DisgoImpl) DeleteCommand(commandID api.Snowflake) error { return d.RestClient().DeleteGlobalCommand(d.ApplicationID(), commandID) } -// SetCommands overrides all commands for this guild -func (d DisgoImpl) SetCommands(commands ...*api.CommandCreate) ([]*api.Command, error) { +// SetCommands overrides all global api.Command(s) +func (d *DisgoImpl) SetCommands(commands ...*api.CommandCreate) ([]*api.Command, error) { return d.RestClient().SetGlobalCommands(d.ApplicationID(), commands...) } + +// GetGuildCommand fetches a specific api.Guild api.Command +func (d *DisgoImpl) GetGuildCommand(guildID api.Snowflake, commandID api.Snowflake) (*api.Command, error) { + return d.RestClient().GetGuildCommand(d.ApplicationID(), guildID, commandID) +} + +// GetGuildCommands fetches all api.Guild api.Command(s) +func (d *DisgoImpl) GetGuildCommands(guildID api.Snowflake, ) ([]*api.Command, error) { + return d.RestClient().GetGuildCommands(d.ApplicationID(), guildID) +} + +// CreateGuildCommand creates a new api.Command for this api.Guild +func (d *DisgoImpl) CreateGuildCommand(guildID api.Snowflake, command *api.CommandCreate) (*api.Command, error) { + return d.RestClient().CreateGuildCommand(d.ApplicationID(), guildID, command) +} + +// EditGuildCommand edits a specific api.Guild api.Command +func (d *DisgoImpl) EditGuildCommand(guildID api.Snowflake, commandID api.Snowflake, command *api.CommandUpdate) (*api.Command, error) { + return d.RestClient().EditGuildCommand(d.ApplicationID(), guildID, commandID, command) +} + +// DeleteGuildCommand creates a new api.Command for this api.Guild +func (d *DisgoImpl) DeleteGuildCommand(guildID api.Snowflake, commandID api.Snowflake) error { + return d.RestClient().DeleteGuildCommand(d.ApplicationID(), guildID, commandID) +} + +// SetGuildCommands overrides all api.Command(s) for this api.Guild +func (d *DisgoImpl) SetGuildCommands(guildID api.Snowflake, commands ...*api.CommandCreate) ([]*api.Command, error) { + return d.RestClient().SetGuildCommands(d.ApplicationID(), guildID, commands...) +} + +// GetGuildCommandsPermissions returns the api.GuildCommandPermissions for a all api.Command(s) in a api.Guild +func (d *DisgoImpl) GetGuildCommandsPermissions(guildID api.Snowflake) ([]*api.GuildCommandPermissions, error) { + return d.RestClient().GetGuildCommandsPermissions(d.ApplicationID(), guildID) +} + +// GetGuildCommandPermissions returns the api.GuildCommandPermissions for a specific api.Command in a api.Guild +func (d *DisgoImpl) GetGuildCommandPermissions(guildID api.Snowflake, commandID api.Snowflake) (*api.GuildCommandPermissions, error) { + return d.RestClient().GetGuildCommandPermissions(d.ApplicationID(), guildID, commandID) +} + +// SetGuildCommandsPermissions sets the api.GuildCommandPermissions for a all api.Command(s) +func (d *DisgoImpl) SetGuildCommandsPermissions(guildID api.Snowflake, commandPermissions ...*api.SetGuildCommandPermissions) ([]*api.GuildCommandPermissions, error) { + return d.RestClient().SetGuildCommandsPermissions(d.ApplicationID(), guildID, commandPermissions...) +} + +// SetGuildCommandPermissions sets the api.GuildCommandPermissions for a specific api.Command +func (d *DisgoImpl) SetGuildCommandPermissions(guildID api.Snowflake, commandID api.Snowflake, permissions *api.SetGuildCommandPermissions) (*api.GuildCommandPermissions, error) { + return d.RestClient().SetGuildCommandPermissions(d.ApplicationID(), guildID, commandID, permissions) +} diff --git a/internal/handlers/guild_create_handler.go b/internal/handlers/guild_create_handler.go index f801a5b7..26ffdb05 100644 --- a/internal/handlers/guild_create_handler.go +++ b/internal/handlers/guild_create_handler.go @@ -76,6 +76,13 @@ func (h GuildCreateHandler) HandleGatewayEvent(disgo api.Disgo, eventManager api } eventManager.Dispatch(genericGuildEvent) + if !guild.Ready { + guild.Ready = true + eventManager.Dispatch(events.GuildReadyEvent{ + GenericGuildEvent: genericGuildEvent, + }) + } + if wasUnavailable { eventManager.Dispatch(events.GuildAvailableEvent{ GenericGuildEvent: genericGuildEvent, diff --git a/internal/handlers/ready_handler.go b/internal/handlers/ready_handler.go index e2c95db3..b1af4ad7 100644 --- a/internal/handlers/ready_handler.go +++ b/internal/handlers/ready_handler.go @@ -2,6 +2,7 @@ package handlers import ( "github.com/DisgoOrg/disgo/api" + "github.com/DisgoOrg/disgo/api/events" ) // ReadyHandler handles api.ReadyGatewayEvent @@ -30,4 +31,9 @@ func (h ReadyHandler) HandleGatewayEvent(disgo api.Disgo, eventManager api.Event disgo.Cache().CacheGuild(readyEvent.Guilds[i]) } + disgo.EventManager().Dispatch(events.ReadyEvent{ + GenericEvent: events.NewEvent(disgo, sequenceNumber), + ReadyGatewayEvent: readyEvent, + }) + } diff --git a/internal/restclient_impl.go b/internal/restclient_impl.go index 2b34291d..e83f782a 100644 --- a/internal/restclient_impl.go +++ b/internal/restclient_impl.go @@ -8,7 +8,6 @@ import ( "github.com/DisgoOrg/restclient" ) - func newRestClientImpl(disgo api.Disgo, httpClient *http.Client) api.RestClient { if httpClient == nil { httpClient = http.DefaultClient @@ -440,7 +439,7 @@ func (r *RestClientImpl) SetGlobalCommands(applicationID api.Snowflake, commands return nil, err } if len(commands) > 100 { - err = api.ErrTooMuchCommands + err = api.ErrMaxCommands return } err = r.Do(compiledRoute, commands, &cmds) @@ -513,7 +512,7 @@ func (r *RestClientImpl) SetGuildCommands(applicationID api.Snowflake, guildID a return nil, err } if len(commands) > 100 { - err = api.ErrTooMuchCommands + err = api.ErrMaxCommands return } err = r.Do(compiledRoute, commands, &cmds)